junit-team / junit4

A programmer-oriented testing framework for Java.
https://junit.org/junit4
Eclipse Public License 1.0
8.51k stars 3.24k forks source link

Compilation error in org.junit.runner.Result - ObjectInputStream.GetField.get(name, object) throws ClassNotFoundException #1739

Closed cushon closed 1 year ago

cushon commented 2 years ago

This code fails to compile on JDK 18 and newer:

https://github.com/junit-team/junit4/blob/cc7c500584fcb85eaf98c568b7441ceac6dd335c/src/main/java/org/junit/runner/Result.java#L190-L198

src/main/java/org/junit/runner/Result.java:192: error: unreported exception ClassNotFoundException; must be caught or declared to be thrown
            fCount = (AtomicInteger) fields.get("fCount", null);
                                               ^
src/main/java/org/junit/runner/Result.java:193: error: unreported exception ClassNotFoundException; must be caught or declared to be thrown
            fIgnoreCount = (AtomicInteger) fields.get("fIgnoreCount", null);
                                                     ^
src/main/java/org/junit/runner/Result.java:194: error: unreported exception ClassNotFoundException; must be caught or declared to be thrown
            assumptionFailureCount = (AtomicInteger) fields.get("assumptionFailureCount", null);
                                                               ^
src/main/java/org/junit/runner/Result.java:195: error: unreported exception ClassNotFoundException; must be caught or declared to be thrown
            fFailures = (List<Failure>) fields.get("fFailures", null);
                                                  ^

This is the corresponding JDK change: https://bugs.openjdk.java.net/browse/JDK-8276742