Bug 466291 - IAE on renaming the location for external annotation attachment
Summary: IAE on renaming the location for external annotation attachment
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.5   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 4.6 M4   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-05-04 07:44 EDT by Noopur Gupta CLA
Modified: 2016-05-29 07:06 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Noopur Gupta CLA 2015-05-04 07:44:37 EDT
Eclipse 4.5 M7 - I20150430-1445

- Create two Java projects P1 and P2.
- Enable annotation-based null analysis for P1.
- Set the location for external annotation attachment in P1 as the workspace location for P2.
- Now, create a class in P1. We get the following error in Error log view.
Any operation like content assist in class C gives the same error after that and does not complete.

Could not retrieve declared methods

java.lang.IllegalArgumentException: Path must include project and resource name: /P2
	at org.eclipse.core.runtime.Assert.isLegal(Assert.java:63)
	at org.eclipse.core.internal.resources.Workspace.newResource(Workspace.java:2075)
	at org.eclipse.core.internal.resources.Container.getFile(Container.java:192)
	at org.eclipse.jdt.internal.core.ClassFile.setupExternalAnnotationProvider(ClassFile.java:391)
	at org.eclipse.jdt.internal.core.ClassFile.getJarBinaryTypeInfo(ClassFile.java:369)
	at org.eclipse.jdt.internal.core.ClassFile.existsUsingJarTypeCache(ClassFile.java:218)
	at org.eclipse.jdt.internal.core.NameLookup.seekTypesInBinaryPackage(NameLookup.java:1051)
	at org.eclipse.jdt.internal.core.NameLookup.seekTypes(NameLookup.java:1019)
	at org.eclipse.jdt.internal.core.NameLookup.findType(NameLookup.java:769)
	at org.eclipse.jdt.internal.core.NameLookup.findType(NameLookup.java:663)
	at org.eclipse.jdt.internal.core.NameLookup.findType(NameLookup.java:622)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.find(SearchableEnvironment.java:103)
	at org.eclipse.jdt.internal.core.SearchableEnvironment.findType(SearchableEnvironment.java:283)
	at org.eclipse.jdt.internal.core.CancelableNameEnvironment.findType(CancelableNameEnvironment.java:50)
	at org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment.askForType(LookupEnvironment.java:144)
	at org.eclipse.jdt.internal.compiler.lookup.UnresolvedReferenceBinding.resolve(UnresolvedReferenceBinding.java:99)
	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveType(BinaryTypeBinding.java:187)
	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.resolveTypesFor(BinaryTypeBinding.java:1453)
	at org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding.availableMethods(BinaryTypeBinding.java:366)
	at org.eclipse.jdt.core.dom.TypeBinding.getDeclaredMethods(TypeBinding.java:302)
	at org.eclipse.jdt.internal.corext.codemanipulation.StubUtility2.getUnimplementedMethods(StubUtility2.java:825)
	at org.eclipse.jdt.internal.corext.codemanipulation.StubUtility2.getUnimplementedMethods(StubUtility2.java:807)
	at org.eclipse.jdt.internal.corext.codemanipulation.AddUnimplementedMethodsOperation.run(AddUnimplementedMethodsOperation.java:197)
	at org.eclipse.jdt.ui.wizards.NewTypeWizardPage.createInheritedMethods(NewTypeWizardPage.java:2657)
	at org.eclipse.jdt.ui.wizards.NewClassWizardPage.createTypeMembers(NewClassWizardPage.java:255)
	at org.eclipse.jdt.ui.wizards.NewTypeWizardPage.createType(NewTypeWizardPage.java:2207)
	at org.eclipse.jdt.internal.ui.wizards.NewClassCreationWizard.finishPage(NewClassCreationWizard.java:71)
	at org.eclipse.jdt.internal.ui.wizards.NewElementWizard$2.run(NewElementWizard.java:118)
	at org.eclipse.jdt.internal.core.BatchOperation.executeOperation(BatchOperation.java:39)
	at org.eclipse.jdt.internal.core.JavaModelOperation.run(JavaModelOperation.java:729)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2241)
	at org.eclipse.jdt.core.JavaCore.run(JavaCore.java:5409)
	at org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter.run(WorkbenchRunnableAdapter.java:106)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:119)
