Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 427229

Summary: Failed to resolve selection in '..' in error log
Product: z_Archived Reporter: Gunnar Wagenknecht <gunnar>
Component: RecommendersAssignee: Project inbox <recommenders-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: marcel.bruch, sewe
Version: unspecifiedKeywords: helpwanted
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Gunnar Wagenknecht CLA 2014-02-03 03:04:55 EST
The following exception is logged quite frequently:

------
Failed to resolve selection in '...' at offset 123

Java Model Exception: Java Model Status [... does not exist]
	at org.eclipse.jdt.internal.core.JavaElement.newJavaModelException(JavaElement.java:508)
	at org.eclipse.jdt.internal.core.Openable.generateInfos(Openable.java:246)
	at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:529)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:258)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:244)
	at org.eclipse.jdt.internal.core.JavaProject.getJavaProjectElementInfo(JavaProject.java:1647)
	at org.eclipse.jdt.internal.core.JavaProject.newNameLookup(JavaProject.java:2335)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.<init>(SearchableEnvironment.java:59)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.<init>(SearchableEnvironment.java:66)
	at org.eclipse.jdt.internal.core.JavaProject.newSearchableNameEnvironment(JavaProject.java:2360)
	at org.eclipse.jdt.internal.core.Openable.codeSelect(Openable.java:148)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:379)
	at org.eclipse.jdt.internal.core.CompilationUnit.codeSelect(CompilationUnit.java:373)
	at org.eclipse.recommenders.internal.rcp.providers.JavaSelectionUtils.resolveJavaElementFromTypeRootInEditor(JavaSelectionUtils.java:147)
	at org.eclipse.recommenders.internal.rcp.providers.JavaSelectionUtils.resolveJavaElementFromEditor(JavaSelectionUtils.java:129)
	at org.eclipse.recommenders.internal.rcp.providers.JavaSelectionUtils.resolveJavaElementFromEditor(JavaSelectionUtils.java:112)
	at org.eclipse.recommenders.internal.rcp.providers.JavaSelectionProvider.handleSelectionInEditor(JavaSelectionProvider.java:108)
	at org.eclipse.recommenders.internal.rcp.providers.JavaSelectionProvider.access$1(JavaSelectionProvider.java:105)
	at org.eclipse.recommenders.internal.rcp.providers.JavaSelectionProvider$1.run(JavaSelectionProvider.java:82)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:178)
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:292)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:744)
------


I think the key point here is that I had a .java file open in the Java source editor. However the .java file is neither part of a regular JDT classpath nor is it located in a Java project. This was really just some source code in a simple project.

Recommenders should detect this and simply skip it's execution but not spam log files.
Comment 1 Andreas Sewe CLA 2014-02-03 03:52:56 EST
Thanks, Lars, for this report.

Yes, Code Recommenders should probably ignore this silently. For random .java files, it simply cannot figure out what library they are from, but at least it can be quiet about it.
Comment 2 Marcel Bruch CLA 2014-02-19 13:16:06 EST
Hi "Lars" :) Looks like there is a change in the JDT behavior. According to the API documentation some methods should return null iff the compilation unit is not part of a java project/the java model, and thus we'd terminate gracefully. This behavior, however, seems to be changed in later versions of JDT. I'll discuss the behavior with the JDT team, update the documentation in JDT, and adjust our code accordingly.

Still targeting 2.0.6 for this fix as the workaround is straight forward.
Comment 3 Marcel Bruch CLA 2014-02-20 11:24:47 EST
Proposed fix in https://git.eclipse.org/r/#/c/22322/

Andreas, there is yet no integration test suite in place to cover that case properly, right? Any suggestions how to test this?
Comment 4 Marcel Bruch CLA 2014-02-21 04:31:13 EST
merged.