Bug 60062

Summary: junit - Classes that cause ExceptionInInitializerError assumed to be failed test
Product: Ant Reporter: glen.a.ritchie
Component: Optional TasksAssignee: Ant Notifications List <notifications>
Status: RESOLVED FIXED    
Severity: enhancement    
Priority: P2    
Version: 1.9.7   
Target Milestone: 1.10.4   
Hardware: PC   
OS: All   

Description glen.a.ritchie 2016-08-29 01:32:11 UTC
Summary
=============

In JUnitTestRunner.run(), when a class fails to initialize properly during the initial Class.forName(), the class is assumed to be a failed test and is reported as such even when skipNonTests is set.

This causes false error reports for classes that are not actual tests. This is especially noticeable when using wildcards in <batchtest> when classes that subclass JavaFX are present.

Cause/Example
=============

Example:
---------
public class MyControl extends javafx.scene.control.Control
{
}
---------

When JUnitTestRunner tests this class, it attempts a Class.forName(), which then fails with:
----------------
java.lang.ExceptionInInitializerError
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:377)
	at ant_fx_test.MyTest.main(MyTest.java:31)
Caused by: java.lang.IllegalStateException: Toolkit not initialized
	at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:273)
	at com.sun.javafx.application.PlatformImpl.runLater(PlatformImpl.java:268)
	at com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(PlatformImpl.java:550)
	at com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(PlatformImpl.java:512)
	at javafx.scene.control.Control.<clinit>(Control.java:87)
	... 4 more
---------------

The cause is static block in javafx.scene.control.Control that eventually throws an exception preventing the Class.forName() from completing.

The skipNonTests option has no effect as it is not checked until the class was initialized properly.

The issue of the static initializer in JavaFX has been reported here https://bugs.openjdk.java.net/browse/JDK-8102211 as fixed, with no indication that it was ever actually "fixed".

Workaround
=============
Exclude the classes on a per name basis.


Requested Enhancement
=====================
A configuration option to ignore classes that fail initialization.
Comment 1 Maarten Coene 2018-04-06 07:28:33 UTC
This will be fixed in the next release (1.9.12 and 1.10.4) where the static initialization of the class is postponed until *after* the check that the class is a junit test.