Fix a bug in test case of RecursiveClinitTest #352
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR should fix the following failing test, which is a part of #274.
I have tested locally and found that it fixes this test case with no more regressions (10 failing tests left now).
Problem Analysis
This is not a bug of JPF but instead a bug of the test case.
Running on JPF, this test case thows the following exception:
Derived
has defined a constructor with anint
parameter; there is no default constructor for it. So instead of callinggetDeclaredConstructor()
to get its constructor,getDeclaredConstructor(int.class)
should be called. According to document of getDeclaredConstructor, in the case of not finding a matching constructor this behavior (throwingjava.lang.NoSuchMethodException
) is correct.Furthermore, according to the document of newInstance, it also need to be called with an argument.
As evidence, running the following code (which is quite similar to the test case code) on OpenJDK 11,
generating
And running the following code (which is quite similar to the test case code) on OpenJDK 11,
generating
Discussions
The test case is not same with that on
master
branch. This is the case on master branch:jpf-core/src/tests/gov/nasa/jpf/test/vm/basic/RecursiveClinitTest.java
Lines 68 to 70 in 3408119
It doesn't invoke
getDeclaredConstructor()
but instead uses.class
expression, which avoidNoSuchMethodException
. It callsjava.lang.Class.newInstance()
which is identical to callnew Derived()
. This should throwjava.lang.NoSuchMethodException
but it doesn't (the same thing happens onjava-10-gradle
branch, i.e.,Derived.class.newInstance()
passes). So there must be some bug withjava.lang.Class.newInstance()
's implementations. I'll diagnose it later.