Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #107 from jglick/cleanUpGlobalClassSet-NPE-JENKINS…
…-41945

[JENKINS-41945] Ignore null elements in ClassInfo.globalClassSet.items
  • Loading branch information
jglick committed Feb 13, 2017
2 parents 51c02d4 + 1155b88 commit 6fe6ea9
Showing 1 changed file with 6 additions and 1 deletion.
Expand Up @@ -1019,14 +1019,15 @@ private static void cleanUpGlobalClassValue(@Nonnull ClassLoader loader) throws
}

private static void cleanUpGlobalClassSet(@Nonnull Class<?> clazz) throws Exception {
Class<?> classInfoC = Class.forName("org.codehaus.groovy.reflection.ClassInfo");
Class<?> classInfoC = Class.forName("org.codehaus.groovy.reflection.ClassInfo"); // or just ClassInfo.class, but unclear whether this will always be there
Field globalClassSetF = classInfoC.getDeclaredField("globalClassSet");
globalClassSetF.setAccessible(true);
Object globalClassSet = globalClassSetF.get(null);
try { // Groovy 1
globalClassSet.getClass().getMethod("remove", Object.class).invoke(globalClassSet, clazz); // like Map but not
LOGGER.log(Level.FINER, "cleaning up {0} from GlobalClassSet", clazz.getName());
} catch (NoSuchMethodException x) { // Groovy 2
// Cannot just call .values() since that returns a copy.
Field itemsF = globalClassSet.getClass().getDeclaredField("items");
itemsF.setAccessible(true);
Object items = itemsF.get(globalClassSet);
Expand All @@ -1037,6 +1038,10 @@ private static void cleanUpGlobalClassSet(@Nonnull Class<?> clazz) throws Except
Iterator<?> iterator = (Iterator) iteratorM.invoke(items);
while (iterator.hasNext()) {
Object classInfo = iterator.next();
if (classInfo == null) {
LOGGER.finer("JENKINS-41945: ignoring null ClassInfo from ManagedLinkedList.Iter.next");
continue;
}
if (klazzF.get(classInfo) == clazz) {
iterator.remove();
LOGGER.log(Level.FINER, "cleaning up {0} from GlobalClassSet", clazz.getName());
Expand Down

0 comments on commit 6fe6ea9

Please sign in to comment.