From 0eaab898cc00e5104be541a646a34f86420fad96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Scheibe?= Date: Mon, 2 Sep 2019 23:14:01 +0200 Subject: [PATCH] Fix anonymous class serialization warnings 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 2366eaee69. 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 --- .../configfiles/ConfigByIdComparator.java | 14 ++++++++++++++ .../configfiles/GlobalConfigFiles$1.java | 18 ++++++++++++++++++ .../configfiles/GlobalConfigFiles.java | 7 +------ .../folder/FolderConfigFileProperty$1.java | 19 +++++++++++++++++++ .../folder/FolderConfigFileProperty.java | 9 ++------- 5 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 src/main/java/org/jenkinsci/plugins/configfiles/ConfigByIdComparator.java create mode 100644 src/main/java/org/jenkinsci/plugins/configfiles/GlobalConfigFiles$1.java create mode 100644 src/main/java/org/jenkinsci/plugins/configfiles/folder/FolderConfigFileProperty$1.java diff --git a/src/main/java/org/jenkinsci/plugins/configfiles/ConfigByIdComparator.java b/src/main/java/org/jenkinsci/plugins/configfiles/ConfigByIdComparator.java new file mode 100644 index 00000000..a39d717b --- /dev/null +++ b/src/main/java/org/jenkinsci/plugins/configfiles/ConfigByIdComparator.java @@ -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, Serializable { + + @Override + public int compare(Config c1, Config c2) { + return c1.id.compareTo(c2.id); + } +} diff --git a/src/main/java/org/jenkinsci/plugins/configfiles/GlobalConfigFiles$1.java b/src/main/java/org/jenkinsci/plugins/configfiles/GlobalConfigFiles$1.java new file mode 100644 index 00000000..8027378d --- /dev/null +++ b/src/main/java/org/jenkinsci/plugins/configfiles/GlobalConfigFiles$1.java @@ -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 } + * 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 {} diff --git a/src/main/java/org/jenkinsci/plugins/configfiles/GlobalConfigFiles.java b/src/main/java/org/jenkinsci/plugins/configfiles/GlobalConfigFiles.java index 21fa86be..7862e89f 100644 --- a/src/main/java/org/jenkinsci/plugins/configfiles/GlobalConfigFiles.java +++ b/src/main/java/org/jenkinsci/plugins/configfiles/GlobalConfigFiles.java @@ -30,12 +30,7 @@ @Symbol("globalConfigFiles") public class GlobalConfigFiles extends GlobalConfiguration implements ConfigFileStore { - private static Comparator COMPARATOR = new Comparator() { - @Override - public int compare(Config o1, Config o2) { - return o1.id.compareTo(o2.id); - } - }; + private static Comparator COMPARATOR = new ConfigByIdComparator(); private static ConfigProviderComparator CONFIGPROVIDER_COMPARATOR = new ConfigProviderComparator(); diff --git a/src/main/java/org/jenkinsci/plugins/configfiles/folder/FolderConfigFileProperty$1.java b/src/main/java/org/jenkinsci/plugins/configfiles/folder/FolderConfigFileProperty$1.java new file mode 100644 index 00000000..8ace7dbf --- /dev/null +++ b/src/main/java/org/jenkinsci/plugins/configfiles/folder/FolderConfigFileProperty$1.java @@ -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 } + * 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 {} diff --git a/src/main/java/org/jenkinsci/plugins/configfiles/folder/FolderConfigFileProperty.java b/src/main/java/org/jenkinsci/plugins/configfiles/folder/FolderConfigFileProperty.java index b0e83c79..ee93ce4d 100644 --- a/src/main/java/org/jenkinsci/plugins/configfiles/folder/FolderConfigFileProperty.java +++ b/src/main/java/org/jenkinsci/plugins/configfiles/folder/FolderConfigFileProperty.java @@ -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; @@ -16,15 +17,9 @@ import java.io.IOException; import java.util.*; - public class FolderConfigFileProperty extends AbstractFolderProperty> implements ConfigFileStore { - private static Comparator COMPARATOR = new Comparator() { - @Override - public int compare(Config o1, Config o2) { - return o1.id.compareTo(o2.id); - } - }; + private static Comparator COMPARATOR = new ConfigByIdComparator(); private static ConfigProviderComparator CONFIGPROVIDER_COMPARATOR = new ConfigProviderComparator();