Duplicate attributes in class files

x4e_x4e x4e_x4e at protonmail.com
Mon Dec 28 16:02:37 UTC 2020


The current JVM specification (chapter 4) does not seem to place enough constraints on duplicate attributes.
What I mean by this is if two attributes share the same name (but not necessarily the same length or content).

The JVM specification does say that if two attributes have the same name and length this will result in a "conflict".
This seems to contradict with the current behavior of the JVM to reject classes that contain known attributes with the same name, regardless of their length.
See:
https://github.com/openjdk/jdk/blob/779ee1104ca7f506bd1113004a84745824a507d4/src/hotspot/share/classfile/classFileParser.cpp#L1364
https://github.com/openjdk/jdk/blob/779ee1104ca7f506bd1113004a84745824a507d4/src/hotspot/share/classfile/classFileParser.cpp#L1395
https://github.com/openjdk/jdk/blob/779ee1104ca7f506bd1113004a84745824a507d4/src/hotspot/share/classfile/classFileParser.cpp#L2503

Would it be a good idea to update the specification to explicitly deny duplicate named attributes?
This would also have a potential benefit of allowing attributes to be stored by implementations in HashTable for fast lookups by name. At the moment this seems to not be possible without collisions.


More information about the hotspot-dev mailing list