Skip to content
Permalink
Browse files

[FIXED JENKINS-44330] - Prevent classloading of Target comparator in …

…LogRecorder#orderedTargets()

It is just a hotfix, there may be other LogRecorders affected. Ideally we need a response from Jetty maintainers to eclipse/jetty.project#1563. No tests since I see no way to trigger such classloading + no actual need in it.
  • Loading branch information
oleg-nenashev committed May 20, 2017
1 parent d13b136 commit e4c4b810793aa4d118702608c16c1d680edbab89
Showing with 11 additions and 6 deletions.
  1. +11 −6 core/src/main/java/hudson/logging/LogRecorder.java
@@ -73,17 +73,14 @@
private volatile String name;

public final CopyOnWriteList<Target> targets = new CopyOnWriteList<Target>();

private final static TargetComparator TARGET_COMPARATOR = new TargetComparator();

@Restricted(NoExternalUse.class)
Target[] orderedTargets() {
// will contain targets ordered by reverse name length (place specific targets at the beginning)
Target[] ts = targets.toArray(new Target[]{});

Arrays.sort(ts, new Comparator<Target>() {
public int compare(Target left, Target right) {
return right.getName().length() - left.getName().length();
}
});
Arrays.sort(ts, TARGET_COMPARATOR);

return ts;
}
@@ -206,6 +203,14 @@ public void disable() {
}

}

private static class TargetComparator implements Comparator<Target> {

@Override
public int compare(Target left, Target right) {
return right.getName().length() - left.getName().length();
}
}

private static final class SetLevel extends MasterToSlaveCallable<Void,Error> {
/** known loggers (kept per agent), to avoid GC */

0 comments on commit e4c4b81

Please sign in to comment.