Skip to content

Commit

Permalink
Correct behaviour of removeRedundantExclusions
Browse files Browse the repository at this point in the history
  • Loading branch information
LunNova committed Sep 4, 2016
1 parent 4d2109a commit 27b7051
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/main/java/me/nallar/modpatcher/LaunchClassLoaderUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,16 @@ public static void removeRedundantExclusions() {
removeRedundantExclusions(getClassLoaderExceptions());
}

private static void removeRedundantExclusions(Set<String> transformerExceptions) {
Iterator<String> parts = transformerExceptions.iterator();
while (parts.hasNext()) {
String part = parts.next();

for (String part2 : new HashSet<>(transformerExceptions)) {
if (!part.equals(part2) && part.startsWith(part2)) {
parts.remove();
}
static void removeRedundantExclusions(Set<String> transformerExceptions) {
HashSet<String> old = new HashSet<>(transformerExceptions);

for (String exclusion : old) {
for (String exclusion2 : old) {
if (exclusion.equals(exclusion2))
continue;

if (exclusion.startsWith(exclusion2))
transformerExceptions.remove(exclusion);
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/me/nallar/modpatcher/LaunchClassLoaderUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package me.nallar.modpatcher;

import org.junit.Test;

import java.util.*;

public class LaunchClassLoaderUtilTest {
@Test
public void TestRemoveRedundantExclusions() {
HashSet<String> test = new HashSet<>();
test.add("me.nallar.test");
test.add("me.");
test.add("me.nallar");
test.add("org.example.banana");
test.add("org.example.apple");
test.add("org.example.pear");
test.add("org.example.apple.pear");

LaunchClassLoaderUtil.removeRedundantExclusions(test);
assert test.contains("me.");
assert test.contains("org.example.banana");
assert test.contains("org.example.apple");
assert test.contains("org.example.pear");
assert !test.contains("me.nallar");
assert !test.contains("me.nallar.test");
assert !test.contains("org.example.apple.pear");
}
}

0 comments on commit 27b7051

Please sign in to comment.