lishunli / projectlombok

Automatically exported from code.google.com/p/projectlombok
0 stars 0 forks source link

Eclipse freezes due to multi thread WeakHashMap access in lombok #590

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Start Eclipse with many projects with many lombok annotations.
2. Immediately start to edit files.

What is the expected output? What do you see instead?
Eclipse should work normally. Instead Eclipse freezes.

What version of the product are you using? On what operating system?
Eclipse 4.2.2, Win 7, Eclipse running with jdk1.7.0_40 (same behavior seen with 
1.6.* too)

Please provide any additional information below.
I looked up threads in jconsole. Last time Eclipse froze it had 4 threads 
accessing a WeakHashMap:

Name: Worker-199
Stack trace: 
 java.util.WeakHashMap.getEntry(WeakHashMap.java:498)
java.util.WeakHashMap.containsKey(WeakHashMap.java:485)
lombok.eclipse.handlers.EclipseHandlerUtil.findGetter(EclipseHandlerUtil.java:88
3)
lombok.eclipse.handlers.EclipseHandlerUtil.getFieldType(EclipseHandlerUtil.java:
961)
lombok.eclipse.handlers.HandleEqualsAndHashCode.createEquals(HandleEqualsAndHash
Code.java:618)
lombok.eclipse.handlers.HandleEqualsAndHashCode.generateMethods(HandleEqualsAndH
ashCode.java:235)
lombok.eclipse.handlers.HandleEqualsAndHashCode.handle(HandleEqualsAndHashCode.j
ava:140)
lombok.eclipse.HandlerLibrary$AnnotationHandlerContainer.handle(HandlerLibrary.j
ava:103)
lombok.eclipse.HandlerLibrary.handleAnnotation(HandlerLibrary.java:237)
lombok.eclipse.TransformEclipseAST$AnnotationVisitor.visitAnnotationOnType(Trans
formEclipseAST.java:209)
lombok.eclipse.EclipseNode.traverse(EclipseNode.java:96)
...
org.eclipse.ui.internal.decorators.LightweightDecoratorManager.decorate(Lightwei
ghtDecoratorManager.java:365)
org.eclipse.ui.internal.decorators.LightweightDecoratorManager.getDecorations(Li
ghtweightDecoratorManager.java:347)
org.eclipse.ui.internal.decorators.DecorationScheduler$1.ensureResultCached(Deco
rationScheduler.java:371)
org.eclipse.ui.internal.decorators.DecorationScheduler$1.run(DecorationScheduler
.java:331)
org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

Name: Worker-202
Stack trace: 
 java.util.WeakHashMap.put(WeakHashMap.java:521)
lombok.eclipse.handlers.EclipseHandlerUtil.registerCreatedLazyGetter(EclipseHand
lerUtil.java:873)
lombok.eclipse.handlers.HandleGetter.createGetter(HandleGetter.java:262)
lombok.eclipse.handlers.HandleGetter.createGetterForField(HandleGetter.java:218)
lombok.eclipse.handlers.HandleGetter.createGetterForFields(HandleGetter.java:166
)
lombok.eclipse.handlers.HandleGetter.handle(HandleGetter.java:152)
lombok.eclipse.HandlerLibrary$AnnotationHandlerContainer.handle(HandlerLibrary.j
ava:103)
lombok.eclipse.HandlerLibrary.handleAnnotation(HandlerLibrary.java:237)
lombok.eclipse.TransformEclipseAST$AnnotationVisitor.visitAnnotationOnField(Tran
sformEclipseAST.java:189)
lombok.eclipse.EclipseNode.traverse(EclipseNode.java:99)
...
org.eclipse.jdt.ui.SharedASTProvider.getAST(SharedASTProvider.java:128)
org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartList
enerGroup.calculateASTandInform(SelectionListenerWithASTManager.java:170)
org.eclipse.jdt.internal.ui.viewsupport.SelectionListenerWithASTManager$PartList
enerGroup$3.run(SelectionListenerWithASTManager.java:155)
   - locked java.lang.Object@45aa9603
org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

Name: org.eclipse.jdt.internal.ui.text.JavaReconciler
Stack trace: 
 java.util.WeakHashMap.put(WeakHashMap.java:521)
