jshiell / checkstyle-idea

CheckStyle plug-in for IntelliJ IDEA
https://plugins.jetbrains.com/plugin/1065-checkstyle-idea
Other
887 stars 161 forks source link

Intellij Checkstyle Plugin - google_checks.xml import fails due to null enum being passed #649

Closed theotrama closed 2 months ago

theotrama commented 2 months ago

whenever importing this google_checks.xml https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml we are getting an error where an Enum,valueOf call fails. This seems to be because at com.puppycrawl.tools.checkstyle.ConfigurationLoader$InternalLoader.endElement(ConfigurationLoader.java:571) a null value seems to be passed. See full stack trace below:

Caused by: java.lang.IllegalArgumentException: No enum constant com.puppycrawl.tools.checkstyle.api.SeverityLevel.
    at java.base/java.lang.Enum.valueOf(Enum.java:273)
    at com.puppycrawl.tools.checkstyle.api.SeverityLevel.getInstance(SeverityLevel.java:67)
    at com.puppycrawl.tools.checkstyle.ConfigurationLoader$InternalLoader.endElement(ConfigurationLoader.java:571)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(AbstractSAXParser.java:618)
    at java.xml/com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endNamespaceScope(XMLDTDValidator.java:1985)
    at java.xml/com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleEndElement(XMLDTDValidator.java:1934)
    at java.xml/com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.endElement(XMLDTDValidator.java:865)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(XMLDocumentFragmentScannerImpl.java:1728)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2899)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:605)
    at java.xml/com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:542)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:889)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:825)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
    at java.xml/com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1224)
    at java.xml/com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:637)
    at com.puppycrawl.tools.checkstyle.XmlLoader.parseInputSource(XmlLoader.java:84)
    at com.puppycrawl.tools.checkstyle.ConfigurationLoader.parseInputSource(ConfigurationLoader.java:195)
    at com.puppycrawl.tools.checkstyle.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:311)
    at com.puppycrawl.tools.checkstyle.ConfigurationLoader.loadConfiguration(ConfigurationLoader.java:282)

IntelliJ IDEA: 2024.1.3 (Ultimate Edition) CheckStyle-IDEA: 5.93.4

jshiell commented 2 months ago

Thanks for the report. I luckily ran into this yesterday when adding the latest checkstyle release to the plugin. The fix should be in main; I just wanted to do some more testing before releasing it. No promises, but I’ll try get it out later today 🤞

theotrama commented 2 months ago

Hey Jamie, thank you so much for the quick reply! And happy that you were able to reproduce the issue. Looking forward to the fix 💪

jshiell commented 2 months ago

My pleasure - fixed in 5.94.0 I believe, but if you see any further problems please just reopen it!

(For the record, the problem was that some paths were returning missing properties as empty strings, which meant that the default value wasn't used. And in the newest release of the Google Checks, the severity value is now driven by a property, falling back on warning. Alas, as you can tell from the exception, trying to find an enum called "" doesn't work very well...)

theotrama commented 2 months ago

Wow Jamie, you're amazing! Just tested it and now it is importing the google_checks.xml successfully. Thank you!

jshiell commented 2 months ago

My pleasure - but it's just sheer luck that I happened to spot the new version yesterday and find the problem! Glad to hear it's working, though 😄