Bug 566616 - Incorrect lazy initialization and update of static field org.eclipse.ltk.internal.core.refactoring.RefactoringCorePlugin.fRefactoringUndoContext in org.eclipse.ltk.internal.core.refactoring.RefactoringCorePlugin.getUndoContext()
Summary: Incorrect lazy initialization and update of static field org.eclipse.ltk.inte...
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.17   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Carsten Hammer CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2020-09-02 13:57 EDT by Carsten Hammer CLA
Modified: 2023-02-06 00:59 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Carsten Hammer CLA 2020-09-02 13:57:58 EDT
Spotbugs error LI_LAZY_INIT_UPDATE_STATIC 

Bug: Incorrect lazy initialization and update of static field org.eclipse.ltk.internal.core.refactoring.RefactoringCorePlugin.fRefactoringUndoContext in org.eclipse.ltk.internal.core.refactoring.RefactoringCorePlugin.getUndoContext()

This method contains an unsynchronized lazy initialization of a static field. After the field is set, the object stored into that location is further updated or accessed. The setting of the field is visible to other threads as soon as it is set. If the further accesses in the method that set the field serve to initialize the object, then you have a very serious multithreading bug, unless something else prevents any other thread from accessing the stored object until it is fully initialized. 

Even if you feel confident that the method is never called by multiple threads, it might be better to not set the static field until the value you are setting it to is fully populated/initialized. 

	public static IUndoContext getUndoContext() {
		if (fRefactoringUndoContext == null) {
			fRefactoringUndoContext= new RefactoringUndoContext();
			IUndoContext workspaceContext= ResourcesPlugin.getWorkspace().getAdapter(IUndoContext.class);
			if (workspaceContext instanceof ObjectUndoContext) {
				((ObjectUndoContext)workspaceContext).addMatch(fRefactoringUndoContext);
			}
			IOperationHistory operationHistory= OperationHistoryFactory.getOperationHistory();
			operationHistory.setLimit(fRefactoringUndoContext, 5);
		}
		return fRefactoringUndoContext;
	}
Comment 1 Eclipse Genie CLA 2020-09-02 14:04:39 EDT
New Gerrit change created: https://git.eclipse.org/r/c/jdt/eclipse.jdt.ui/+/168684
Comment 2 Eclipse Genie CLA 2023-02-06 00:59:29 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.