Skip to content

Commit

Permalink
Do not report any incompatibilities if class becomes public
Browse files Browse the repository at this point in the history
  • Loading branch information
siom79 committed Nov 2, 2023
1 parent 77d89b9 commit c0ace88
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
19 changes: 7 additions & 12 deletions japicmp/src/main/java/japicmp/compat/CompatibilityChanges.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ private Map<String, JApiClass> buildClassMap(List<JApiClass> classes) {
}

private void evaluateBinaryCompatibility(JApiClass jApiClass, Map<String, JApiClass> classMap) {
if (jApiClass.getAccessModifier().hasChangedTo(AccessModifier.PUBLIC)) {
return; // class appears as "new" public class
}
if (jApiClass.getChangeStatus() == JApiChangeStatus.REMOVED) {
addCompatibilityChange(jApiClass, JApiCompatibilityChange.CLASS_REMOVED);
} else if (jApiClass.getChangeStatus() == JApiChangeStatus.MODIFIED) {
Expand Down Expand Up @@ -583,11 +586,11 @@ public JApiMethod callback(JApiClass implementedInterface, Map<String, JApiClass
}

private boolean isAbstract(JApiHasAbstractModifier jApiHasAbstractModifier) {
boolean isAbstract = false;
if (jApiHasAbstractModifier.getAbstractModifier().hasChangedTo(AbstractModifier.ABSTRACT)) {
isAbstract = true;
if (jApiHasAbstractModifier.getAbstractModifier().getNewModifier().isPresent()) {
AbstractModifier abstractModifier = jApiHasAbstractModifier.getAbstractModifier().getNewModifier().get();
return abstractModifier == AbstractModifier.ABSTRACT;
}
return isAbstract;
return false;
}

private void checkIfExceptionIsNowChecked(JApiBehavior behavior) {
Expand Down Expand Up @@ -840,14 +843,6 @@ public JApiSuperclass callback(JApiClass clazz, Map<String, JApiClass> classMap,
checkIfAbstractMethodAdded(jApiClass, classMap);
}

private boolean isAbstract(JApiMethod jApiMethod) {
if (jApiMethod.getAbstractModifier().getNewModifier().isPresent()) {
AbstractModifier abstractModifier = jApiMethod.getAbstractModifier().getNewModifier().get();
return abstractModifier == AbstractModifier.ABSTRACT;
}
return false;
}

private boolean hasSameType(JApiField field, JApiField otherField) {
boolean hasSameNewType = false;
if (field.getType().getNewTypeOptional().isPresent() && otherField.getType().getNewTypeOptional().isPresent()) {
Expand Down
5 changes: 3 additions & 2 deletions japicmp/src/main/java/japicmp/model/JApiModifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ public boolean hasChangedFrom(T oldValue) {

public boolean hasChangedTo(T value) {
boolean hasChangedTo = false;
if (newModifier.isPresent()) {
if (oldModifier.isPresent() && newModifier.isPresent()) {
T newValue = newModifier.get();
if (value == newValue) {
T oldValue = oldModifier.get();
if (value == newValue && oldValue != value) {
hasChangedTo = true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2214,14 +2214,16 @@ public List<CtClass> createOldClasses(ClassPool classPool) throws Exception {
public List<CtClass> createNewClasses(ClassPool classPool) throws Exception {
CtClass ctInterfaceF = CtInterfaceBuilder.create().name("F").addToClassPool(classPool);
CtClass ctClassFImpl = CtClassBuilder.create().name("FImpl").implementsInterface(ctInterfaceF).addToClassPool(classPool);
CtClass ctClassC = CtClassBuilder.create().name("C").notPublicModifier().addToClassPool(classPool);
CtClass ctClassC = CtClassBuilder.create().name("C").addToClassPool(classPool);
CtMethodBuilder.create().publicAccess().staticAccess().name("M").returnType(ctClassFImpl).addToClass(ctClassC);
return Arrays.asList(ctInterfaceF, ctClassC);
}
});
JApiClass jApiClass = getJApiClass(jApiClasses, "C");
JApiMethod jApiMethod = getJApiMethod(jApiClass.getMethods(), "M");
assertThat(jApiMethod.getChangeStatus(), is(JApiChangeStatus.MODIFIED));
assertThat(jApiMethod.getCompatibilityChanges(), hasItem(JApiCompatibilityChange.METHOD_RETURN_TYPE_CHANGED));
assertThat(jApiMethod.isBinaryCompatible(), is(true));
assertThat(jApiMethod.isSourceCompatible(), is(true));
assertThat(jApiMethod.getCompatibilityChanges().size(), is(0));
}
}

0 comments on commit c0ace88

Please sign in to comment.