Uploaded image for project: 'XWiki Commons'
  1. XWiki Commons
  2. XCOMMONS-3772

Don't run javac lint checks on generated sources

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Unresolved
    • Major
    • None
    • None
    • None
    • Unknown

    Description

      The Maven build reports 120 javac lint warnings on machine-generated sources, and none of them can be fixed since we don't control the code generators:

      • xwiki-platform-query-jpql-parser: 100 rawtypes warnings from the SableCC-generated parser and AST nodes. SableCC predates generics and is unmaintained, and it generates code such as ArrayList list = new ArrayList();.
      • xwiki-rendering-wikimodel: 6 this-escape and 6 static warnings from the JavaCC-generated scanners. JavaCC generates the *TokenManager class body itself, so there is nowhere to put a @SuppressWarnings.
      • xwiki-commons-repository-model: 4 dep-ann and 4 deprecation warnings from the XJC-generated JAXB model. XJC copies the @deprecated note from the XSD into javadoc but does not emit the @Deprecated annotation. That raises dep-ann on the declarations, and it also raises deprecation on the generated fluent accessors, which call the deprecated getters and are not annotated either.

      These warnings are what prevents enabling -Werror, which xwiki-commons-pom has carried as a TODO for a long time ("At some point, we should turn on failing on warnings since they can be real errors and they keep growing on our build logs"): we cannot fail the build on warnings while it contains warnings that are impossible to fix.

      Note that -Xlint applies to a whole javac invocation and not to a source path, so switching a category off for a module also stops checking that module's hand-written sources. So for modules that mix generated and hand-written sources, compile the generated source root in its own maven-compiler-plugin execution with -Xlint:none and restrict the default execution to src/main/java, which keeps the hand-written sources fully checked. Add a xwiki.compiler.xlint property to xwiki-commons-pom for the whole-module cases, that is modules containing only generated sources, and later the legacy and Jakarta bridge modules whose very purpose is to call deprecated APIs.

      We already made this choice for our other linters, and this only makes javac agree with them: xwiki-platform-query-jpql-parser excludes the generated packages from Checkstyle, xwiki-commons-repository-model and xwiki-rendering-wikimodel set xwiki.checkstyle.skip, and xwiki-commons-pom silences Sonar's java:S1133 for legacy modules.

      Note that this applies to every project inheriting the XWiki parent POM, including xwiki-contrib extensions. See the proposal on the forum https://forum.xwiki.org/t/stop-running-javac-lint-checks-on-generated-code/18828.

      Attachments

        Activity

          People

            vmassol Vincent Massol
            vmassol Vincent Massol
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: