New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip unnecessary exception 'Severity not set, ignoring exception' #3657

Closed
romani opened this Issue Dec 15, 2016 · 1 comment

Comments

Projects
None yet
1 participant
@romani
Member

romani commented Dec 15, 2016

Launch any valildation with -d:

$ cat config.xml 
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
        "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
    <module name="TreeWalker">
        <module name="Indentation">
            <property name="basicOffset" value="2"/>
            <property name="braceAdjustment" value="0"/>
            <property name="caseIndent" value="2"/>
            <property name="throwsIndent" value="4"/>
            <property name="lineWrappingIndentation" value="2"/>
            <property name="arrayInitIndent" value="2"/>
        </module>
    </module>
</module>

$ cat PackageDimensions.java
public class PackageDimensions {

  @SuppressWarnings(
    {"unchecked", "deprecation"}
  ) // violation
  @Deprecated
  private int height;

  @SuppressWarnings(
    {"unchecked", "deprecation"}
  ) // no voilation
  private int height2;

  void foo () {
    indentationOfBrace(
      "as",
      "adsf"
    ); // no violation
  }

  void indentationOfBrace(String v, String v2) {}

}

java -jar checkstyle-7.3-all.jar -d -c config.xml PackageDimensions.java

in result a lot of exception , one of them is :

Dec 14, 2016 5:02:56 PM com.puppycrawl.tools.checkstyle.ConfigurationLoader endElement
FINE: Severity not set, ignoring exception
com.puppycrawl.tools.checkstyle.api.CheckstyleException: missing key 'severity' in TreeWalker
	at com.puppycrawl.tools.checkstyle.DefaultConfiguration.getAttribute(DefaultConfiguration.java:68)
	at com.puppycrawl.tools.checkstyle.ConfigurationLoader$InternalLoader.endElement(ConfigurationLoader.java:479)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:609)
	at com.sun.org.apache.xerces.internal.impl.dtd.XMLNSDTDValidator.endNamespaceScope(XMLNSDTDValidator.java:266)
	at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.java:2005)
	at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:879)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1782)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2967)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:602)
	at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:112)
	at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:505)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:841)
	at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:770)
	at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
	at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
	at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
	at com.puppycrawl.tools.checkstyle.api.AbstractLoader.parseInputSource(AbstractLoader.java:96)
	at com.puppycrawl.tools.checkstyle.ConfigurationLoader.parseInputSource(ConfigurationLoader.java:152)
	at com.puppycrawl.tools.checkstyle.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:231)
	at com.puppycrawl.tools.checkstyle.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:183)
	at com.puppycrawl.tools.checkstyle.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:164)
	at com.puppycrawl.tools.checkstyle.Main.runCheckstyle(Main.java:407)
	at com.puppycrawl.tools.checkstyle.Main.runCli(Main.java:359)
	at com.puppycrawl.tools.checkstyle.Main.main(Main.java:174)

reason
https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/ConfigurationLoader.java#L477 :

                // remove modules with severity ignore if these modules should
                // be omitted
                SeverityLevel level = null;
                try {
                    final String severity = recentModule.getAttribute(SEVERITY);
                    level = SeverityLevel.getInstance(severity);
                }
                catch (final CheckstyleException ex) {
                    LOG.debug("Severity not set, ignoring exception", ex);
                }

catch is nonsense, logic is based on exception - BAD.
need to be refactored to validate that module has such attribute.

@romani romani self-assigned this Dec 15, 2016

romani added a commit that referenced this issue Dec 15, 2016

romani added a commit that referenced this issue Dec 15, 2016

romani added a commit that referenced this issue Dec 16, 2016

@romani romani added bug and removed miscellaneous labels Dec 16, 2016

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Dec 16, 2016

Member

fix is merged

Member

romani commented Dec 16, 2016

fix is merged

@romani romani closed this Dec 16, 2016

@romani romani added this to the 7.4 milestone Dec 16, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment