alexo / wro4j

New project location is:https://github.com/wro4j/wro4j
442 stars 110 forks source link

NPE in LazyProcessorDecorator when running parallelProcessing #210

Closed muffl0n closed 10 years ago

muffl0n commented 10 years ago

This seems like a problem with concurrency to me: It happened twice in the last few days while around 30 builds ran without any problems.

[ERROR] Exception occured while processing: ro.isdc.wro.WroRuntimeException, class: ro.isdc.wro.WroRuntimeException,caused by: java.lang.NullPointerException
ro.isdc.wro.WroRuntimeException
    at ro.isdc.wro.WroRuntimeException.wrap(WroRuntimeException.java:69)
    at ro.isdc.wro.WroRuntimeException.wrap(WroRuntimeException.java:54)
    at ro.isdc.wro.maven.plugin.AbstractWro4jMojo$1.onException(AbstractWro4jMojo.java:415)
    at ro.isdc.wro.util.concurrent.TaskExecutor.doConsumeResult(TaskExecutor.java:170)
    at ro.isdc.wro.util.concurrent.TaskExecutor.submit(TaskExecutor.java:106)
    at ro.isdc.wro.maven.plugin.Wro4jMojo.doExecute(Wro4jMojo.java:164)
    at ro.isdc.wro.maven.plugin.AbstractWro4jMojo.execute(AbstractWro4jMojo.java:169)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: java.lang.NullPointerException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:536)
    at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:941)
    at ro.isdc.wro.util.concurrent.TaskExecutor.doConsumeResult(TaskExecutor.java:160)
    ... 24 more
Caused by: java.lang.NullPointerException
    at ro.isdc.wro.model.resource.processor.decorator.LazyProcessorDecorator.getProcessorDecorator(LazyProcessorDecorator.java:39)
    at ro.isdc.wro.model.resource.processor.decorator.LazyProcessorDecorator.getSupportedResourceType(LazyProcessorDecorator.java:64)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceTypeForProcessor(AbstractProcessorDecoratorSupport.java:71)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceTypeInternal(AbstractProcessorDecoratorSupport.java:57)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceType(AbstractProcessorDecoratorSupport.java:50)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceTypeForProcessor(AbstractProcessorDecoratorSupport.java:71)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceTypeInternal(AbstractProcessorDecoratorSupport.java:57)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceType(AbstractProcessorDecoratorSupport.java:50)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceTypeForProcessor(AbstractProcessorDecoratorSupport.java:71)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceTypeInternal(AbstractProcessorDecoratorSupport.java:57)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceType(AbstractProcessorDecoratorSupport.java:50)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceTypeForProcessor(AbstractProcessorDecoratorSupport.java:71)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceTypeInternal(AbstractProcessorDecoratorSupport.java:57)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceType(AbstractProcessorDecoratorSupport.java:50)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceTypeForProcessor(AbstractProcessorDecoratorSupport.java:71)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceTypeInternal(AbstractProcessorDecoratorSupport.java:57)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceType(AbstractProcessorDecoratorSupport.java:50)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceTypeForProcessor(AbstractProcessorDecoratorSupport.java:71)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceTypeInternal(AbstractProcessorDecoratorSupport.java:57)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceType(AbstractProcessorDecoratorSupport.java:50)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceTypeForProcessor(AbstractProcessorDecoratorSupport.java:71)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceTypeInternal(AbstractProcessorDecoratorSupport.java:57)
    at ro.isdc.wro.model.resource.processor.decorator.AbstractProcessorDecoratorSupport.getSupportedResourceType(AbstractProcessorDecoratorSupport.java:50)
    at ro.isdc.wro.model.resource.processor.decorator.ProcessorDecorator.isEligible(ProcessorDecorator.java:109)
    at ro.isdc.wro.model.resource.processor.decorator.DefaultProcessorDecorator.isEnabled(DefaultProcessorDecorator.java:61)
    at ro.isdc.wro.model.resource.processor.decorator.ProcessorDecorator.process(ProcessorDecorator.java:87)
    at ro.isdc.wro.model.resource.processor.decorator.DefaultProcessorDecorator.process(DefaultProcessorDecorator.java:42)
    at ro.isdc.wro.model.group.processor.GroupsProcessor$1.process(GroupsProcessor.java:131)
    at ro.isdc.wro.model.group.processor.GroupsProcessor.applyPostProcessors(GroupsProcessor.java:115)
    at ro.isdc.wro.model.group.processor.GroupsProcessor.process(GroupsProcessor.java:84)
    at ro.isdc.wro.cache.support.DefaultSynchronizedCacheStrategyDecorator.loadValue(DefaultSynchronizedCacheStrategyDecorator.java:101)
    at ro.isdc.wro.cache.support.DefaultSynchronizedCacheStrategyDecorator.loadValue(DefaultSynchronizedCacheStrategyDecorator.java:1)
    at ro.isdc.wro.cache.support.AbstractSynchronizedCacheStrategyDecorator.get(AbstractSynchronizedCacheStrategyDecorator.java:55)
    at ro.isdc.wro.manager.ResourceBundleProcessor.serveProcessedBundle(ResourceBundleProcessor.java:63)
    at ro.isdc.wro.manager.WroManager.process(WroManager.java:159)
    at ro.isdc.wro.maven.plugin.Wro4jMojo.processGroup(Wro4jMojo.java:275)
    at ro.isdc.wro.maven.plugin.Wro4jMojo.access$0(Wro4jMojo.java:251)
    at ro.isdc.wro.maven.plugin.Wro4jMojo$1.call(Wro4jMojo.java:154)
    at ro.isdc.wro.maven.plugin.Wro4jMojo$1.call(Wro4jMojo.java:1)
    at ro.isdc.wro.config.support.ContextPropagatingCallable.call(ContextPropagatingCallable.java:62)
    at ro.isdc.wro.util.concurrent.TaskExecutor$1.call(TaskExecutor.java:126)
    at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1288)
    at java.util.concurrent.ForkJoinTask.doInvoke(ForkJoinTask.java:377)
    at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:654)
    at java.util.concurrent.ForkJoinTask$AdaptedCallable.run(ForkJoinTask.java:1298)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ForkJoinTask$AdaptedRunnable.exec(ForkJoinTask.java:1265)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:334)
    at java.util.concurrent.ForkJoinWorkerThread.execTask(ForkJoinWorkerThread.java:604)
    at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:784)
    at java.util.concurrent.ForkJoinPool.work(ForkJoinPool.java:646)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:398)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:02.236s
[INFO] Finished at: Mon Sep 22 16:55:38 CEST 2014
[INFO] Final Memory: 45M/316M
[...]
[ERROR] Failed to execute goal ro.isdc.wro4j:wro4j-maven-plugin:1.7.7-SNAPSHOT:run (css_ndr) on project ndr-web: Exception occured while processing: ro.isdc.wro.WroRuntimeException, class: ro.isdc.wro.WroRuntimeException,caused by: java.lang.NullPointerException -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

LazyProcessorDecorator.java:

36  private ProcessorDecorator getProcessorDecorator() {
37    if (processor == null) {
38      processor = new ProcessorDecorator(getDecoratedObject().get());
39      injector.inject(processor);
40    }
41    return processor;
42  }

I'm quite uninformed how the whole processor/decorator stuff works, so unfortunately I have absolutely no clue what is going on there. :)

alexo commented 10 years ago

Thanks for reporting this issue.

alexo commented 10 years ago

The only way to avoid this issue currently, is by not using "parallelProcessing" property.

muffl0n commented 10 years ago

The build failed again, but this time in another Class:

[ERROR] Exception occured while processing: ro.isdc.wro.WroRuntimeException, class: ro.isdc.wro.WroRuntimeException,caused by: java.lang.NullPointerException
ro.isdc.wro.WroRuntimeException
    at ro.isdc.wro.WroRuntimeException.wrap(WroRuntimeException.java:69)
    at ro.isdc.wro.WroRuntimeException.wrap(WroRuntimeException.java:54)
    at ro.isdc.wro.maven.plugin.AbstractWro4jMojo$1.onException(AbstractWro4jMojo.java:415)
    at ro.isdc.wro.util.concurrent.TaskExecutor.doConsumeResult(TaskExecutor.java:170)
    at ro.isdc.wro.util.concurrent.TaskExecutor.submit(TaskExecutor.java:106)
    at ro.isdc.wro.maven.plugin.Wro4jMojo.doExecute(Wro4jMojo.java:164)
    at ro.isdc.wro.maven.plugin.AbstractWro4jMojo.execute(AbstractWro4jMojo.java:169)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: java.lang.NullPointerException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:536)
    at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:941)
    at ro.isdc.wro.util.concurrent.TaskExecutor.doConsumeResult(TaskExecutor.java:160)
    ... 24 more
Caused by: java.lang.NullPointerException
    at ro.isdc.wro.model.resource.processor.decorator.ExceptionHandlingProcessorDecorator.isIgnoreFailingProcessor(ExceptionHandlingProcessorDecorator.java:80)
    at ro.isdc.wro.model.resource.processor.decorator.ExceptionHandlingProcessorDecorator.process(ExceptionHandlingProcessorDecorator.java:60)
    at ro.isdc.wro.model.resource.processor.decorator.ProcessorDecorator.process(ProcessorDecorator.java:89)
    at ro.isdc.wro.model.resource.processor.decorator.BenchmarkProcessorDecorator.process(BenchmarkProcessorDecorator.java:44)
    at ro.isdc.wro.model.resource.processor.decorator.ProcessorDecorator.process(ProcessorDecorator.java:89)
    at ro.isdc.wro.model.resource.processor.decorator.DefaultProcessorDecorator.process(DefaultProcessorDecorator.java:42)
    at ro.isdc.wro.model.group.processor.PreProcessorExecutor$2.process(PreProcessorExecutor.java:227)
    at ro.isdc.wro.model.group.processor.PreProcessorExecutor.applyPreProcessors(PreProcessorExecutor.java:207)
    at ro.isdc.wro.model.group.processor.PreProcessorExecutor.processAndMerge(PreProcessorExecutor.java:103)
    at ro.isdc.wro.model.group.processor.PreProcessorExecutor.processAndMerge(PreProcessorExecutor.java:77)
    at ro.isdc.wro.model.group.processor.GroupsProcessor.process(GroupsProcessor.java:83)
    at ro.isdc.wro.cache.support.DefaultSynchronizedCacheStrategyDecorator.loadValue(DefaultSynchronizedCacheStrategyDecorator.java:101)
    at ro.isdc.wro.cache.support.DefaultSynchronizedCacheStrategyDecorator.loadValue(DefaultSynchronizedCacheStrategyDecorator.java:1)
    at ro.isdc.wro.cache.support.AbstractSynchronizedCacheStrategyDecorator.get(AbstractSynchronizedCacheStrategyDecorator.java:55)
    at ro.isdc.wro.manager.ResourceBundleProcessor.serveProcessedBundle(ResourceBundleProcessor.java:63)
    at ro.isdc.wro.manager.WroManager.process(WroManager.java:159)
    at ro.isdc.wro.maven.plugin.Wro4jMojo.processGroup(Wro4jMojo.java:275)
    at ro.isdc.wro.maven.plugin.Wro4jMojo.access$0(Wro4jMojo.java:251)
    at ro.isdc.wro.maven.plugin.Wro4jMojo$1.call(Wro4jMojo.java:154)
    at ro.isdc.wro.maven.plugin.Wro4jMojo$1.call(Wro4jMojo.java:1)
    at ro.isdc.wro.config.support.ContextPropagatingCallable.call(ContextPropagatingCallable.java:62)
    at ro.isdc.wro.util.concurrent.TaskExecutor$1.call(TaskExecutor.java:126)
    at java.util.concurrent.ForkJoinTask$AdaptedCallable.exec(ForkJoinTask.java:1288)
    at java.util.concurrent.ForkJoinTask.doInvoke(ForkJoinTask.java:377)
    at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:654)
    at java.util.concurrent.ForkJoinTask$AdaptedCallable.run(ForkJoinTask.java:1298)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ForkJoinTask$AdaptedRunnable.exec(ForkJoinTask.java:1265)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:334)
    at java.util.concurrent.ForkJoinWorkerThread.execTask(ForkJoinWorkerThread.java:604)
    at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:784)
    at java.util.concurrent.ForkJoinPool.work(ForkJoinPool.java:646)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:398)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 35.409s
[INFO] Finished at: Tue Sep 23 13:36:50 CEST 2014
[INFO] Final Memory: 30M/316M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal ro.isdc.wro4j:wro4j-maven-plugin:1.7.7-SNAPSHOT:run (css_ndr) on project ndr-web: Exception occured while processing: ro.isdc.wro.WroRuntimeException, class: ro.isdc.wro.WroRuntimeException,caused by: java.lang.NullPointerException -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
79  protected boolean isIgnoreFailingProcessor() {
80    return context.getConfig().isIgnoreFailingProcessor();
81  }

The problem seems related because "context" get's injected similar to "injector" in the starting post:

  @Inject
  private ReadOnlyContext context;
alexo commented 10 years ago

It would help if I could reproduce it with unit tests... The first attempt to reproduce failed.
I have a feeling that synchronizing a code where each processor is decorated (to be injected) would fix it. But since I cannot reproduce it easily, I cannot be sure. Could you help me with a little experiment (trial and error)?

muffl0n commented 10 years ago

Reproducing concurrency problems always sucks. :) Surely, I'd be glad to assist you with any help I can provide.

alexo commented 10 years ago

Synchronize the following methods: PreProcessorExecutor#decoratePreProcessor GroupsProcessor#decorateProcessor

And let me know if you can reproduce the issue with the new build.

Thanks, Alex

muffl0n commented 10 years ago

I hope I can give this a try tomorrow. For today I'm out of the office.

muffl0n commented 10 years ago

I created a new branch for this: https://github.com/muffl0n/wro4j/tree/1.7_synchronize_processor Will give it a try with our Jenkins now.

muffl0n commented 10 years ago

So far the build runs without error. Time will tell if this patch fixes the NPE.

alexo commented 10 years ago

Ok, I'll include this fix in next release. I'm planning to release it today... there are enough useful changes to release it.

On 25 September 2014 10:46, Sven Schliesing notifications@github.com wrote:

So far the build runs without error. Time will tell if this patch fixes the NPE.

— Reply to this email directly or view it on GitHub https://github.com/alexo/wro4j/issues/210#issuecomment-56785130.

alexo commented 10 years ago

Fixed in branch 1.7.x