Skip to content

Commit c65774e

Browse files
committed
Fix regression in 529061b breaking ClassInfo equality checks
Because the info-importer is can be configured to skip method metadata (which it will by default) this broke the tests where the other model was using the metadata. Realistically if two JVM classes have the same byte-array then they are equal, and we dont need to do any model checking. Only if the array is different should we fall back to model checks.
1 parent f803eaa commit c65774e

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

recaf-core/src/main/java/software/coley/recaf/info/BasicJvmClassInfo.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,14 @@ public int getVersion() {
4949
public boolean equals(Object o) {
5050
if (this == o) return true;
5151
if (o == null) return false;
52-
if (!super.equals(o)) return false;
5352

5453
if (o instanceof JvmClassInfo other) {
5554
if (version != other.getVersion()) return false;
5655
return Arrays.equals(bytecode, other.getBytecode());
56+
} else if (!super.equals(o)) {
57+
return false;
5758
}
59+
5860
return false;
5961
}
6062

recaf-core/src/main/java/software/coley/recaf/info/builder/JvmClassInfoBuilder.java

+12
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ public JvmClassInfoBuilder(@Nonnull ClassReader reader) {
8585
adaptFrom(reader);
8686
}
8787

88+
/**
89+
* Creates a builder with data pulled from the given bytecode.
90+
*
91+
* @param reader
92+
* ASM class reader to read bytecode from.
93+
* @param readerFlags
94+
* Reader flags to use when populating information via {@link ClassReader#accept(ClassVisitor, int)}.
95+
*/
96+
public JvmClassInfoBuilder(@Nonnull ClassReader reader, int readerFlags) {
97+
adaptFrom(reader, readerFlags);
98+
}
99+
88100
/**
89101
* Creates a builder with the given bytecode.
90102
*

recaf-core/src/test/java/software/coley/recaf/info/JvmClassInfoTest.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
import org.junit.jupiter.api.BeforeAll;
44
import org.junit.jupiter.api.Test;
5+
import org.objectweb.asm.Opcodes;
56
import software.coley.cafedude.classfile.VersionConstants;
67
import software.coley.recaf.test.TestClassUtils;
78
import software.coley.recaf.test.dummy.AccessibleFields;
89
import software.coley.recaf.util.ByteHeaderUtil;
910

1011
import java.io.IOException;
12+
import java.util.Arrays;
1113

1214
import static org.junit.jupiter.api.Assertions.*;
1315

@@ -93,8 +95,10 @@ void toBuilder() {
9395
"Direct copy via builder should have same class equality");
9496

9597
// With modification
98+
byte[] modifiedBytecode = Arrays.copyOf(accessibleFields.getBytecode(), accessibleFields.getBytecode().length);
99+
modifiedBytecode[5] = 1; // Change minor version to any non-zero value
96100
JvmClassInfo builderModifiedCopy = accessibleFields.toJvmClassBuilder()
97-
.withName("Modified")
101+
.withBytecode(modifiedBytecode)
98102
.build();
99103
assertNotEquals(accessibleFields, builderModifiedCopy,
100104
"Direct copy via builder should have same class equality");

0 commit comments

Comments
 (0)