Skip to content

Commit dbe3392

Browse files
authored
fix: check for duplicate annotations (#80)
1 parent 0739be3 commit dbe3392

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

classport-commons/src/main/java/io/github/project/classport/commons/AnnotationConstantPool.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,15 @@ public byte[] injectAnnotation(byte[] originalBytes, ConstantPoolData cpd) {
107107

108108
int rvaUtf8Index = findUtf8InConstantPool(existingCpData, originalConstantPoolCount - 1, "RuntimeVisibleAnnotations");
109109
boolean rvaExists = rvaUtf8Index > 0;
110+
111+
// check if ClassportInfo is already in the constant pool
112+
int classportInfoIndex = findUtf8InConstantPool(existingCpData, originalConstantPoolCount - 1, String.format("L%s;", ClassportInfo.class.getName().replace('.', '/')));
113+
boolean classportInfoExists = classportInfoIndex > 0;
114+
if (classportInfoExists) {
115+
// we don't want duplicate classport info entries
116+
// so we return the original bytes
117+
return originalBytes;
118+
}
110119

111120
int newConstantPoolCount = originalConstantPoolCount + cpd.entryCount();
112121
if (!rvaExists) {

0 commit comments

Comments
 (0)