[GRADLE-1682] Test classloader ordering seems to not be in parent first Created: 21/Jul/11  Updated: 13/Sep/16  Resolved: 13/Sep/16

Status: Resolved
Project: Gradle
Affects Version/s: 1.0-milestone-3
Fix Version/s: 3.2-rc-1

Type: Bug
Reporter: Frédéric Camblor Assignee: Unassigned
Resolution: Fixed Votes: 12

Attachments: File gradle-runtimeTestClasspath-issue.tar    


When referencing the org.apache.felix:org.osgi.foundation artefact, which redefine rt.jar classes (Object class and so on...) in my unit tests, my tests are failing (with java.lang.IllegalArgumentException: superClassName is empty!)
If I comment the dependency in build.gradle, my tests are OK.

Looks like gradle is taking first the org.osgi.foundation jar, before rt.jar when executing tests.
Am I right ?

I attached a test project reproducing this problem.
Just comment the org.osgi.foundation artefact to resolve the problem.

"superClassName is empty" error seems to appear when we have classes in src/test/java, that doesn't have any @Test annotation (that's why I provided the empty SomeNonTestClassThatWillBreakTheBuild class).

Comment by Shawn Ma [ 15/Sep/11 ]

same issue here.

from the debug log:

24872 21:21:02.807 [DEBUG] [org.gradle.api.internal.tasks.testing.detection.ClassFileExtractionManager] extracted class groovy/lang/Closure from groovy-all-1.7.10.jar
24873 21:21:02.871 [DEBUG] [org.gradle.api.internal.tasks.testing.detection.ClassFileExtractionManager] extracted class groovy/lang/GroovyObjectSupport from groovy-all-1.7.10.jar
24874 21:21:02.880 [DEBUG] [org.gradle.api.internal.tasks.testing.detection.ClassFileExtractionManager] extracted class java/lang/Object from org.osgi.foundation-1.0.0.jar

Comment by Zach A. Thomas [ 24/Jun/12 ]

I just ran into this. In my case, I don't have a direct dependency on org.osgi.foundation. I depend on org.osgi.compendium which pulls in foundation transitively.

I'm brand new to gradle, interested in moving off of maven for a multi-module OSGi project[1]. If we can't run the tests, my investigation is more or less stalled.

For a specific module where you can see this error, see [2] and use build.gradle at [3].

[1] https://github.com/sakaiproject/nakamura
[2] https://github.com/sakaiproject/nakamura/tree/master/bundles/connections
[3] http://pastebin.com/pfDwrbku

Comment by Andy Ma [ 30/Jan/13 ]

I also have this issue, if no @Test annoation in a java file under src/test/java and also the project has dependency to "org.osgi.foundation" jar, this issue will happen, now I temporarily solve it by exclude dependency to "org.osgi.foundation" like follow in my gradle.build file.

configurations {
  all*.exclude module: "org.osgi.foundation"
Comment by Olafur Egilsson [ 17/May/15 ]

This almost four year old issue is still unresolved in Gradle 2.4.
IMHO it should have higher priority since it could prevent larger projects to switch to Gradle.

Comment by Sandu Turcan [ 16/Sep/15 ]

I got the same error today.
It happens because it's examining the class hierarchy and doesn't stop at java.lang.Object.
I think it can be solved by changing one line in org.gradle.api.internal.tasks.testing.detection.AbstractTestFrameworkDetector#getSuperTestClassFile, to exclude all JDK classes.
See the last return statement:

    protected File getSuperTestClassFile(String superClassName) {
        if (StringUtils.isEmpty(superClassName)) {
            throw new IllegalArgumentException("superClassName is empty!");

        final Iterator<File> testClassDirectoriesIt = testClassDirectories.iterator();

        File superTestClassFile = null;
        while (superTestClassFile == null && testClassDirectoriesIt.hasNext()) {
            final File testClassDirectory = testClassDirectoriesIt.next();
            final File superTestClassFileCandidate = new File(testClassDirectory, superClassName + ".class");
            if (superTestClassFileCandidate.exists()) {
                superTestClassFile = superTestClassFileCandidate;

        if (superTestClassFile != null) {
            return superTestClassFile;
        } else { // super test class file not in test class directories
            // Skip JDK classes
            return superClassName.startsWith("java/") || superClassName.startsWith("javax/") ? null : classFileExtractionManager.getLibraryClassFile(superClassName);
Comment by Piotr Jagielski [ 09/Feb/16 ]

For future reference, there was an unfinished pull request that contain some discussion at https://github.com/gradle/gradle/pull/558. It would be great if someone from the community could pick it up.

Comment by Jendrik Johannes (Inactive) [ 13/Sep/16 ]

PR fixing this issue: https://github.com/gradle/gradle/pull/676

Generated at Wed Jun 30 12:01:45 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.