Bug 578305 - CompareUIPlugin.getImage(IAdaptable) needs null check
Summary: CompareUIPlugin.getImage(IAdaptable) needs null check
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Compare (show other bugs)
Version: 4.7   Edit
Hardware: PC All
: P3 minor (vote)
Target Milestone: 4.23 M2   Edit
Assignee: Andrey Loskutov CLA
QA Contact:
URL:
Whiteboard:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2022-01-20 15:54 EST by Nate Jensen CLA
Modified: 2022-01-22 01:33 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nate Jensen CLA 2022-01-20 15:54:51 EST
I'm upgrading an Eclipse RCP application that has a perspective that has text editors (text, xml, etc) from Eclipse 4.6 to a newer version.  We found that when you right click on the file and select "Replace With -> Previous from Local History" it now throws a NullPointerException, whereas with Eclipse 4.6 it worked.  The stacktrace of the exception with Eclipse 2021-12 (4.22) is

java.lang.NullPointerException: null
	at org.eclipse.compare.internal.CompareUIPlugin.getImage(CompareUIPlugin.java:739)
	at org.eclipse.compare.internal.EditionAction.doFromHistory(EditionAction.java:153)
	at org.eclipse.compare.internal.EditionAction.run(EditionAction.java:114)
	at org.eclipse.compare.internal.BaseCompareAction.run(BaseCompareAction.java:27)
	at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:239)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:580)
	at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:414)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)


I traced the error to this code change, around line 742: https://git.eclipse.org/c/platform/eclipse.platform.team.git/commit/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/CompareUIPlugin.java?id=16bb9ed654149328b54869c05526a5fdb9562b01

With the debugger I found with both older and newer Eclipse versions, the call to get the adapter returns null.  However, with the older code the instanceof check prevents a NullPointerException while the newer code has no safety check.  Therefore, I think this is a bug and the solution is to just add a check for if the adapter is null before calling getImageDescriptor(adaptable) on it.
Comment 1 Andrey Loskutov CLA 2022-01-20 15:58:25 EST
Thanks. Would you please provide a patch?
https://wiki.eclipse.org/Platform/How_to_Contribute
Comment 2 Eclipse Genie CLA 2022-01-21 04:35:58 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.team/+/189864
Comment 3 Eclipse Genie CLA 2022-01-21 04:36:01 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.team/+/189865
Comment 4 Andrey Loskutov CLA 2022-01-21 04:36:45 EST
(In reply to Andrey Loskutov from comment #1)
> Thanks. Would you please provide a patch?
> https://wiki.eclipse.org/Platform/How_to_Contribute

Too late now.
Comment 7 Nate Jensen CLA 2022-01-21 14:48:59 EST
Thank you!  I was trying to do it but my Eclipse account seems messed up.