JavaDoc - Undeclared Type Variable

北城以北 提交于 2020-01-07 04:57:27

问题


I think everybody who has to work with Maven and Java8 knows of this bug that release builds suddenly fail for spelling mistakes in JavaDoc. As a company we decided to let some poor sap (aka me) work all of them out. Now I'm stuck with the following "error":

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:2.10.1:javadoc (default-cli) on project org.acme.project.demo: An error has occurred in JavaDocs report generation:
[ERROR] Exit code: 1 - C:\jenkins\workspace\Project 2.0\org.acme.project.demo\src\main\java\org\acme\project\demo\SomeClass.java:36: error: cannot access OtherClass
[ERROR] import org.acme.project.OtherClass;
[ERROR] ^
[ERROR] bad class file: C:\jenkins\workspace\Project 2.0\org.acme.project\target\org.acme.project-2.0.0-SNAPSHOT-v20150128-1503.jar(org/acme/project/OtherClass.class)
[ERROR] undeclared type variable: N
[ERROR] Please remove or make sure it appears in the correct subdirectory of the classpath.

I tried to clean it up a bit, but to summarize: Project B throws the exception when it tries to resolve a method call to Project A (yes, while generating JavaDoc!). The method in question looks like that:

public static <N extends Bean> void hookContinousImageFunction(final OtherClass<N> dialog,
        final ImageGroup imageGroup, N model, final BiFunction<Image, N, ? extends Image> imageFunction) {
    final Image original = imageGroup.getImage();
    dialog.setOnCancelClick((notUsed) -> imageGroup.setImage(original));
    model.addPropertyChangeListener(new ContinousImageFunctionListener<>(dialog, imageGroup, imageFunction));
    dialog.setInitialModel(model);
}

It doesn't even have JavaDoc (not that any of this should matter when the generation of Project A's JavaDoc is already finished, and Maven is trying to generate JavaDoc for Project B).

As of now, we have this bug in multiple projects, about 1 out of 5. Project A (the one with a typed method / class like above) is more often than not in an entirely different build reactor and sometimes completely out of our control.

How do I fix this bug inside a bug?

(As a as a side note, the error occurs on the Jenkin's running with Java 1.8.0_31 and jdk1.8.0_40 or locally with 1.8.0_45, 1.8.0_60, but not locally with 1.8.0_20, but JavaDoc generation hasn't been that reliable, so I can't say for sure it has something to do with the Java version.)


回答1:


I got the same kind of error message using a central build while having no problems in my local build. (Unfortunately I have no details about the central build environment.)

Adding a '@param ' explanation in the JavaDoc comment for the static method in question solved the issue. Adapted to the given example I did something like this:

/**
 * @param <N> This is the class that ...
 */
public static <N extends Bean> void hookContinuousImageFunction(...)



回答2:


Okay the answer is to a) downgrade Java to 1.8.0_20, or - if that is not possible - b) to use this code in the pom.xml to disable JavaDoc of the project until the Java people feel the need to fix the bug:

<properties>
    <maven.javadoc.skip>true</maven.javadoc.skip>
</properties>


来源:https://stackoverflow.com/questions/28208139/javadoc-undeclared-type-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!