From 3acd4aad506faacd9b4ef9271df9bb0599300cae Mon Sep 17 00:00:00 2001 From: syev Date: Fri, 24 Oct 2014 11:50:17 +0200 Subject: Changed members detection update Check the members against all the new members, not only the ones that match the DiffCriteria. --- api/src/main/java/org/osjava/jardiff/JarDiff.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'api/src/main/java/org/osjava/jardiff/JarDiff.java') diff --git a/api/src/main/java/org/osjava/jardiff/JarDiff.java b/api/src/main/java/org/osjava/jardiff/JarDiff.java index 432993a..d391712 100644 --- a/api/src/main/java/org/osjava/jardiff/JarDiff.java +++ b/api/src/main/java/org/osjava/jardiff/JarDiff.java @@ -393,12 +393,12 @@ public class JarDiff } changedMethods.addAll(removedMethods); - changedMethods.retainAll(addedMethods); + changedMethods.retainAll(newMethods.keySet()); removedMethods.removeAll(changedMethods); removedMethods.removeAll(extNewMethods.keySet()); addedMethods.removeAll(changedMethods); changedFields.addAll(removedFields); - changedFields.retainAll(addedFields); + changedFields.retainAll(newFields.keySet()); removedFields.removeAll(changedFields); removedFields.removeAll(extNewFields.keySet()); addedFields.removeAll(changedFields); -- cgit v1.2.3 From 327e7fdf59a05f16a050b4132abe4b8b4b0d93be Mon Sep 17 00:00:00 2001 From: syev Date: Fri, 24 Oct 2014 18:46:01 +0200 Subject: Clarifications about access permissions checks Renamed the Tools method that checks the access permissions / visibility. Added comments. --- api/src/main/java/org/osjava/jardiff/JarDiff.java | 4 ++++ api/src/main/java/org/osjava/jardiff/Tools.java | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'api/src/main/java/org/osjava/jardiff/JarDiff.java') diff --git a/api/src/main/java/org/osjava/jardiff/JarDiff.java b/api/src/main/java/org/osjava/jardiff/JarDiff.java index d391712..24d92ff 100644 --- a/api/src/main/java/org/osjava/jardiff/JarDiff.java +++ b/api/src/main/java/org/osjava/jardiff/JarDiff.java @@ -392,7 +392,11 @@ public class JarDiff addedFields.add(entry.getKey()); } + // We add all the old methods that match the criteria changedMethods.addAll(removedMethods); + // We keep the intersection of these with all the new methods + // to detect as changed a method that no longer match the + // criteria (i.e. a method that was public and is now private) changedMethods.retainAll(newMethods.keySet()); removedMethods.removeAll(changedMethods); removedMethods.removeAll(extNewMethods.keySet()); diff --git a/api/src/main/java/org/osjava/jardiff/Tools.java b/api/src/main/java/org/osjava/jardiff/Tools.java index 41ba63c..42ba817 100644 --- a/api/src/main/java/org/osjava/jardiff/Tools.java +++ b/api/src/main/java/org/osjava/jardiff/Tools.java @@ -65,7 +65,7 @@ public final class Tools return (value & mask) == 0; } - private static boolean isLessAccessPermitted(int oldAccess, int newAccess) { + private static boolean isAccessIncompatible(int oldAccess, int newAccess) { if (has(newAccess, Opcodes.ACC_PUBLIC)) { return false; } else if (has(newAccess, Opcodes.ACC_PROTECTED)) { @@ -73,6 +73,7 @@ public final class Tools } else if (has(newAccess, Opcodes.ACC_PRIVATE)) { return not(oldAccess, Opcodes.ACC_PRIVATE); } else { + // new access is package, it is incompatible if old access was public or protected return has(oldAccess, Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED); } } @@ -175,7 +176,7 @@ public final class Tools * @return */ public static boolean isFieldAccessChange(final int oldAccess, final int newAccess) { - if (isLessAccessPermitted(oldAccess, newAccess)) { + if (isAccessIncompatible(oldAccess, newAccess)) { return true; // 13.4.7 } if ( not(oldAccess, Opcodes.ACC_FINAL) && has(newAccess, Opcodes.ACC_FINAL) ) { @@ -244,7 +245,7 @@ public final class Tools * @return */ public static boolean isMethodAccessChange(final int oldAccess, final int newAccess) { - if (isLessAccessPermitted(oldAccess, newAccess)) { + if (isAccessIncompatible(oldAccess, newAccess)) { return true; // 13.4.7 } if ( not(oldAccess, Opcodes.ACC_ABSTRACT) && has(newAccess, Opcodes.ACC_ABSTRACT) ) { -- cgit v1.2.3