JDK-8320396 : Class-File API ClassModel::verify should include checks from hotspot/share/classfile/classFileParser.cpp
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang.classfile
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-11-20
  • Updated: 2024-06-07
  • Resolved: 2024-05-31
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 23
23 b26Fixed
Related Reports
Relates :  
Description
ClassModel::verify does not report fields and methods duplicities.

For example a class with doubled method with the same signatures fails to load with error message:
Error: LinkageError occurred while loading main class Test
	java.lang.ClassFormatError: Duplicate method name "test" with signature "()V" in class file Test

Comments
Changeset: 22ef827e Author: Adam Sotona <asotona@openjdk.org> Date: 2024-05-31 06:26:35 +0000 URL: https://git.openjdk.org/jdk/commit/22ef827e2cc2409f21ad5c26611cb13d39b5cb3e
31-05-2024

Just to be clear these structural checks are defined by the JVMS Chapter 4
22-03-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/16809 Date: 2023-11-24 13:20:20 +0000
21-03-2024

Draft PR with work in progress: https://github.com/openjdk/jdk/pull/16809
24-11-2023

https://raw.githubusercontent.com/openjdk/jdk/master/src/hotspot/share/classfile/classFileParser.cpp contains numerous class checks and I suggest all of them should be included in the ClassModel::verify execution. Brief list of the errors that should be reported: "Class file version does not support constant tag %u in class file %s" "Unknown constant tag %u in class file %s" "Bad method handle kind at constant pool index %u in class file %s" "Bad method name at constant pool index %u in class file %s" "Bad constructor name at constant pool index %u in class file %s" "Bad method name at constant pool index %u in class file %s" "Duplicate interface name \"%s\" in class file %s" "Unable to set initial value %u in class file %s" "Duplicate ConstantValue attribute in class file %s" "Invalid Synthetic field attribute length %u in class file %s" "Invalid Deprecated field attribute length %u in class file %s" "Multiple Signature attributes for field in class file %s" "Wrong size %u for field's Signature attribute in class file %s" "Multiple RuntimeVisibleAnnotations attributes for field in class file %s" "Multiple RuntimeInvisibleAnnotations attributes for field in class file %s" "Multiple RuntimeVisibleTypeAnnotations attributes for field in class file %s" "Multiple RuntimeInvisibleTypeAnnotations attributes for field in class file %s" "Duplicate field name \"%s\" with signature \"%s\" in class file %s" "Invalid start_pc %u in %s in class file %s" "Invalid length %u in %s in class file %s" "Duplicated LocalVariableTable attribute entry for '%s' in class file %s", "LVTT entry for '%s' in class file %s does not match any LVT entry", "Duplicated LocalVariableTypeTable attribute entry for '%s' in class file %s", "Method <clinit> is not static in class file %s" "Interface cannot have a method named <init>, class file %s" "Too many arguments in method signature in class file %s" "Multiple Code attributes in class file %s" "Multiple StackMapTable attributes in class file %s" "Multiple Exceptions attributes in class file %s" "Multiple MethodParameters attributes in class file %s" "Invalid MethodParameters method attribute length %u in class file" "Invalid Synthetic method attribute length %u in class file %s" "Invalid Deprecated method attribute length %u in class file %s" "Multiple Signature attributes for method in class file %s" "Invalid Signature attribute length %u in class file %s" "Multiple RuntimeVisibleAnnotations attributes for method in class file %s" "Multiple RuntimeInvisibleAnnotations attributes for method in class file %s" "Multiple RuntimeVisibleParameterAnnotations attributes for method in class file %s" "Multiple RuntimeInvisibleParameterAnnotations attributes for method in class file %s" "Multiple AnnotationDefault attributes for method in class file %s" "Multiple RuntimeVisibleTypeAnnotations attributes for method in class file %s" "Multiple RuntimeInvisibleTypeAnnotations attributes for method in class file %s" "Duplicate method name \"%s\" with signature \"%s\" in class file %s" "Multiple Signature attributes for Record component in class file %s" "Invalid Signature attribute length %u in Record component in class file %s" "Multiple RuntimeVisibleAnnotations attributes for Record component in class file %s" "Multiple RuntimeInvisibleAnnotations attributes for Record component in class file %s" "Multiple RuntimeVisibleTypeAnnotations attributes for Record component in class file %s" "Multiple RuntimeInvisibleTypeAnnotations attributes for Record component in class file %s" "Multiple SourceFile attributes in class file %s" "Multiple SourceDebugExtension attributes in class file %s" "Multiple InnerClasses attributes in class file %s" "Invalid Synthetic classfile attribute length %u in class file %s" "Invalid Deprecated classfile attribute length %u in class file %s" "Multiple Signature attributes in class file %s" "Wrong Signature attribute length %u in class file %s" "Multiple RuntimeVisibleAnnotations attributes in class file %s" "Multiple RuntimeInvisibleAnnotations attributes in class file %s" "Multiple EnclosingMethod attributes in class file %s" "Invalid class index in EnclosingMethod attribute in class file %s" "Multiple BootstrapMethods attributes in class file %s" "Multiple RuntimeVisibleTypeAnnotations attributes in class file %s" "Multiple RuntimeInvisibleTypeAnnotations attributes in class file %s" "Multiple NestMembers attributes in class file %s" "Conflicting NestHost and NestMembers attributes in class file %s" "Multiple NestHost attributes in class file %s" "Conflicting NestMembers and NestHost attributes in class file %s" "Multiple Record attributes in class file %s" "Multiple PermittedSubclasses attributes in class file %s" "PermittedSubclasses attribute in final class file %s" "Illegal UTF8 string in constant pool in class file %s" "Class name is empty or contains illegal character in descriptor in class file %s" "Array type descriptor has more than 255 dimensions in class file %s" "Unknown constant tag %u in class file %s"
20-11-2023