Comment 1 Stephan Herrmann CLA 2015-05-04 12:43:06 EDT
Just to clarify: the bug title speaks of renaming, how does this relate to the steps in comment 0?
Comment 2 Noopur Gupta CLA 2015-05-04 12:55:20 EDT
(In reply to Stephan Herrmann from comment #1)
> Just to clarify: the bug title speaks of renaming, how does this relate to
> the steps in comment 0?

Sorry, missed the step.
After step 3 in comment #0, rename P2.
Then, create a class in P1 as mentioned in step 4.
Comment 3 Stephan Herrmann CLA 2015-05-08 17:51:45 EDT
After bug 466879 has been filed, this bug will only cover the immediate issue: not to break content assist etc. after the broken configuration has been detected.
I'll have to see if we can restrict the logging to once per broken external annotation location - not sure if that is possible.
Comment 4 Stephan Herrmann CLA 2015-06-08 13:24:04 EDT
outch, by accidentally setting target to 4.4RC2 this bug escaped my attention. Thanks for putting it back on track.

Might be a candidate for 4.5.1, let's see.
Comment 5 Stephan Herrmann CLA 2015-07-16 11:46:28 EDT
Tentatively pulling into 4.6 M1
Comment 6 Stephan Herrmann CLA 2015-12-03 11:40:46 EST
The immediate problem doesn't even relate to the renaming: the call
   root.getFile(externalAnnotationPath)
doesn't admit a project path (absolute, one-segment).

TODO:

(1) decide whether project root is a valid external annotation path
  - adjust UI, to add corresponding validation, if necessary

(2) protect against immediate IAE

(3) consider caching bogus annotation paths in ClasspathEntry to avoid floods of identical log messages.

(4) decide if more validation is needed in some central location.

I have WIP re (2) and (3) in my workspace
Comment 7 Eclipse Genie CLA 2015-12-03 18:27:33 EST
New Gerrit change created: https://git.eclipse.org/r/61928
Comment 8 Stephan Herrmann CLA 2015-12-03 18:33:07 EST
(In reply to Stephan Herrmann from comment #6)
> (1) decide whether project root is a valid external annotation path
>   - adjust UI, to add corresponding validation, if necessary

UI admits project root & there's no fundamental problem with this (it just looks a bit weird to configure it that way) - so lets not change this.
 
> (2) protect against immediate IAE

Done via https://git.eclipse.org/r/61928
 
> (4) decide if more validation is needed in some central location.

I believe for validation we can simply extend ClasspathEntry.validateClasspathEntry(). This should then obsolete item (3) above.
Comment 9 Eclipse Genie CLA 2015-12-07 19:22:46 EST
New Gerrit change created: https://git.eclipse.org/r/62159
Comment 10 Stephan Herrmann CLA 2015-12-07 19:39:49 EST
(In reply to Eclipse Genie from comment #9)
> New Gerrit change created: https://git.eclipse.org/r/62159

This change adds validation for the external annotation cp attribute.

----------------------------------------
@Jay, do you want to review this change?
----------------------------------------

Contained:

* 1 new API Constant in IJavaModelStatusConstants

* 2 more triggers into ClasspathValidation.validate()


The new control logic is as follows:

ClasspathEntry.validateClasspathEntry() triggers a new method:
  validateExternalAnnotationPath() 
  - effect is only by returning a JavaModelStatus as all validations do.

When ClasspathEntry.getExternalAnnotationPath(..resolve=true) encounters a problem, we signal invalidExternalAnnotationPath() with two possible outcomes:
- if we already have a buildpath problem for the current project: no-op
- otherwise trigger ClasspathValidation.validate() to create a new marker

When checking JavaBuilder.isClasspathBroken() and if we find a marker with the new problem ID CP_INVALID_EXTERNAL_ANNOTATION_PATH, we re-validate using ClasspathValidation.validate() and try once more.


I manually tested that this indeed updates the new error marker (build path problem) on all relevant events. OTOH, projects not using external annotations should see no penalty from these new validations.

I guess I should write a bunch of tests for o.e.j.c.tests.builder, other than that I believe we are done here ...
Comment 11 Jay Arthanareeswaran CLA 2015-12-08 00:30:29 EST
(In reply to Stephan Herrmann from comment #10)
> ----------------------------------------
> @Jay, do you want to review this change?
> ----------------------------------------

Looks good Stephan.
Comment 13 Stephan Herrmann CLA 2015-12-08 05:31:30 EST
Thanks, released for 4.6 M4
Comment 14 Manoj N Palat CLA 2015-12-09 05:45:10 EST
Verified for Eclipse Neon Version: Neon 4.6M4 Build id: I20151208-0800
Comment 15 Stephan Herrmann CLA 2016-05-29 07:06:56 EDT
For posterity:

(In reply to Stephan Herrmann from comment #8)
> (In reply to Stephan Herrmann from comment #6)
> > (2) protect against immediate IAE
> 
> Done via https://git.eclipse.org/r/61928

This has been pushed directly (on 2015-12-05) as http://git.eclipse.org/c/jdt/eclipse.jdt.core.git/commit/?id=10d9ee7d6cd7cd29aebe50986af8fcc7cd9d4e32