Name: jl125535 Date: 06/23/2004
FULL PRODUCT VERSION :
...> java -version
java version "1.5.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b56)
Java HotSpot(TM) Server VM (build 1.5.0-beta3-b56, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
...> uname -a
Linux riedquat 2.4.20-64GB-SMP #1 SMP Fri Apr 2 19:10:22 UTC 2004 i686 unknown unknown GNU/Linux
A DESCRIPTION OF THE PROBLEM :
The class part of the tools.jar that implements the interface com.sun.mirror.apt.Messager for apt counts warnings as errors instead of warnings.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Variant 1:
Run this script on the supplied source:
#!/bin/sh
javac -cp .:$JAVA_HOME/lib/tools.jar TodoProcessorFactory.java
apt -cp .:$JAVA_HOME/lib/tools.jar -factory TodoProcessorFactory TodoProcessorFactory.java
Variant 2:
Write some processor which invokes printWarning and look at the last lines apt prints, watch out wether your warning was counted as warning or error.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Running the above commands, the last line of output from apt should be:
1 warning
ACTUAL -
Running the above commands, the last line of output from apt actually is:
1 error
__input:14: [todo] Something
(source unavailable)
1 error
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import com.sun.mirror.apt.*;
import com.sun.mirror.declaration.*;
import com.sun.mirror.util.*;
import java.lang.annotation.*;
import java.util.*;
@Documented
@Retention(value=RetentionPolicy.RUNTIME)
@interface Todo {
String value();
}
@Todo("Something")
class Anno {
}
public class TodoProcessorFactory implements AnnotationProcessorFactory {
// include @Retention and @Documented to suppress warning about
// annotations without processors
private static final Collection<String> supportedAnnotations =
Collections.unmodifiableCollection(
Arrays.asList(Todo.class.getName(), Retention.class.getName(),
Documented.class.getName()));
private static final Collection<String> supportedOptions =
Collections.emptySet();
public Collection<String> supportedAnnotationTypes() {
return supportedAnnotations;
}
public Collection<String> supportedOptions() { return supportedOptions; }
public AnnotationProcessor getProcessorFor(
final Set<AnnotationTypeDeclaration> atds,
final AnnotationProcessorEnvironment env)
{
return new TodoProcessor(env);
}
}
class TodoProcessor implements AnnotationProcessor {
private final AnnotationProcessorEnvironment env;
public TodoProcessor(final AnnotationProcessorEnvironment env) {
this.env = env;
}
public void process() {
for (Declaration decl :
env.getDeclarationsAnnotatedWith(
(AnnotationTypeDeclaration)
env.getTypeDeclaration(Todo.class.getName())))
{
todo(decl.getPosition(), decl.getAnnotation(Todo.class).value());
}
}
private final void todo(final SourcePosition pos, final String text) {
// Here comes the bug:
// printWarning increases the error counter instead of the
// warning counter
env.getMessager().printWarning(pos, "[todo] " + text);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
don't use Messager.printWarning(), use System.err.println() instead
(Incident Review ID: 281128)
======================================================================
- relates to
-
JDK-5055902 REGRESSION:Messager.printXXX(SourcePosition, String) broken in b51
- Closed