Scala Programming Language
  1. Scala Programming Language
  2. SI-6905

Unsafe.throwException doesn't exist on Android

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      The throwException method doesn't exist on sun.misc.Unsafe on Android,
      but good news, it can be emulated in Java without any performance loss.

      From jsr116y: http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/jsr166e/ForkJoinTask.java?view=markup

          /**
           * A version of "sneaky throw" to relay exceptions
           */
          static void rethrow(final Throwable ex) {
              if (ex != null) {
                  if (ex instanceof Error)
                      throw (Error)ex;
                  if (ex instanceof RuntimeException)
                      throw (RuntimeException)ex;
                  ForkJoinTask.<RuntimeException>uncheckedThrow(ex);
              }
          }
      
          /**
           * The sneaky part of sneaky throw, relying on generics
           * limitations to evade compiler complaints about rethrowing
           * unchecked exceptions
           */
          @SuppressWarnings("unchecked") static <T extends Throwable>
              void uncheckedThrow(Throwable t) throws T {
              if (t != null)
                  throw (T)t; // rely on vacuous cast
          }
      

        Issue Links

          Activity

          Show
          Viktor Klang added a comment - https://github.com/scala/scala/pull/1838
          Hide
          Viktor Klang added a comment -

          This is a duplicate

          Show
          Viktor Klang added a comment - This is a duplicate

            People

            • Assignee:
              Unassigned
              Reporter:
              Viktor Klang
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development