4 ms·
Java 9 compiler fails with the following error (for similar code): Error:(4, 9) java: UTF8 representation for string "LMain$Clazz<LMain$Cl..." is too long for
by kovrik 9y ago
Java 9 compiler fails with the following error (for similar code):
Error:(4, 9) java: UTF8 representation for string "LMain$Clazz<LMain$Cl..." is too long for the constant pool
- matthewwarren 9y agoHmm, I would've thought that this would be easier for the Java compiler to handle, because it uses type erasure for generics. So in metadata, everything is just 'Object' rather than exact types, but I'm no Java expert, so I could be wrong?
- DannyB2 9y agoSee my post above. I can confirm the problem in Java. It is a different problem than the C# compiler has. But it still runs into a limit.
- _old_dude_ 9y agoMost parts are erased, the method descriptor, the bytecode but the generic signature is kept for enabling separated compilation (you can also retrieve it by reflection). Here the generic signature which is a String is just too big, the dictionary part of the classfile, the constant pool, stores a String as an UTF8 byte array prefixed by its size on 16bits (hence the 65535 limit).
- matthewwarren 9y agoThanks for the info on Java generics, I always assumed that it 'erased' everything. I didn't appreciate that it would actually need to keep some info around, to make things work.
- tigershark 9y agoThe limit is the class (or method) name that is bigger than 65535 in this case, it has nothing to do specifically with generics because of type erasure.
- DannyB2 9y agoI can confirm a similar error. Java 8u152. Four 'Inner's work. Five gives error: The type generates a string that requires more than 65535 bytes to encode in Utf8 format in the constant pool This is using Eclipse. So it is the Eclipse compiler which is integrated with the editor. I haven't tried Oracle's Java compiler. Because the problem is to do with the size of a class constant pool, the limit of four Inner's should be universal across Java compilers, IDEs, and Operating Systems. (Assuming the class name mangling algorithm is part of the class specification.)