Uploaded image for project: 'HiveMind'
  1. HiveMind
  2. HIVEMIND-78

Certain classloaders (AntClassLoader for example) cause NullPointerException in impl.MessageFormatter

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0, 1.1
    • 1.1
    • framework
    • None
    • MacOSX. Running unit tests of code running within hivemind using JUnit inside Ant inside Maven.

    Description

      MessageFormat uses java.lang.Class.getPackage() to obtain the name of the package for the 'reference class' in order to choose an appropriate resource bundle. Unfortunately, java.lang.Class.getPackage() does not guarantee to return a Package object.

      It may return 'null' if (a) the reference class is loaded by the primordial classloader, or (b) if the classloader didn't create a package object and associated it with the class.

      I am seeing this problem while running unit tests of my application within Maven. Example stacktrace follows:

      java.lang.ExceptionInInitializerError
      at org.apache.hivemind.impl.RegistryImpl.getServicePoint(RegistryImpl.java:142)
      at org.apache.hivemind.impl.RegistryImpl.getService(RegistryImpl.java:149)
      at org.apache.hivemind.impl.RegistryImpl.startup(RegistryImpl.java:321)
      at org.apache.hivemind.impl.RegistryBuilder.constructRegistry(RegistryBuilder.java:417)
      ... lots more
      Caused by: java.lang.NullPointerException
      at org.apache.hivemind.impl.MessageFormatter.<init>(MessageFormatter.java:49)
      at org.apache.hivemind.impl.MessageFormatter.<init>(MessageFormatter.java:44)
      at org.apache.hivemind.impl.ImplMessages.<clinit>(ImplMessages.java:45)
      ... 59 more

      The only safe way that I can see to achieve the same effect as Class.getPackage().getName() is to do something like:

      String lReferenceClassName = referenceClass.getName();
      String lPackageName = lReferenceClassName.substring(0,lReferenceClassName.lastIndexOf('.'));

      ... probably as a private function within MessageFormat itself.

      Attachments

        1. hivemind-package-defect.diff
          1 kB
          Paul Russell

        Activity

          People

            jwcarman James Carman
            prussell Paul Russell
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: