Skip to content

Lazy methods: mark JVM-generated exceptions as always available #1467

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

Conversation

antlechner
Copy link
Contributor

java.lang.NullPointerException et al are producable from Java ops
other than throw, and therefore weren't previously noticed. This adds
the exceptions that can be introduced by java_bytecode/java_bytecode_instrument.cpp
into the lazy methods loader's list of always-available classes.

java.lang.NullPointerException et al are producable from Java ops
other than throw, and therefore weren't previously noticed. This adds
the exceptions that can be introduced by java_bytecode/java_bytecode_instrument.cpp
into the lazy methods loader's list of always-available classes.
@antlechner
Copy link
Contributor Author

Suggested reviewers:
@thk123 @smowton @LAJW

Copy link
Contributor

@smowton smowton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve of course, but then I wrote it :)

Copy link
Contributor

@LAJW LAJW left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful if this PR included an example of what it's fixing.

@antlechner
Copy link
Contributor Author

antlechner commented Oct 11, 2017

An example of why this PR is/will be needed:

public static int check1(String s) {
    try {
        return s.length();
    }
    catch (NullPointerException e) {
        e.getMessage();
        return -1;
    }
}

With the current platform options, the catch block is ignored. But with the --java-throw-runtime-exceptions parameter (which will be added as a platform option at some point, hopefully soon), test-gen tries to generate a test for catch block, looks up NullPointerException.getMessage, and can't find it because the exception is generated after lazy methods analysed the code. The result is an error and no generated tests.

Copy link
Contributor

@thk123 thk123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @LAJW - could you take your example and create regression or unit tests exhibiting the problem this will fix (pref ably one for each type of exception). Or if there are already tests for each exception (they're should be...), extend them to use lazy-methods and the models library so that they would catch this in future.

lazy_methods.add_needed_class(
"java::java.lang.ArrayIndexOutOfBoundsException");
lazy_methods.add_needed_class("java::java.lang.ClassCastException");
lazy_methods.add_needed_class("java::java.lang.NegativeArraySizeException");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a comment to java_bytecode_instrument::instrument_expr to say that new runtime thrown exceptions need to be added to ci_lazy_methods.cpp

@antlechner
Copy link
Contributor Author

test-gen doesn't build with the version of cbmc that this is based on, so I'll rebase the changes on my fork and create a new PR. I'll close this one and link the new one here. Sorry about that.

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

Successfully merging this pull request may close these issues.

4 participants