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

Exception thrown from a JavaVoidCallback terminates the whole JVM process #217

Closed
peter-gergely-horvath opened this issue Dec 7, 2016 · 6 comments
Labels

Comments

@peter-gergely-horvath
Copy link

peter-gergely-horvath commented Dec 7, 2016

Any exception thrown from a JavaCallback/JavaVoidCallback causes the JVM to exit.

Consider the following sample:

public class J2V8Example {

    public static void main(String[] args) throws Exception {

        String script = " foobar(); ";

        Path tempFile = scriptToTempFile(script);

        JavaVoidCallback testCallback = (receiver, parameters) -> {
            throw new IllegalStateException("This simulates an error");
        };

        NodeJS theNodeJs = NodeJS.createNodeJS();
        theNodeJs.getRuntime().registerJavaMethod(testCallback, "foobar");

        try {
            theNodeJs.exec(tempFile.toFile());

            while (theNodeJs.isRunning()) {
                theNodeJs.handleMessage();
            }
        } catch (Exception ex) {
            System.err.println("Caught Exception: ");
            ex.printStackTrace();
        } catch (Throwable t) {
            System.err.println("Caught Throwable: ");
            t.printStackTrace();
        }
    }

    private static Path scriptToTempFile(String script) throws IOException {
        Path tempFile = Files.createTempFile("J2V8Example", ".tmp");
        Files.write(tempFile, script.getBytes("UTF-8"),
                StandardOpenOption.WRITE,
                StandardOpenOption.TRUNCATE_EXISTING);
        return tempFile;
    }
}

Instead of printing "Caught Exception: " or "Caught Throwable: " and the stack trace, this sample immediately terminates the WHOLE JVM PROCESS with an error message similar to the one below:

node.js:376
        callback();
        ^
/tmp/J2V8Example7781710029960180303.tmp:1: This simulates an error
@plg1971
Copy link

plg1971 commented Jan 23, 2017

THANK YOU!! : - )

@irbull
Copy link
Member

irbull commented Jan 23, 2017

Sorry, I missed this bug report. Crashing the VM is never the right behaviour. I will take a look. Thanks for reporting.

@midzelis
Copy link

@irbull not sure if you saw, but this is another JVM crash bug: #202

@rdemirkoparan
Copy link

Hello, @irbull any update on this issue?

@TonyRice
Copy link
Contributor

I am attempting to debug this issue.

@irbull irbull added the nodejs label Jan 11, 2019
@irbull
Copy link
Member

irbull commented Jan 11, 2019

Unfortunately, I'm not able to support NodeJS with J2V8 and for the project to continue, I need to scope the work and be honest about what I can support. Please see #441. If someone else would like to extend J2V8 in a downstream project to support NodeJS, I would be happy to help them get started.

I'm tagging this as NodeJS in case someone wants to address these issues in a downstream project, but I'm going to close this as out of scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants