Skip to content

Commit b84d7e6

Browse files
committed
Populate "small" numbers as Integers in the symbol cache
As specified by Java and thus expected by ClassReader and downstream consumers. Should fix #1809
1 parent e44d7ab commit b84d7e6

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/CachingClassSymbolClassReader.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.util.stream.StreamSupport;
3030

3131
import javax.lang.model.element.ElementKind;
32+
import javax.lang.model.type.PrimitiveType;
33+
import javax.lang.model.type.TypeKind;
3234
import javax.tools.JavaFileObject;
3335

3436
import org.eclipse.core.runtime.ILog;
@@ -192,8 +194,21 @@ public VarSymbol create(Symbol owner, CachingClassSymbolClassReader reader) {
192194
res.setData(ElementKind.EXCEPTION_PARAMETER);
193195
} else if (isDataResourceVariable) {
194196
res.setData(ElementKind.RESOURCE_VARIABLE);
195-
} else {
196-
res.setData(this.constantValue);
197+
} else if (this.constantValue != null) {
198+
Object o = this.constantValue;
199+
// In ClassReader AttributeReader(names.ConstantValue), we see that
200+
// integer non-Long types are expected to be stored as Integers in symbol
201+
if (res.type instanceof PrimitiveType primitive) {
202+
if (TypeKind.BOOLEAN == primitive.getKind() && o instanceof Boolean b) {
203+
// as per https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html#jvms-2.3.4
204+
o = Integer.valueOf(b.booleanValue() ? 1 : 0);
205+
} else if (TypeKind.CHAR == primitive.getKind() && o instanceof Character c) {
206+
o = Integer.valueOf((int)c.charValue());
207+
} else if (TypeKind.BYTE == primitive.getKind() && o instanceof Byte b) {
208+
o = Integer.valueOf((int)b.byteValue());
209+
}
210+
}
211+
res.setData(o);
197212
}
198213
this.metadata.applyTo(res, reader);
199214
reader.localAnnotate.normal(res, this.toAnnotate);

0 commit comments

Comments
 (0)