"Invalid use of @throws" compiles an error if log4j-core is present in the classpath

We started getting this error on our tests a week ago. It was turned on and off - sometimes people get it, and in other cases they won't.

/.../product/integration/src/test/java/com/acme/integration/code/CodeTestUtils.java:74: error: invalid use of @throws
         * @throws Exception if an error occurs.

I think the error message is a bit vague. Wrong? The code looks good to me:

    /**
     * Iterates to find modules and then calls
     * {@link #checkModule(Path, String, DirectoryStream.Filter, CheckFile)} for each.
     *
     * @param subPath the path within each module to start checks from.
     * @param filter the filter to apply to choose which files to check.
     * @param checkFile the checks to perform on each file.
     * @throws Exception if an error occurs.
     */
    public static void checkProject(String subPath, DirectoryStream.Filter<Path> filter, CheckFile checkFile) throws Exception
    {
        for (Path file : listFiles(EnvironmentUtils.getDevelopmentRoot().toPath()))
        {
            if (FileUtils.isDirectory(file) && FileUtils.exists(file.resolve("src/java")))
            {
                checkModule(file, subPath, filter, checkFile);
            }
        }
    }

We enable doclint at compile time because we want to find out about Javadoc errors without having to run Javadoc separately.

What exactly should this error mean? Is there anything invalid about what we are doing here? Are we looking at a compiler error? Of course, an error like this will hit the first person who tried to declare that the method throws an exception ... :(

The study is still ...

  • , . , Travis CI Linux, macOS, ( , !), Windows .
  • Gradle, javac , javac.
  • javac :

    javac -source 1.8 -target 1.8 -d build/classes/test \
      -classpath build/classes/main:build/resources/main:$HOME/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.8.2/979fc0cf8460302e4ffbfe38c1b66a99450b0bb7/log4j-core-2.8.2.jar:$HOME/.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-api/2.8.2/e590eeb783348ce8ddef205b82127f9084d82bf3/log4j-api-2.8.2.jar \
      -Xdoclint:all,-missing \
      src/test/java/com/acme/CodeTestUtils.java
    

    , Gradle . (Gradle -processorpath -g .)

+4
3

Log4j, , javac, Oracle , .

, Log4j - - -proc:none javac, , , , !

- . , .

+3

DocLint OpenJDK "dc.invalid.throws" , , @throws , Exception, - , .

, , . , , - .

. Lucene Jira, , :

( Solr build), , , .

+2

I duplicated this problem without Log4j. The project is located at https://github.com/rgoers/LOG4J2-1925 . From what I can say, this will happen to any annotation processor.

This error was posted by Oracle at http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8186647 .

+1
source

Source: https://habr.com/ru/post/1678219/


All Articles