JDK-8296656 : java.lang.NoClassDefFoundError exception on running fully legitimate code
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8,11,17,18,19,20,21
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2022-10-29
  • Updated: 2024-08-30
  • Resolved: 2023-03-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21
21 b16Fixed
Related Reports
CSR :  
Duplicate :  
Relates :  
Relates :  
Sub Tasks
JDK-8304995 :  
Description
ADDITIONAL SYSTEM INFORMATION :
x86/windows 10/ openjdk 19.0.1

A DESCRIPTION OF THE PROBLEM :
Getting java.lang.NoClassDefFoundError exception on running fully legitimate code

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
run this snippet

public interface Main {
	
	@interface Annotation {
		interface foo {
			static void print() {System.out.println("Oops!");}
		}
		
		@interface Foo {}
	}
	
	static void main(String[] args) {
		Annotation.foo.print();
	}
}

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
 Ooops in the console
ACTUAL -
Exception in thread "main" java.lang.NoClassDefFoundError: Main$Annotation$Foo (wrong name: Main$Annotation$foo)
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	at Main.main(Main.java:13)

---------- BEGIN SOURCE ----------
public interface Main {
	
	@interface Annotation {
		interface foo {
			static void print() {System.out.println("Oops!");}
		}
		
		@interface Foo {}
	}
	
	static void main(String[] args) {
		Annotation.foo.print();
	}
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
rename foo or Foo to something else


Comments
[~vromero] The changes to the javac.1 manpage that are part of this issue should have been applied to the closed javac.md source and re-generated to apply them to the open java.1 page. These changes will be lost as soon as the manpages are re-generated, both for JDK 21 and JDK 22, so this needs to be fixed in both JDK 21 and JDK 22
14-06-2023

Changeset: 14b970dc Author: Archie L. Cobbs <archie.cobbs@gmail.com> Committer: Vicente Romero <vromero@openjdk.org> Date: 2023-03-27 21:33:01 +0000 URL: https://git.openjdk.org/jdk/commit/14b970dc9e8d0fe1173039c01cced8a9422ec1ae
27-03-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/12754 Date: 2023-02-25 21:22:57 +0000
20-03-2023

This is due to javac not supporting case-insensitive filesystems, which is a "known bug". Same underlying issue as JDK-8287885, though this bug is harder to workaround because it doesn't involve local classes.
22-02-2023

Moving this to tools/javac for now. This is about javac generating Main$Annotation$foo.class containing class Main$Annotation$Foo. That said, it will be very file system dependent on whether Main$Annotation$foo.class and Main$Annotation$Foo.class can exist as distinct files in the same directory.
09-11-2022

The observations on Windows 10: JDK 8: Failed, NoClassDefFoundError thrown. JDK 11: Failed. JDK 17: Failed. JDK 18: Failed. JDK 19: Failed. JDK 20ea+22: Failed.
09-11-2022