Bug 204339 - [compiler] Invalid length for missing package declaration in empty package-info.java file
Summary: [compiler] Invalid length for missing package declaration in empty package-in...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: 3.4 M3   Edit
Assignee: Kent Johnson CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-09-21 19:17 EDT by Brock Janiczak CLA
Modified: 2007-10-29 06:17 EDT (History)
3 users (show)

See Also:


Attachments
Possible Fix (2.65 KB, patch)
2007-09-28 05:22 EDT, Dani Megert CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Brock Janiczak CLA 2007-09-21 19:17:55 EDT
Version: 3.3.0
Build id: I20070809-1105

Creating a new package-info file for the non default package always results in an error and no immediate way to quick fix it.

In a project with 5.0 compliance:
1. Create a package
2. Create a new file called package-info.java in the package
3. The problem view will correctly show an error about an incorrect package specification (The declared package "" does not match the expected package "foo")
4. Observe: there are no quick fixes available to the problem (either in the problems view or in the editor)
5. Insert a space and save the editor
6. The quickfix is now available

The problem seems to be that the problem annotation has a position of 0 and a length of 1.  This causes the annotation model to throw a BadLocationException as the document has a length of 0.

Would it be possible to link this type of error with the file instead of a text position?
Comment 1 Dani Megert CLA 2007-09-24 04:09:11 EDT
>Would it be possible to link this type of error with the file instead of a text
>position?
JDT Core should set length 0 and not invalid length 1.
Comment 2 Olivier Thomann CLA 2007-09-24 16:46:42 EDT
JDT/Core sets the end of the marker to 1 since this is exclusive.
So the problem goes from 0 inclusive to 1 exclusive.
What should we change?
Comment 3 Dani Megert CLA 2007-09-25 03:44:42 EDT
>JDT/Core sets the end of the marker to 1 since this is exclusive.
>So the problem goes from 0 inclusive to 1 exclusive.
Start is inclusive and there is nothing at position 0. You have to report
  start= -1
  end= -1
and because you already correctly set the line number to 1, the error will be shown in the editor.
Comment 4 Kent Johnson CLA 2007-09-27 14:38:30 EDT
ProblemReporter.packageIsNotExpectedPackage() uses 0 & 0 as the start/end.

Changing these values to -1 & -1 does not improve anything, it actually makes the case of a single space, worse. No quick fix shows up at all.

Also tried 0 & 1, and -1 & 0.


0 & 0 is the only pair that causes a quick fix to show up when a space is added.

No quickfix appears with any values, if the file is empty.

So Dani, why should we change from 0 & 0 to -1 & -1 ?
Comment 5 Dani Megert CLA 2007-09-28 05:00:18 EDT
Hi Kent,

the initial problem is with the MARKER values which are currently set to start=0 and end=1. This causes a BadLocationException on our side as the document has no characters at all and also disables the quick fix in the Problems view.

On the marker you should either not set start and end at all or set it to 0,0. -1/-1 is Platform Text convention and not specified directly on CHAR_START/END.

Now when it comes to the temporary IProblem reported during reconcile JDT Core has a problem in the definition of IProblem.getSourceStart/End() because both are declared as being inclusive, hence you cannot report the difference between
x
^ bug at first character in document i.e. 0/0 and the case when the document is empty. As you can see, this can be expressed with the marker by either setting it to 0/0 or better: not set it at all.

A workaround could be to use -1/-1 on your side for the problem position i.e. unknown as speced in Javadoc. I committed code on the JDT Text side to handle such IProblems (this was missing on our side).
Comment 6 Dani Megert CLA 2007-09-28 05:22:52 EDT
Created attachment 79360 [details]
Possible Fix
Comment 7 Kent Johnson CLA 2007-09-28 10:29:05 EDT
Well in that case, why don't we use 0 & -1 ?

The marker would then be created with 0 & 0.
Comment 8 Kent Johnson CLA 2007-09-28 10:49:40 EDT
Changed my mind, instead we'll detect a source end position of 0 and leave it alone when we're creating the marker.

There are numerous problems created with 0 & 0 as their positions, so we'll leave all of them alone, and create the marker differently.
Comment 9 Dani Megert CLA 2007-09-28 11:26:50 EDT
>There are numerous problems created with 0 & 0 as their positions
That's what I also suspected. I might to adjust our code regarding 0/0 as well.
Comment 10 Kent Johnson CLA 2007-09-28 14:28:55 EDT
Fixed up positions in tests from BuildpathTests, ErrorTests & MultiProjectTests

Released into HEAD for 3.4M3
Comment 11 Dani Megert CLA 2007-10-03 06:58:56 EDT
Adjusted JDT Text side and tested it.
Comment 12 Olivier Thomann CLA 2007-10-03 14:11:40 EDT
Added org.eclipse.jdt.core.tests.builder.PackageInfoTest#test003 as a regression test.
Comment 13 Frederic Fusier CLA 2007-10-29 06:17:49 EDT
Verified for 3.4M3 using I20071029-0010 build.