JDK-8160601 : unexpected error compiling @Deprecated package
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-06-29
  • Updated: 2024-11-20
  • Resolved: 2020-09-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 16
16 b15Fixed
Related Reports
Relates :  
Description
The @Deprecated annotation is supposed to be ignored if it occurs on a package declaration in a package-info.java file. It usually is, unless a javadoc comment with an @deprecated tag also appears on the same package declaration. Consider this package-info.java file:

========================================
/**
 * @deprecated This is a deprecated package.
 */
@Deprecated
package com.example.foobar;
========================================

Compiling this results in the following:

package-info.java:5: error: modifier deprecated not allowed here
package com.example.foobar;
^
1 error


Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/68563b1343f3 User: jlahoda Date: 2020-09-03 09:16:10 +0000
03-09-2020

I think this falls out of how the parser records `@deprecated` in the same bit set as actual modifiers, and then asserts that package-info's don't have modifiers. The parallel assertion on module declarations ignores `@deprecated`: http://hg.openjdk.java.net/jdk/jdk/file/3cf00fca0fbf/src/jdk.compiler/share/classes/com/sun/tools/javac/parser/JavacParser.java#l3252 Can we do the same thing for package-info? JDK-8193377 suggests this is working as intended and that the diagnostic should be improved. But if using `@deprecated` on package declarations is an error, shouldn't it be an error regardless of whether or not annotations are present? The following is currently accepted, and rejecting it would have compatibility implications: ``` /** @deprecated */ package foo; ```
13-04-2018

The bizarre thing about the error message is that "deprecated" (little-d) is not a modifier, and so if nothing else, the text of the error message needs to be made more accurate.
29-06-2016