JDK-7157671 : compiler tree API: incorrectly detects start/end positions under JDK6
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2012-03-29
  • Updated: 2012-09-21
  • Resolved: 2012-09-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6Resolved
Related Reports
Duplicate :  
Relates :  
Description
I use compiler tree API to find start/end positions of the import constructs. 

       SourcePositions sourcePositions = Trees.instance(task).getSourcePositions();
       long s = sourcePositions.getStartPosition(untiTree, impTree);
       long e = sourcePositions.getEndPosition(untiTree, impTree);

It seems to me that under jdk6 the end position of the import constructs is not detected correctly. A small class demonstrating the problem (Javac.java) is attached. Being run under jdk6/jdk7 it reports different results:

java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Client VM (build 19.1-b02, mixed mode)
File: Javac.java
import: 0:0
import: 48:48
import: 87:87
import: 125:125
import: 169:169
import: 203:203
import: 224:224
import: 252:252
import: 280:280
import: 303:303
import: 336:336
import: 371:371
import: 415:415
-----
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode)
File: Javac.java
import: 0:47
import: 48:86
import: 87:124
import: 125:168
import: 169:202
import: 203:223
import: 224:251
import: 252:279
import: 280:302
import: 303:335
import: 336:370
import: 371:414
import: 415:447

Trivial run.sh script is attached as well.