lombok.eclipse.handlers.EclipseHandlerUtil.registerCreatedLazyGetter(EclipseHand
lerUtil.java:873)
lombok.eclipse.handlers.HandleGetter.createGetter(HandleGetter.java:262)
lombok.eclipse.handlers.HandleGetter.createGetterForField(HandleGetter.java:218)
lombok.eclipse.handlers.HandleGetter.createGetterForFields(HandleGetter.java:166
)
lombok.eclipse.handlers.HandleGetter.handle(HandleGetter.java:152)
lombok.eclipse.HandlerLibrary$AnnotationHandlerContainer.handle(HandlerLibrary.j
ava:103)
lombok.eclipse.HandlerLibrary.handleAnnotation(HandlerLibrary.java:237)
lombok.eclipse.TransformEclipseAST$AnnotationVisitor.visitAnnotationOnField(Tran
sformEclipseAST.java:189)
lombok.eclipse.EclipseNode.traverse(EclipseNode.java:99)
...
org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReco
ncilingStrategy.java:87)
org.eclipse.jdt.internal.ui.text.java.JavaReconcilingStrategy.reconcile(JavaReco
ncilingStrategy.java:151)
org.eclipse.jdt.internal.ui.text.CompositeReconcilingStrategy.reconcile(Composit
eReconcilingStrategy.java:86)
org.eclipse.jdt.internal.ui.text.JavaCompositeReconcilingStrategy.reconcile(Java
CompositeReconcilingStrategy.java:104)
org.eclipse.jface.text.reconciler.MonoReconciler.process(MonoReconciler.java:77)
org.eclipse.jface.text.reconciler.AbstractReconciler$BackgroundThread.run(Abstra
ctReconciler.java:206)

Name: ModalContext
Stack trace: 
 java.util.WeakHashMap.put(WeakHashMap.java:521)
lombok.eclipse.handlers.EclipseHandlerUtil.registerCreatedLazyGetter(EclipseHand
lerUtil.java:873)
lombok.eclipse.handlers.HandleGetter.createGetter(HandleGetter.java:262)
lombok.eclipse.handlers.HandleGetter.createGetterForField(HandleGetter.java:218)
lombok.eclipse.handlers.HandleGetter.createGetterForFields(HandleGetter.java:166
)
lombok.eclipse.handlers.HandleGetter.handle(HandleGetter.java:152)
lombok.eclipse.HandlerLibrary$AnnotationHandlerContainer.handle(HandlerLibrary.j
ava:103)
lombok.eclipse.HandlerLibrary.handleAnnotation(HandlerLibrary.java:237)
lombok.eclipse.TransformEclipseAST$AnnotationVisitor.visitAnnotationOnField(Tran
sformEclipseAST.java:189)
lombok.eclipse.EclipseNode.traverse(EclipseNode.java:99)
...
org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:162)
org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:37
7)
org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:37
1)
org.eclipse.jdt.internal.ui.actions.SelectionConverter.codeResolve(SelectionConv
erter.java:273)
org.eclipse.jdt.internal.ui.actions.SelectionConverter$1CodeResolveRunnable.run(
SelectionConverter.java:257)
org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.jav
a:121)

Cause:
WeakHashMap is not thread safe.

Solution:
change line 868 in EclipseHandlerUtil from:
private static final Map<FieldDeclaration, Object> 
generatedLazyGettersWithPrimitiveBoolean = new WeakHashMap<FieldDeclaration, 
Object>();
to:
private static final Map<FieldDeclaration, Object> 
generatedLazyGettersWithPrimitiveBoolean = Collections.synchronizedMap(new 
WeakHashMap<FieldDeclaration, Object>());

Original issue reported on code.google.com by nutin.ha...@gmail.com on 11 Oct 2013 at 1:16

GoogleCodeExporter commented 9 years ago

Original comment by r.spilker on 20 Nov 2013 at 1:42

GoogleCodeExporter commented 9 years ago
Hmm, we've overlooked this issue. Working on it right now. We're not just 
solving this problem, but also other similar potential problems.

Original comment by r.spilker on 11 Mar 2014 at 7:26

GoogleCodeExporter commented 9 years ago
Pushed an implementation to master.

Original comment by r.spilker on 17 Mar 2014 at 9:34