JDK-5067261 : com.sun.mirror.apt.Messager.printWarning() Impl emits Error instead of Warning
  • Type: Bug
  • Component: tools
  • Sub-Component: apt
  • Affected Version: 5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2004-06-23
  • Updated: 2004-07-16
  • Resolved: 2004-07-16
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
5.0 b59Fixed
Related Reports
Relates :  
Description

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) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-rc FIXED IN: tiger-rc INTEGRATED IN: tiger-b59 tiger-rc
03-08-2004

SUGGESTED FIX src/share/classes/com/sun/tools/apt/mirror/apt>sccs sccsdiff -r1.2 -r1.3 MessagerImpl.java ------- MessagerImpl.java ------- 13a14 > import com.sun.tools.javac.util.Name; 17d17 < 53,55c53,58 < if (pos instanceof SourcePositionImpl) < bark.error(((SourcePositionImpl) pos).getJavacPosition(), "Messager", msg); < else --- > if (pos instanceof SourcePositionImpl) { > SourcePositionImpl posImpl = (SourcePositionImpl) pos; > Name prev = bark.useSource(posImpl.getName()); > bark.error(posImpl.getJavacPosition(), "Messager", msg); > bark.useSource(prev); > } else 70,72c73,78 < if (pos instanceof SourcePositionImpl) < bark.error(((SourcePositionImpl)pos).getJavacPosition(), "Messager", msg); < else --- > if (pos instanceof SourcePositionImpl) { > SourcePositionImpl posImpl = (SourcePositionImpl) pos; > Name prev = bark.useSource(posImpl.getName()); > bark.warning(posImpl.getJavacPosition(), "Messager", msg); > bark.useSource(prev); > } else 87,89c93,98 < if (pos instanceof SourcePositionImpl) < bark.note(((SourcePositionImpl)pos).getJavacPosition(), "Messager", msg); < else --- > if (pos instanceof SourcePositionImpl) { > SourcePositionImpl posImpl = (SourcePositionImpl) pos; > Name prev = bark.useSource(posImpl.getName()); > bark.note(posImpl.getJavacPosition(), "Messager", msg); > bark.useSource(prev); > } else src/share/classes/com/sun/tools/apt/mirror/util>sccs sccsdiff -r1.2 -r1.3 SourcePositionImpl.java ------- SourcePositionImpl.java ------- 37a38,41 > public Name getName() { > return sourcefile; > } > ###@###.### 2004-07-13
13-07-2004

EVALUATION Should be fixed. ###@###.### 2004-06-24
24-06-2004