JDK-6376083 : JSR 269 should check annotation processor for compatability with specified source version
  • Type: Bug
  • Component: core-libs
  • Sub-Component: javax.annotation.processing
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-01-24
  • Updated: 2010-04-02
  • Resolved: 2006-04-01
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
6 b79Fixed
Related Reports
Relates :  
Relates :  
Description
Annotation processors specify the highest version of the source code they can process via the results of the Processor.getSupportedSourceVersion method.  The implementation of the discovery process should verify that the source versions reported by annotation processors is compatible with the source version specified, perhaps implicitly, by the javac invocation.

Comments
SUGGESTED FIX src/share/classes/com/sun/tools/javac/processing>sccs sccsdiff -r1.13 -r1.14 JavacProcessingEnvironment.java ------- JavacProcessingEnvironment.java ------- 87a88,91 > */ > private final Set<String> unmatchedProcessorOptions; > > /** 95a100,104 > /** > * Source level of the compile. > */ > Source source; > 101a111 > source = Source.instance(context); 115a126 > unmatchedProcessorOptions = initUnmatchedProcessorOptions(); 303a315,320 > private Set<String> initUnmatchedProcessorOptions() { > Set<String> unmatchedProcessorOptions = new HashSet<String>(); > unmatchedProcessorOptions.addAll(processorOptions.keySet()); > return unmatchedProcessorOptions; > } > 306,313c323,327 < * processors has been used on a prior round, its process method < * is called on all subsequent rounds, perhaps with an empty set < * of annotations to process. The {@code annotatedSupported} < * method caches the supported annotation information from the < * first (and only) getSupportedAnnotations call to the processor. < * If we decide to support returning different supported annotations < * on different rounds, the tool could check if the new set is == < * to the one returned from the prior round. --- > * processor has been used on a prior round, its process method is > * called on all subsequent rounds, perhaps with an empty set of > * annotations to process. The {@code annotatedSupported} method > * caches the supported annotation information from the first (and > * only) getSupportedAnnotationTypes call to the processor. 318a333 > private java.util.List<String> supportedOptionNames; 320c335 < ProcessorState(Processor p, Log log, ProcessingEnvironment env) { --- > ProcessorState(Processor p, Log log, Source source, ProcessingEnvironment env) { 325c340,356 < p.init(env); --- > processor.init(env); > > checkSourceVersionCompatibility(source, log); > > supportedAnnotationPatterns = new ArrayList<Pattern>(); > for (String importString : processor.getSupportedAnnotationTypes()) { > supportedAnnotationPatterns.add(importStringToPattern(importString, > processor, > log)); > } > > supportedOptionNames = new ArrayList<String>(); > for (String optionName : processor.getSupportedOptions() ) { > if (validOptionName(optionName, log)) > supportedOptionNames.add(optionName); > } > 329,335c360,381 < < // TODO: supportedAnnotationPatterns should be a set and < // we should check for duplicates besides noMatches; also < // if allMatches is return, that can be the sole element. < supportedAnnotationPatterns = new ArrayList<Pattern>(); < for (String supportedAnnotationType : processor.getSupportedAnnotationTypes()) { < supportedAnnotationPatterns.add(importStringToPattern(supportedAnnotationType, p, log)); --- > } > > /** > * Checks whether or not a processor's source version is > * compatible with the compilation source version. The > * processor's source version needs to be greater than or > * equal to the source version of the compile. > */ > private void checkSourceVersionCompatibility(Source source, Log log) { > /* > * Compare the ordinal positions of the two kinds of > * enums; the Source enum's first value is "1.2" so its > * ordinal is offset by 2 compared to the corresponding > * SourceVersion enum. > */ > SourceVersion procSourceVersion = processor.getSupportedSourceVersion(); > > if (procSourceVersion.ordinal() < (source.ordinal() + 2)) { > log.warning("proc.processor.incompatible.source.version", > procSourceVersion, > processor.getClass().getName(), > source.name); 336a383 > } 337a385,391 > private boolean validOptionName(String optionName, Log log) { > boolean valid = SourceVersion.isIdentifier(optionName); > if (!valid) > log.warning("proc.processor.bad.option.name", > optionName, > processor.getClass().getName()); > return valid; 346a401,407 > > /** > * Remove options that are matched by this processor. > */ > public void removeSupportedOptions(Set<String> unmatchedProcessorOptions) { > unmatchedProcessorOptions.removeAll(supportedOptionNames); > } 382c443 < log, JavacProcessingEnvironment.this); --- > log, source, JavacProcessingEnvironment.this); 500c561,562 < --- > ps.removeSupportedOptions(unmatchedProcessorOptions); > 562,569d623 < private void initProcessor(Processor proc) { < try { < proc.init(this); < } catch (Throwable t) { < throw new AnnotationProcessingError(t); < } < } < 717a772 > warnIfUnmatchedOptions(); 723c778 < --- > 750a806,811 > private void warnIfUnmatchedOptions() { > if (!unmatchedProcessorOptions.isEmpty()) { > log.warning("proc.unmatched.processor.options", unmatchedProcessorOptions.toString()); > } > } > src/share/classes/com/sun/tools/javac/resources>sccs sccsdiff -r1.113 -r1.114 compiler.properties ------- compiler.properties ------- 656a657,662 > compiler.warn.proc.processor.bad.option.name=\ > Ignoring bad option name ''{0}'' provided by processor ''{1}'' > > compiler.warn.proc.processor.incompatible.source.version=\ > Supported source version ''{0}'' from annotation processor ''{1}'' less than -source ''{2}'' > 666a673,675 > compiler.warn.proc.unmatched.processor.options=\ > The following options were not recognized by any processor: ''{0}'' >
28-03-2006

EVALUATION Should be fixed.
24-01-2006