Uploaded image for project: 'Hibernate ORM'
  1. HHH-8383

ExceptionInInitializerError when changing System properties while Environment class is initialized

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.1.7, 4.2.2
    • Fix Version/s: 4.3.0.Beta4, 4.2.5
    • Component/s: hibernate-core
    • Labels:
    • Environment:
      Windows 7
      Hibernate 4.1.7
      Java(TM) SE Runtime Environment, 1.7.0_13-b20
    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Suitable for new contributors:
      Yes, likely
    • Last commented by a user?:
      true
    • Sprint:

      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:

      try {
          GLOBAL_PROPERTIES.putAll(systemProperties);
      } catch (SecurityException se) {
          LOG.unableToCopySystemProperties();
      }
      

      to

      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.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 5m
                5m
                Remaining:
                Remaining Estimate - 5m
                5m
                Logged:
                Time Spent - Not Specified
                Not Specified