Repository: jenkinsci/jenkins
File: core/src/main/java/hudson/PluginManager.java (Java)

Code before:
 * Constructors are searched in the order provided above and only the first found suitable constructor is
 * tried to build an instance. In the last two cases the {@link File} argument refers to the <i>Jenkins home directory</i>.
 *
 * @author Kohsuke Kawaguchi
 */
@ExportedBean
public abstract class PluginManager extends AbstractModelObject implements OnMaster, StaplerOverridable, StaplerProxy {
    /** Custom plugin manager system property or context param. */
    public static final String CUSTOM_PLUGIN_MANAGER = PluginManager.class.getName() + ".className";

    private static final Logger LOGGER = Logger.getLogger(PluginManager.class.getName());

    /**
     * Time elapsed between retries to check the updates sites. It's kind of constant, but let it so for tests
     */
    /* private final */ static int CHECK_UPDATE_SLEEP_TIME_MILLIS;

    /**
     * Number of attempts to check the updates sites. It's kind of constant, but let it so for tests
     */
    /* private final */ static int CHECK_UPDATE_ATTEMPTS;

    /**
     * Class name prefixes to skip in the class loading
     */
    private static final String[] CLASS_PREFIXES_TO_SKIP = new String[] {
            "SimpleTemplateScript",  // cf. groovy.text.SimpleTemplateEngine
            "groovy.tmp.templates.GStringTemplateScript", // Leaks on classLoader in some cases, see JENKINS-75879
    };

    static {
        try {
            // Secure initialization
            CHECK_UPDATE_SLEEP_TIME_MILLIS = SystemProperties.getInteger(PluginManager.class.getName() + ".checkUpdateSleepTimeMillis", 1000);
            CHECK_UPDATE_ATTEMPTS = SystemProperties.getInteger(PluginManager.class.getName() + ".checkUpdateAttempts", 1);
        } catch (RuntimeException e) {
            LOGGER.warning(String.format("There was an error initializing the PluginManager. Exception: %s", e));
        } finally {
            CHECK_UPDATE_ATTEMPTS = CHECK_UPDATE_ATTEMPTS > 0 ? CHECK_UPDATE_ATTEMPTS : 1;
            CHECK_UPDATE_SLEEP_TIME_MILLIS = CHECK_UPDATE_SLEEP_TIME_MILLIS > 0 ? CHECK_UPDATE_SLEEP_TIME_MILLIS : 1000;
        }
    }

    /** Accepted constructors for custom plugin manager, in the order they are tried. */
    private enum PMConstructor {
        JENKINS {
            @Override
            @NonNull
            PluginManager doCreate(@NonNull Class<? extends PluginManager> klass,
                                   @NonNull Jenkins jenkins) throws ReflectiveOperationException {
                return klass.getConstructor(Jenkins.class).newInstance(jenkins);

Review comment (suggestion):
or more concisely
```suggestion
    private static final String[] CLASS_PREFIXES_TO_SKIP = {
```

Code after:
 * Constructors are searched in the order provided above and only the first found suitable constructor is
 * tried to build an instance. In the last two cases the {@link File} argument refers to the <i>Jenkins home directory</i>.
 *
 * @author Kohsuke Kawaguchi
 */
@ExportedBean
public abstract class PluginManager extends AbstractModelObject implements OnMaster, StaplerOverridable, StaplerProxy {
    /** Custom plugin manager system property or context param. */
    public static final String CUSTOM_PLUGIN_MANAGER = PluginManager.class.getName() + ".className";

    private static final Logger LOGGER = Logger.getLogger(PluginManager.class.getName());

    /**
     * Time elapsed between retries to check the updates sites. It's kind of constant, but let it so for tests
     */
    /* private final */ static int CHECK_UPDATE_SLEEP_TIME_MILLIS;

    /**
     * Number of attempts to check the updates sites. It's kind of constant, but let it so for tests
     */
    /* private final */ static int CHECK_UPDATE_ATTEMPTS;

    /**
     * Class name prefixes to skip in the class loading
     */
    private static final String[] CLASS_PREFIXES_TO_SKIP = {
            "SimpleTemplateScript",  // cf. groovy.text.SimpleTemplateEngine
            "groovy.tmp.templates.GStringTemplateScript", // Leaks on classLoader in some cases, see JENKINS-75879
    };

    static {
        try {
            // Secure initialization
            CHECK_UPDATE_SLEEP_TIME_MILLIS = SystemProperties.getInteger(PluginManager.class.getName() + ".checkUpdateSleepTimeMillis", 1000);
            CHECK_UPDATE_ATTEMPTS = SystemProperties.getInteger(PluginManager.class.getName() + ".checkUpdateAttempts", 1);
        } catch (RuntimeException e) {
            LOGGER.warning(String.format("There was an error initializing the PluginManager. Exception: %s", e));
        } finally {
            CHECK_UPDATE_ATTEMPTS = CHECK_UPDATE_ATTEMPTS > 0 ? CHECK_UPDATE_ATTEMPTS : 1;
            CHECK_UPDATE_SLEEP_TIME_MILLIS = CHECK_UPDATE_SLEEP_TIME_MILLIS > 0 ? CHECK_UPDATE_SLEEP_TIME_MILLIS : 1000;
        }
    }

    /** Accepted constructors for custom plugin manager, in the order they are tried. */
    private enum PMConstructor {
        JENKINS {
            @Override
            @NonNull
            PluginManager doCreate(@NonNull Class<? extends PluginManager> klass,
                                   @NonNull Jenkins jenkins) throws ReflectiveOperationException {
                return klass.getConstructor(Jenkins.class).newInstance(jenkins);