Description
Renier Roth opened SPR-14886 and commented
Another place where String.intern() can be used as described in issue #19428
is in
file: org.springframework.asm.ClassReader
line: 3463
{CODE}
/**
-
Reads a class constant pool item in {
@link
#b b}. <i>This method is -
intended for {
@link
Attribute} sub classes, and is normally not needed by -
class generators or adapters.</i>
-
@param
index
the start index of an unsigned short value in {@link #b b},
whose value is the index of a class constant pool item.
-
@param
buf
buffer to be used to read the item. This buffer must be
sufficiently large. It is not automatically resized.
@return
the String corresponding to the specified class item.
*/
public String readClass(final int index, final char[] buf) {
// computes the start index of the CONSTANT_Class item in b
// and reads the CONSTANT_Utf8 item designated by
// the first two bytes of this CONSTANT_Class item
return readUTF8(items[readUnsignedShort(index)], buf);
}
{CODE}
This is the most inner class i could find that create the String. So the return of this method can use ....intern()
This method is used internally inside the class for super / interface and other classnames.
Spring uses this ClassReader via an Visitor "AnnotationMetadataReadingVisitor" more precise the extend "ClassMetadataReadingVisitor".
This visitor is returned as an implementation for the Interface "AnnotationMetadata" inside "SimpleMetadataReader" which is the only implementation for an metadata reader in the "ScannedGenericBeanDefinition" definition which will be hold inside memory.
Complicated enough, if you read backwards the ScannedGenericBeanDefinition stores the metadata as a field. This is the Visitor described above, which uses the ASM ClassReader to generate the Strings. The Strings are stored multiple times in Memory, this can be avoided to intern the String inside this chain of classes - most inner one is ClassReader (see source above).
Affects: 4.3.4
Issue Links:
- Use String.intern() for Annotation and Class scanning [SPR-14862] #19428 Use String.intern() for Annotation and Class scanning
- Upgrade to ASM 5.2 [SPR-15071] #19637 Upgrade to ASM 5.2