From dc7abd4f0f22fe950069cb2758acfc6fa86bd65d Mon Sep 17 00:00:00 2001 From: Col-E Date: Sun, 20 Feb 2022 20:49:36 -0500 Subject: [PATCH] fix: Element value union for classes points to UTF8 desc, not a Class CP entry --- .../cafedude/classfile/annotation/ClassElementValue.java | 4 ++-- .../cafedude/transform/IllegalStrippingTransformer.java | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/coley/cafedude/classfile/annotation/ClassElementValue.java b/src/main/java/me/coley/cafedude/classfile/annotation/ClassElementValue.java index 8ff09a3..be218fc 100644 --- a/src/main/java/me/coley/cafedude/classfile/annotation/ClassElementValue.java +++ b/src/main/java/me/coley/cafedude/classfile/annotation/ClassElementValue.java @@ -25,7 +25,7 @@ public ClassElementValue(char tag, int classIndex) { } /** - * @return Index of class constant. + * @return Index of a class's descriptor. */ public int getClassIndex() { return classIndex; @@ -33,7 +33,7 @@ public int getClassIndex() { /** * @param classIndex - * Index of class constant. + * Index of a class's descriptor. */ public void setClassIndex(int classIndex) { this.classIndex = classIndex; diff --git a/src/main/java/me/coley/cafedude/transform/IllegalStrippingTransformer.java b/src/main/java/me/coley/cafedude/transform/IllegalStrippingTransformer.java index 4c4ec85..da43ae5 100644 --- a/src/main/java/me/coley/cafedude/transform/IllegalStrippingTransformer.java +++ b/src/main/java/me/coley/cafedude/transform/IllegalStrippingTransformer.java @@ -83,6 +83,8 @@ public IllegalStrippingTransformer(ClassFile clazz) { super(clazz); } + // TODO: Make it possible to track if calling transform did remove anything + @Override public void transform() { logger.info("Transforming '{}'", clazz.getName()); @@ -476,8 +478,8 @@ private void addElementValueValidation(AttributeHolder holder, ElementValue elementValue) { if (elementValue instanceof ClassElementValue) { int classIndex = ((ClassElementValue) elementValue).getClassIndex(); - expectedTypeMasks.put(classIndex, i -> i == ConstantPool.CLASS); - cpEntryValidators.put(classIndex, matchClassType()); + expectedTypeMasks.put(classIndex, i -> i == ConstantPool.UTF8); + cpEntryValidators.put(classIndex, matchUtf8ClassType()); } else if (elementValue instanceof EnumElementValue) { EnumElementValue enumElementValue = (EnumElementValue) elementValue; expectedTypeMasks.put(enumElementValue.getNameIndex(), i -> i == ConstantPool.UTF8);