Skip to content

Commit

Permalink
Ignore changes to synthetic methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Apr 20, 2024
1 parent d7ce760 commit ba39ea9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ bin
# intellij
out
*.idea
*.iml
*.iml

output.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.neoforged.jarcompatibilitychecker.data.MemberInfo;
import net.neoforged.jarcompatibilitychecker.data.MethodInfo;
import net.neoforged.jarcompatibilitychecker.sort.TopologicalSort;
import net.neoforged.jarcompatibilitychecker.util.AccessHelpers;
import org.jetbrains.annotations.Nullable;
import org.objectweb.asm.Opcodes;

Expand Down Expand Up @@ -111,6 +112,9 @@ public static ClassInfoComparisonResults compare(boolean checkBinary, @Nullable
Set<MethodInfo> seenMethods = new HashSet<>();

for (MethodInfo baseInfo : baseClassInfo.getMethods().values()) {
// base synthetic -> ignore changes
if (AccessHelpers.isSynthetic(baseInfo)) continue;

boolean isStatic = (baseInfo.access & Opcodes.ACC_STATIC) != 0;
MethodInfo inputInfo = getMethodInfo(concreteClassInfo, concreteParents, isStatic, baseInfo.name, baseInfo.desc);
boolean methodInternal = isInternalApi(baseInfo, internalAnnotations, internalAnnotationCheckMode);
Expand All @@ -120,7 +124,8 @@ public static ClassInfoComparisonResults compare(boolean checkBinary, @Nullable
boolean isMethodError = !methodInternal || internalAnnotationCheckMode == InternalAnnotationCheckMode.ERROR;
boolean methodVisible = isVisible(checkBinary, baseInfo.access);

if (inputInfo == null) {
// base non-synthetic -> synthetic should be considered an error as synthetic methods aren't stable
if (inputInfo == null || AccessHelpers.isSynthetic(inputInfo)) {
if (checkBinary) {
results.addMethodIncompatibility(baseInfo, IncompatibilityMessages.METHOD_REMOVED, isMethodError);
} else if (methodVisible) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.neoforged.jarcompatibilitychecker.util;

import net.neoforged.jarcompatibilitychecker.data.MemberInfo;
import org.objectweb.asm.Opcodes;

public class AccessHelpers {
public static boolean isSynthetic(int access) {
return ((access & Opcodes.ACC_SYNTHETIC)) != 0;
}

public static boolean isSynthetic(MemberInfo info) {
return isSynthetic(info.getAccess());
}
}
3 changes: 3 additions & 0 deletions tests/base/src/main/java/com/example/test/TestClassA.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

public class TestClassA {
public String field;
public Runnable lambdaThing = () -> {
System.out.println("Hi!");
};
public void publicMethodA(String p1) {

}
Expand Down
1 change: 1 addition & 0 deletions tests/top/src/main/java/com/example/test/TestClassA.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

abstract class TestClassA {
public final String field = "a";
public Runnable lambdaThing;
private void publicMethodA(String p1) {

}
Expand Down

0 comments on commit ba39ea9

Please sign in to comment.