Julian Reschke
Julian Reschke

Reputation: 42045

Weird javadoc error (with jdk12) for OSGi version annotation

With the change from Java 11 to Java 12, we now see a weird error when generating Javadoc on package-info files containing OSGi version annotations.

The source code is:

@Version("1.3.0")
package org.apache.jackrabbit.oak.commons;

import org.osgi.annotation.versioning.Version;

The error is:

[ERROR] C:\projects\apache\oak\trunk\oak-commons\src\main\java\org\apache\jackrabbit\oak\commons\package-info.java:17: error: unknown tag: Version
[ERROR] @Version("1.3.0")
[ERROR] ^

(See details and context)

Is this a regression in Java 12, or is there something wrong in the way the annotations are used, or how Javadoc is invoked (through maven)?

Upvotes: 4

Views: 796

Answers (2)

Liam Miller-Cushon
Liam Miller-Cushon

Reputation: 450

The fix is to upgrade to a newer JDK version.

The issue affects JDK 12, and was fixed in JDK 13 by JDK-8222091: Javadoc does not handle package annotations correctly on package-info.java.

The same issue also affects OpenJDK 11.0.17, because the change that introduced the javadoc regression was backported. It was fixed in JDK 11.0.18. (See https://bugs.openjdk.org/browse/JDK-8295850.)

Simplified repro:

package p;

import static java.lang.annotation.ElementType.PACKAGE;

import java.lang.annotation.Target;

@Target(PACKAGE)
public @interface A {}
@A
package p;
$ javadoc package-info.java A.java
...
package-info.java:1: error: unknown tag: A
@A
^

Upvotes: 3

Marcos Zolnowski
Marcos Zolnowski

Reputation: 2797

Probably a Javadoc bug, because Javadoc considers the Java Annotation as a Javadoc Tag.

Workaround 1: disable this Javadoc tag

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>                        
                    <tags>
                        <tag>
                            <name>Version</name>                            
                            <placement>X</placement>                            
                        </tag>
                    </tags>
                </configuration>
            </plugin>

Workaround 2: add an empty Javadoc block in front of every annotation

/** */@Version("1.3.0")
package org.apache.jackrabbit.oak.commons;

Upvotes: 4

Related Questions