-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Expected exception: org.junit.runners.model.InitializationError #749
Comments
Has there been an intentional change in JDK 8 that allows reflective calls like getDeclaredMethods to succeed on classes that would otherwise be inaccessible, i.e., package-private classes in another package? |
Needed for testing junit-team/junit4#749.
The behaviour of java.lang.reflect.Method.getAnnotations() has changed. You can check https://github.com/stefanbirkner/oraclejdk8-method-getannotations-bug for the difference. I created a bug report: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=9008626 (Will be available when it is accepted.) |
That appears to be a rather old bug. Is there a way to workaround it so that JUnit works both in its presence and in its absence? Thanks. |
@dsaff I try to find a solution. Unfortunately I still don't have feedback from Oracle about the issue. |
As I understood you found that Take a look into JDK 6 and you will see the implementation of Method -> AccessibleObject |
Is there a fix for this, I'm unable to build junit from source, without skipping the test phase. |
I did some more research on this issue. The difference between Java 7 and Java 8 is that JUnit with Java 7 uses the
whereas JUnit with Java 8 uses the
|
It seems as if JDK 8 generates a bridge method
|
There are two solutions for solving this issue. Remove the validation
from I recommend removing the validation, but I'm not sure whether this could cause problems with security managers. @junit-team/junit-committers Which solution are you preferring? |
For those missing context, the source file for Sub.java is here: It looks like in this case a bridge method might be created because the base class is not public, but the method is public, and the subclass is public. I'm curious what will happen in JDK7 and JDK8 if we turn off the validation check, ignore the bridge method and try to call the test method via the |
@stefanbirkner It's also possible that removing the validation would be safe. Why do we care if the class that declares the method is public? Shouldn't we only care that |
I just realized something; all of the users of MethodValidator are deprecated, with comments claiming they will be removed in the next release. Can we delete these?
|
I created a separate pull request for removing the deprecated classes: #862 |
I would not expect FrameworkMethod.validatePublicVoid(...) to test visibility of the declaring class. Since the last commit the runner itself verifies that a test class is public. Hence we can safely remove this validation from FrameworkMethod. This fixes junit-team#749 (JUnit cannot be build with JDK 8), too.
We can now build JUnit with JDK 8, because junit-team#749 is fixed.
We can now build JUnit with JDK 8, because junit-team#749 is fixed.
Hi,
We're run apache gump (https://svn.apache.org/repos/asf/gump/trunk/) to test a new JDK 8 early access releases from https://jdk8.java.net/download.html
Came across a new failure staring with b94:
populate-dist:
[copy] Copying 53 files to /home/dtftest/gump/results/junit/gump-test/doc
[copy] Copying 1 file to /home/dtftest/gump/results/junit/gump-test
[copy] Copying 1 file to /home/dtftest/gump/results/junit/gump-test
[copy] Copying 1 file to /home/dtftest/gump/results/junit/gump-test
[copy] Copying 1 file to /home/dtftest/gump/results/junit/gump-test
dist:
[java] JUnit version 4.12
[java] ....................................................................................................................................................................................................................................................................................................................................................I.I............................................E.....................................................................................................................................................................................................................................................................................................................................................................................................
[java] Time: 8.442
[java] There was 1 failure:
[java] 1) inaccessibleBaseClassIsCaughtAtValidation(org.junit.tests.validation.InaccessibleBaseClassTest)
[java] java.lang.AssertionError: Expected exception: org.junit.runners.model.InitializationError
[java] at org.junit.internal.runners.statements.ExpectException.evaluate(ExpectException.java:33)
[java] at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:274)
[java] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
[java] at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:55)
[java] at org.junit.runners.ParentRunner$3.run(ParentRunner.java:239)
[java] at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:64)
[java] at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:237)
[java] at org.junit.runners.ParentRunner.access$000(ParentRunner.java:54)
[java] at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:228)
[java] at org.junit.runners.ParentRunner.run(ParentRunner.java:312)
[java] at org.junit.runners.Suite.runChild(Suite.java:128)
[java] at org.junit.runners.Suite.runChild(Suite.java:27)
[java] at org.junit.runners.ParentRunner$3.run(ParentRunner.java:239)
[java] at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:64)
[java] at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:237)
[java] at org.junit.runners.ParentRunner.access$000(ParentRunner.java:54)
[java] at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:228)
[java] at org.junit.runners.ParentRunner.run(ParentRunner.java:312)
[java] at org.junit.runners.Suite.runChild(Suite.java:128)
[java] at org.junit.runners.Suite.runChild(Suite.java:27)
[java] at org.junit.runners.ParentRunner$3.run(ParentRunner.java:239)
[java] at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:64)
[java] at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:237)
[java] at org.junit.runners.ParentRunner.access$000(ParentRunner.java:54)
[java] at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:228)
[java] at org.junit.runners.ParentRunner.run(ParentRunner.java:312)
[java] at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
[java] at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
[java] at org.junit.runner.JUnitCore.runMain(JUnitCore.java:77)
[java] at org.junit.runner.JUnitCore.main(JUnitCore.java:36)
[java]
[java] FAILURES!!!
[java] Tests run: 774, Failures: 1
[java]
BUILD FAILED
/home/dtftest/gump/results/junit/build.xml:211: The following error occurred while executing this line:
/home/dtftest/gump/results/junit/build.xml:181: Java returned: 1
Total time: 28 seconds
The text was updated successfully, but these errors were encountered: