Skip to content

StdSchedulerFactory ConcurrentModificationException reading system properties #474

Closed
@davidmoten

Description

Using quartz 2.3.1 I get the following exception occasionally on startup of a webapp in Tomcat.

java.util.ConcurrentModificationException
        at java.util.Hashtable$Enumerator.next(Hashtable.java:1387)
        at java.util.Hashtable.putAll(Hashtable.java:523)
        at org.quartz.impl.StdSchedulerFactory.overrideWithSysProps(StdSchedulerFactory.java:495)
        at org.quartz.impl.StdSchedulerFactory.initialize(StdSchedulerFactory.java:472)
        at org.quartz.impl.StdSchedulerFactory.getScheduler(StdSchedulerFactory.java:1552)

This is due to StdSchedulerFactory.overrideWithSysProps which looks like this:

/**
* Add all System properties to the given <code>props</code>. Will override
* any properties that already exist in the given <code>props</code>.
*/
private Properties overrideWithSysProps(Properties props) {
Properties sysProps = null;
try {
sysProps = System.getProperties();
} catch (AccessControlException e) {
getLog().warn(
"Skipping overriding quartz properties with System properties " +
"during initialization because of an AccessControlException. " +
"This is likely due to not having read/write access for " +
"java.util.PropertyPermission as required by java.lang.System.getProperties(). " +
"To resolve this warning, either add this permission to your policy file or " +
"use a non-default version of initialize().",
e);
}
if (sysProps != null) {
props.putAll(sysProps);
}

By calling putAll the entrySet() iterator is used on System.getProperties() which is not a thread-safe way of traversing System properties.

The fix would be to instead traverse the System properties by using the Enumeration propertyNames() and calling getProperty on each property name.

Happy to provide PR.

CC @SuperEventSteven

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions