ComposeWarningsGuard is not thread safe

71 views
Skip to first unread message

Alex Objelean

unread,
Jul 30, 2012, 8:52:10 AM7/30/12
to closure-comp...@googlegroups.com
When running google closure compiler concurrently, I get the following stacktrace:

java.util.ConcurrentModificationException
	at java.util.TreeMap$PrivateEntryIterator.nextEntry(TreeMap.java:1100)
	at java.util.TreeMap$KeyIterator.next(TreeMap.java:1154)
	at com.google.javascript.jscomp.ComposeWarningsGuard.enables(ComposeWarningsGuard.java:150)
	at com.google.javascript.jscomp.CompilerOptions.enables(CompilerOptions.java:1027)
	at com.google.javascript.jscomp.Compiler.initOptions(Compiler.java:257)
	at com.google.javascript.jscomp.Compiler.initModules(Compiler.java:347)
	at com.google.javascript.jscomp.Compiler.init(Compiler.java:328)
	at com.google.javascript.jscomp.Compiler.compile(Compiler.java:536)
	at com.google.javascript.jscomp.Compiler.compile(Compiler.java:522)


I have created an issue for this problem: http://code.google.com/p/closure-compiler/issues/detail?id=781

Thanks,
Alex

Nick Santos

unread,
Jul 30, 2012, 9:27:30 AM7/30/12
to closure-comp...@googlegroups.com
Each Compiler is only meant for one compile job. Sharing a Compiler
object across threads doesn't really make sense. Can you elaborate a
bit more on what you're trying to do?

Alex Objelean

unread,
Jul 30, 2012, 9:39:37 AM7/30/12
to closure-comp...@googlegroups.com
I'm using the compiler job as a processor responsible for minimizing a javascript. The processor can be used in multi-threaded environment. Each processor reuses a single instance of the compiler. 
If for each processing I have to create a new compiler instance in order to avoid the problem, it is ok as a workaround. I just didn't know that it isn't thread-safe by its nature. 

Thanks,
Alex

Nick Santos

unread,
Jul 30, 2012, 9:55:54 AM7/30/12
to closure-comp...@googlegroups.com
Yeah, you should only be calling compile() once on each compiler
instance, or weird things will happen. We'll add some precondition
checks to prevent people from stubbing their toe on this in the
future.

Alex Objelean

unread,
Jul 30, 2012, 10:15:28 AM7/30/12
to closure-comp...@googlegroups.com
Actually I'm using a fresh new Compiler instance for each processing. Apparently the CompilerOptions is the problem. The CompilerOptions is not threadSafe, since I'm reusing the same instance for each compilation. Could this be fixed or should I find a workaround myself?

Thanks,
Alex
Reply all
Reply to author
Forward
0 new messages