Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsafe.throwException doesn't exist on Android #6905

Closed
scabug opened this issue Jan 3, 2013 · 3 comments
Closed

Unsafe.throwException doesn't exist on Android #6905

scabug opened this issue Jan 3, 2013 · 3 comments

Comments

@scabug
Copy link

scabug commented Jan 3, 2013

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
    }
@scabug
Copy link
Author

scabug commented Jan 3, 2013

Imported From: https://issues.scala-lang.org/browse/SI-6905?orig=1
Reporter: @viktorklang
Duplicates #6594

@scabug
Copy link
Author

scabug commented Jan 3, 2013

@viktorklang said:
scala/scala#1838

@scabug
Copy link
Author

scabug commented Jan 3, 2013

@viktorklang said:
This is a duplicate

@scabug scabug closed this as completed Jan 3, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant