JDK-4993280 : apt should favor source files over class files for type information
  • Type: Enhancement
  • Component: tools
  • Sub-Component: apt
  • Affected Version: 5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2004-02-12
  • Updated: 2012-10-09
  • Resolved: 2004-09-24
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.
Other JDK 6
5.0u1 01Fixed 6Fixed
Related Reports
Relates :  
Relates :  
Description
When javac is looking for information about a class, it favors examining a class file over a source file as long as the class file is newer.  However, apt should always favor a source file over the corresponding class file since the class file will not have the annotations with @RententionPolicy.SOURCE. 

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.5.0_01 mustang FIXED IN: 1.5.0_01 mustang INTEGRATED IN: 1.5.0_01 mustang
26-09-2004

SUGGESTED FIX src/share/classes/com/sun/tools/apt/main>sccs sccsdiff -r1.10 -r1.11 JavaCompiler.java ------- JavaCompiler.java ------- 30,38c30,34 < /** This class could be the main entry point for GJC when GJC is used as a < * component in a larger software system. It provides operations to < * construct a new compiler, and to run a new compiler on a set of source < * files. < * < * <p><b>This is NOT part of any API suppored by Sun Microsystems. If < * you write code that depends on this, you do so at your own risk. < * This code and its internal interfaces are subject to change or < * deletion without notice.</b> --- > /** > * <p><b>This is NOT part of any API supported by Sun Microsystems. > * If you write code that depends on this, you do so at your own > * risk. This code and its internal interfaces are subject to change > * or deletion without notice.</b> 159c155 < reader = ClassReader.instance(context); --- > reader = AptClassReader.instance0(context); 198a195 > classesAsDecls= options.get("-XclassesAsDecls") != null; 259a257,260 > /** Are class files being treated as declarations > */ > public boolean classesAsDecls; > 426a428 > 431c433,447 < for (List<String> l = filenames; l.nonEmpty(); l = l.tail) --- > for (List<String> l = filenames; l.nonEmpty(); l = l.tail) { > if (classesAsDecls) { > if (! l.head.endsWith(".java") ) { // process as class file > ClassSymbol cs = reader.enterClass(names.fromString(l.head)); > try { > cs.complete(); > } catch(Symbol.CompletionFailure cf) { > bark.error(Position.NOPOS, "CantFindClass", l); > continue; > } > > classes.append(cs); // add to list of classes > continue; > } > } 432a449 > } 441c458,460 < apt.main(roots, origOptions, aptCL, --- > apt.main(roots, > classes, > origOptions, aptCL, 568a588,616 > > static class AptClassReader extends com.sun.tools.javac.jvm.ClassReader { > public static AptClassReader instance0(Context context) { > ClassReader instance = context.get(classReaderKey); > if (instance == null) > instance = new AptClassReader(context); > return (AptClassReader)instance; > } > > public static void preRegister(final Context context) { > context.put(classReaderKey, new Context.Factory<ClassReader>() { > public ClassReader make() { > return new AptClassReader(context); > } > }); > } > > private AptClassReader(Context context) { > super(context, true); > } > > protected FileEntry preferredFileEntry(FileEntry sourceEntry, > FileEntry classEntry) { > // apt always prefers source over class files so that > // annotations with source retention level are maximally > // available. > return sourceEntry; > } > } src/share/classes/com/sun/tools/javac/jvm>sccs sccsdiff -r1.99 -r1.100 ClassReader.java ------- ClassReader.java ------- 1404c1404 < return flags; --- > return flags & ~ACC_SUPER; // SUPER and SYNCHRONIZED bits overloaded 1685,1694c1685,1686 < if ((c.flags_field & (CLASS_SEEN | SOURCE_SEEN)) != 0) { < // we have encountered a file of the other kind, < // i.e. ".class" instead of ".java" or vice versa. < // now we have find out which one is newer. < long fdate = file.lastModified(); < long cdate = c.classfile.lastModified(); < if (fdate >= 0 && cdate >= 0 && fdate > cdate) { < c.classfile = file; < } < } --- > if ((c.flags_field & (CLASS_SEEN | SOURCE_SEEN)) != 0) > c.classfile = preferredFileEntry(file, c.classfile); 1698a1691,1705 > /** Implement policy to choose to derive information from a source > * file or a class file when both are present. May be overridden > * by subclasses. > */ > protected FileEntry preferredFileEntry(FileEntry sourceEntry, > FileEntry classEntry) { > // If we have encountered both kinds of files, > // i.e. ".class" and ".java", we prefer the newer one. > long fdate = sourceEntry.lastModified(); > long cdate = classEntry.lastModified(); > return (fdate >= 0 && cdate >= 0 && fdate > cdate) ? > sourceEntry : > classEntry; > } > ###@###.### 2004-09-16
16-09-2004

EVALUATION Should be fixed; will require modifying earlier javac compiler phases. ###@###.### 2004-02-11
11-02-2004