We're updating the issue view to help you get more done. 

ExceptionInInitializerError when changing System properties while Environment class is initialized

Description

When I start my program I set some System properties. At the same time Hibernate is started and the classes initialized.
This calls the static block in Environment which copies the System properties to GLOBAL_PROPERTIES. This is not thread-safe although Properties/Hashtables are used.
In the javadoc it says, that the Hashtable has to be synchronized when an iterator is used.

Change it from:

1 2 3 4 5 try { GLOBAL_PROPERTIES.putAll(systemProperties); } catch (SecurityException se) { LOG.unableToCopySystemProperties(); }

to

1 2 3 4 5 6 7 8 try { Properties systemProperties = System.getProperties(); synchronized (systemProperties) { GLOBAL_PROPERTIES.putAll(systemProperties); } } catch (SecurityException se) { LOG.unableToCopySystemProperties(); }

I attached a small test case which can reproduce this issue. It is very annoying because it happens randomly.

Environment

Windows 7 Hibernate 4.1.7 Java(TM) SE Runtime Environment, 1.7.0_13-b20

Status

Assignee

Brett Meyer

Reporter

Michael Schöndorfer

Labels

Suitable for new contributors

Yes, likely

Time Tracking

5m

Components

Fix versions

Affects versions

4.1.7
4.2.2

Priority

Major