diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java index 84df3a625c..03c0313fc9 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java @@ -34,7 +34,9 @@ public interface SemanticErrorReporter { /** * Report a warning at the given location. Warnings do not abort - * the analysis. + * the analysis. They are usually recoverable errors. They are used + * to warn the user that something wrong is going on, which may cause + * subsequent errors or inconsistent behavior. * * @param location Location where the warning should be reported * @param message Message (rendered using a {@link MessageFormat}) @@ -44,9 +46,9 @@ public interface SemanticErrorReporter { /** - * Report an error at the given location. Errors abort subsequent analysis. - * The produced error can be thrown by the caller if it cannot be recovered - * from. + * Report an error at the given location. Errors abort subsequent analysis + * and cause a processing error to be put in the report. The produced error + * can be thrown by the caller if it cannot be recovered from. * * @param location Location where the error should be reported * @param message Message (rendered using a {@link MessageFormat}) diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java index 5497c9b93a..90e2952100 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java @@ -4,12 +4,15 @@ package net.sourceforge.pmd.lang.ast; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.contains; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; import org.junit.Before; import org.junit.Test; @@ -36,6 +39,7 @@ public class SemanticErrorReporterTest { @Before public void setup() { mockReporter = mock(MessageReporter.class); + when(mockReporter.isLoggable(Level.ERROR)).thenReturn(true); mockLogger = spy(NOPLogger.class); } @@ -44,11 +48,15 @@ public class SemanticErrorReporterTest { SemanticErrorReporter reporter = SemanticErrorReporter.reportToLogger(mockReporter, mockLogger); RootNode node = parseMockNode(reporter); + assertFalse(reporter.hasError()); + String message = "an error occurred"; reporter.error(node, message); verify(mockReporter).log(eq(Level.ERROR), contains(message)); verifyNoMoreInteractions(mockLogger); + + assertTrue(reporter.hasError()); } @Test diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AstDisambiguationPass.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AstDisambiguationPass.java index 6a4fe24939..458b52d8b7 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AstDisambiguationPass.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AstDisambiguationPass.java @@ -211,7 +211,7 @@ final class AstDisambiguationPass { JTypeDeclSymbol sym = type.getReferencedSym(); if (type.getParent() instanceof ASTAnnotation) { if (!(sym instanceof JClassSymbol && (sym.isUnresolved() || ((JClassSymbol) sym).isAnnotation()))) { - ctx.getLogger().error(type, JavaSemanticErrors.EXPECTED_ANNOTATION_TYPE); + ctx.getLogger().warning(type, JavaSemanticErrors.EXPECTED_ANNOTATION_TYPE); } return; } @@ -219,7 +219,7 @@ final class AstDisambiguationPass { int actualArity = ASTList.sizeOrZero(type.getTypeArguments()); int expectedArity = sym instanceof JClassSymbol ? ((JClassSymbol) sym).getTypeParameterCount() : 0; if (actualArity != 0 && actualArity != expectedArity) { - ctx.getLogger().error(type, JavaSemanticErrors.MALFORMED_GENERIC_TYPE, expectedArity, actualArity); + ctx.getLogger().warning(type, JavaSemanticErrors.MALFORMED_GENERIC_TYPE, expectedArity, actualArity); } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java index 9dcc91966f..7cc7f1345c 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java @@ -98,7 +98,7 @@ public final class InternalApiBridge { try { it.getTypeMirror(); } catch (Exception e) { - processor.getLogger().error(it, "Error during type resolution of node " + it.getXPathNodeName()); + processor.getLogger().warning(it, "Error during type resolution of node " + it.getXPathNodeName()); } }); } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/table/internal/ReferenceCtx.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/table/internal/ReferenceCtx.java index 800b67c249..b949c7973c 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/table/internal/ReferenceCtx.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/table/internal/ReferenceCtx.java @@ -90,7 +90,7 @@ public final class ReferenceCtx { if (distinct.size() == 1) { return distinct.iterator().next(); } - processor.getLogger().error( + processor.getLogger().warning( errorLocation, AMBIGUOUS_NAME_REFERENCE, name, diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/LazyTypeResolver.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/LazyTypeResolver.java index c2d28ceb14..c1df639d18 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/LazyTypeResolver.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/LazyTypeResolver.java @@ -564,7 +564,7 @@ public final class LazyTypeResolver extends JavaVisitorBase