Uploaded image for project: 'ZZZ: PUBLIC - Old Liferay Portal (Use Liferay Portal Standard Edition)'
  1. ZZZ: PUBLIC - Old Liferay Portal (Use Liferay Portal Standard Edition)
  2. LEP-3668

Please initialize the ApplicationContext in SpringUtil in a lazy manner...

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 4.3.1
    • Fix Version/s: 4.3.2, 4.4.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      Liferay 4.3.1

      Description

      I've been debugging an issue with trying to migrate our datamodel integration with liferay 4.3.1 and maven. We use Maven 2 to build all our portlets. We always run into issues with every new version of Liferay and they take hours to debug due to quirks in debuggers, trying to get any source code together, upgrading libraries that are discovered to be upgraded by liferay, and so on. One of the things that have plagued us this time is that the ApplicationContext is not lazy loaded whenever it is null. This is useful because of how the Maven surefire plugin uses an IsolatedClassloader when running unit tests. For us, due to the newest liferay changes, the ApplicationContext doesn't get initialized in SpringUtil (I think because of a buried exception, which I'll get to later) and then never tried to initialize again, this leads to a misleading error such as:

      Loading file:/C:/projects/Flare/trunk/FlareModel/target/test-classes/portal-ext.properties
      java.lang.ExceptionInInitializerError
      at com.liferay.portal.velocity.LiferayResourceCache.get(LiferayResourceCache.java:43)
      at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:288)
      at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1102)
      at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1077)
      at org.apache.velocity.runtime.VelocimacroFactory.initVelocimacro(VelocimacroFactory.java:196)
      at org.apache.velocity.runtime.RuntimeInstance.init(RuntimeInstance.java:251)
      at org.apache.velocity.runtime.RuntimeSingleton.init(RuntimeSingleton.java:113)
      at org.apache.velocity.app.Velocity.init(Velocity.java:83)
      at com.liferay.portal.events.InitAction.run(InitAction.java:229)
      at com.liferay.portal.util.InitUtil.init(InitUtil.java:40)
      at com.liferay.portal.util.PropsUtil.<clinit>(PropsUtil.java:41)
      at com.liferay.portal.spring.util.SpringUtil.<clinit>(SpringUtil.java:42)
      at com.liferay.portal.bean.BeanLocatorImpl.locate(BeanLocatorImpl.java:54)
      at com.liferay.portal.kernel.bean.BeanLocatorUtil.locate(BeanLocatorUtil.java:51)
      at com.liferay.portal.service.CompanyLocalServiceFactory._getFactory(CompanyLocalServiceFactory.java:70)
      at com.liferay.portal.service.CompanyLocalServiceFactory.getService(CompanyLocalServiceFactory.java:53)
      at com.liferay.portal.service.CompanyLocalServiceUtil.addCompany(CompanyLocalServiceUtil.java:73)
      at com.bae.gse.flare.model.LiferayDataModelImpl.performAddCorporation(LiferayDataModelImpl.java:76)
      at com.bae.gse.flare.model.AbstractFlareDataModel.addCorporation(AbstractFlareDataModel.java:47)
      at com.bae.gse.flare.model.LiferayDataModelImplTest.testUpdateRole(LiferayDataModelImplTest.java:235)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:552)
      at org.testng.internal.Invoker.invokeMethod(Invoker.java:411)
      at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:785)
      at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:114)
      at org.testng.TestRunner.privateRun(TestRunner.java:693)
      at org.testng.TestRunner.run(TestRunner.java:574)
      at org.testng.SuiteRunner.privateRun(SuiteRunner.java:241)
      at org.testng.SuiteRunner.run(SuiteRunner.java:145)
      at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:901)
      at org.testng.TestNG.runSuitesLocally(TestNG.java:863)
      at org.apache.maven.surefire.testng.TestNGExecutor.executeTestNG(TestNGExecutor.java:64)
      at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)
      at org.apache.maven.surefire.Surefire.run(Surefire.java:129)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:225)
      at org.apache.maven.surefire.booter.SurefireBooter.run(SurefireBooter.java:139)
      at org.apache.maven.plugin.surefire.SurefirePlugin.execute(SurefirePlugin.java:376)
      at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:443)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:539)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:480
      )
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:459)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java
      :311)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:278)
      at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:143)
      at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:334)
      at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:125)
      at org.apache.maven.cli.MavenCli.main(MavenCli.java:272)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
      at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
      at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
      at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
      Caused by: java.lang.NullPointerException
      at com.liferay.portal.bean.BeanLocatorImpl.locate(BeanLocatorImpl.java:60)
      at com.liferay.portal.kernel.bean.BeanLocatorUtil.locate(BeanLocatorUtil.java:51)
      at com.liferay.portal.kernel.cache.SingleVMPoolUtil._getUtil(SingleVMPoolUtil.java:94)
      at com.liferay.portal.kernel.cache.SingleVMPoolUtil.getSingleVMPool(SingleVMPoolUtil.java:59)
      at com.liferay.portal.kernel.cache.SingleVMPoolUtil.getCache(SingleVMPoolUtil.java:55)
      at com.liferay.portal.velocity.LiferayResourceCacheUtil.<clinit>(LiferayResourceCacheUtil.java:57)
      ... 62 more

      This is the only exception you will get when there are missing resources in a maven build environment. This is because in LazyClassPathApplicationContext, if a resource can't be loaded, then the exception is caught and hidden (unless the appropriate logging is turned on) and then it allows the application to continue. If a resource can't be loaded, then application should fail and it should be fixed. The application shouldn't be allowed to continue, since it results in the above exception and a lot of confusion:

      Line 50 of LazyClassPathApplicationContext:
      try

      { reader.loadBeanDefinitions(configLocations[i]); }

      catch (Exception e)

      { _log.warn(e); }

      I suggest that this is changed to allow the exception to propogate up and halt application processing instead of it trying to limp along.

      This is the current SpringUtil class:

      public class SpringUtil {

      public static ApplicationContext getContext()

      { return _ctx; }

      private static ApplicationContext _ctx =
      new LazyClassPathApplicationContext(
      PropsUtil.getArray(PropsUtil.SPRING_CONFIGS));

      }

      I suggest it changed to:

      public class SpringUtil {

      public static ApplicationContext getContext() {
      if(_ctx == null)

      { _ctx = new LazyClassPathApplicationContext( PropsUtil.getArray(PropsUtil.SPRING_CONFIGS)); }

      return _ctx;
      }

      private static ApplicationContext _ctx = null;

      }

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Packages

                Version Package
                4.3.2
                4.4.0