Skip to content

Commit

Permalink
Fix anonymous class serialization warnings
Browse files Browse the repository at this point in the history
Anonymous inner classes are replaced by a dedicated comparator class.

NOTE: Also introducing classes to keep XStream backward compatibility.
This was missed in the previous attempt in commit 2366eae.

The warnings from org.jenkinsci.remoting.util.AnonymousClassWarnings have been:
> "Attempt to (de-)serialize anonymous class org.jenkinsci.plugins.configfiles.GlobalConfigFiles$1 ..."
> "Attempt to (de-)serialize anonymous class org.jenkinsci.plugins.configfiles.folder.FolderConfigFileProperty$1 ..."
see: https://wiki.jenkins.io/display/JENKINS/Serialization+of+anonymous+classes
  • Loading branch information
darxriggs committed Sep 3, 2019
1 parent 8b8a1b0 commit 0eaab89
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.jenkinsci.plugins.configfiles;

import org.jenkinsci.lib.configprovider.model.Config;

import java.io.Serializable;
import java.util.Comparator;

public class ConfigByIdComparator implements Comparator<Config>, Serializable {

@Override
public int compare(Config c1, Config c2) {
return c1.id.compareTo(c2.id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.jenkinsci.plugins.configfiles;

import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;

/**
* This class is required for XStream backward compatibility because {@link GlobalConfigFiles}
* formerly contained an anonymous inner class defining the comparator.
*
* For old XML configurations that still contain a comparator element as follows
* {@code <comparator class="org.jenkinsci.plugins.configfiles.GlobalConfigFiles$1"/>}
* XStream tries to resolve a class named exactly like this during deserialization.
*
* @deprecated replaced by {@link ConfigByIdComparator}
*/
@Deprecated
@Restricted(DoNotUse.class)
final class GlobalConfigFiles$1 extends ConfigByIdComparator {}
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@
@Symbol("globalConfigFiles")
public class GlobalConfigFiles extends GlobalConfiguration implements ConfigFileStore {

private static Comparator<Config> COMPARATOR = new Comparator<Config>() {
@Override
public int compare(Config o1, Config o2) {
return o1.id.compareTo(o2.id);
}
};
private static Comparator<Config> COMPARATOR = new ConfigByIdComparator();

private static ConfigProviderComparator CONFIGPROVIDER_COMPARATOR = new ConfigProviderComparator();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.jenkinsci.plugins.configfiles.folder;

import org.jenkinsci.plugins.configfiles.ConfigByIdComparator;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;

/**
* This class is required for XStream backward compatibility because {@link FolderConfigFileProperty}
* formerly contained an anonymous inner class defining the comparator.
*
* For old XML configurations that still contain a comparator element as follows
* {@code <comparator class="org.jenkinsci.plugins.configfiles.folder.FolderConfigFileProperty$1"/>}
* XStream tries to resolve a class named exactly like this during deserialization.
*
* @deprecated replaced by {@link ConfigByIdComparator}
*/
@Deprecated
@Restricted(DoNotUse.class)
final class FolderConfigFileProperty$1 extends ConfigByIdComparator {}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.sf.json.JSONObject;
import org.jenkinsci.lib.configprovider.ConfigProvider;
import org.jenkinsci.lib.configprovider.model.Config;
import org.jenkinsci.plugins.configfiles.ConfigByIdComparator;
import org.jenkinsci.plugins.configfiles.ConfigByNameComparator;
import org.jenkinsci.plugins.configfiles.ConfigFileStore;
import org.jenkinsci.plugins.configfiles.ConfigProviderComparator;
Expand All @@ -16,15 +17,9 @@
import java.io.IOException;
import java.util.*;


public class FolderConfigFileProperty extends AbstractFolderProperty<AbstractFolder<?>> implements ConfigFileStore {

private static Comparator<Config> COMPARATOR = new Comparator<Config>() {
@Override
public int compare(Config o1, Config o2) {
return o1.id.compareTo(o2.id);
}
};
private static Comparator<Config> COMPARATOR = new ConfigByIdComparator();

private static ConfigProviderComparator CONFIGPROVIDER_COMPARATOR = new ConfigProviderComparator();

Expand Down

0 comments on commit 0eaab89

Please sign in to comment.