This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 199215 - package-info.java --> annotation type not applicable to this kind of declaration
Summary: package-info.java --> annotation type not applicable to this kind of declaration
Status: RESOLVED INVALID
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 7.0
Hardware: PC Linux
: P3 normal (vote)
Assignee: Dusan Balek
URL:
Keywords:
Depends on: 178452
Blocks:
  Show dependency tree
 
Reported: 2011-06-06 20:34 UTC by psilvaggio
Modified: 2011-06-08 19:48 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description psilvaggio 2011-06-06 20:34:37 UTC
Seems NetBeans compiler doesn't like it when an annotation is placed before package in package-info.java.

This is the error I get:

"annotation type not applicable to this kind of declaration"

From:

@SequenceGenerator(name = "seqId", sequenceName = "SEQ_ID", allocationSize = 1)

package com.something.something.everything.nothing.whatever;

import javax.persistence.SequenceGenerator;
Comment 1 Jan Lahoda 2011-06-07 15:14:12 UTC
Sorry, but it appears that the SequenceGenerator has specified "@Target(value={TYPE,METHOD,FIELD})". I.e. it cannot be applied to packages and the error is correct.
Comment 2 psilvaggio 2011-06-07 22:44:17 UTC
Well, let me just say that this was working in NetBeans < 7.0.

Also, take a look here:

http://docs.jboss.org/ejb3/app-server/HibernateAnnotations/reference/en/html_single/index.html

Also, the spec:

http://java.sun.com/docs/books/jls/third_edition/html/packages.html

Lets be frank, the spec is not crystal clear on this BUT javac compiles fine.

The fact that the annotation target is not PACKAGE seems to be irrelevant in the case of package-info.java since it is NOT a standard java class but a synthetic interface.

Please don't easily dismiss this.
Comment 3 Jan Lahoda 2011-06-08 19:32:59 UTC
(In reply to comment #2)
> Well, let me just say that this was working in NetBeans < 7.0.

Yes, there was a bug in NetBeans < 7.0 and javac before JDK7. The annotations were not properly validated, so some errors were incorrectly missing.

> 
> Also, take a look here:
> 
> http://docs.jboss.org/ejb3/app-server/HibernateAnnotations/reference/en/html_single/index.html

I see its marked with "3.1 beta 9". If I take a look at e.g.:
http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/
it no longer proposes to put this annotation on packages.

> 
> Also, the spec:
> 
> http://java.sun.com/docs/books/jls/third_edition/html/packages.html
> 
> Lets be frank, the spec is not crystal clear on this BUT javac compiles fine.

I think that the javadoc for the java.lang.annotation.Target is quite clear ("If such a meta-annotation is present, the compiler will enforce the specified usage restriction."). This program would be rejected by any recent JDK7 javac, AFAIK.

> 
> The fact that the annotation target is not PACKAGE seems to be irrelevant in
> the case of package-info.java since it is NOT a standard java class but a
> synthetic interface.

Sorry, I do not follow. The annotations in package-info.java clearly apply to whole package, and so should have ElementType.PACKAGE.

> 
> Please don't easily dismiss this.

I am sorry, but the error is correct according to the specifications, and so there is basically nothing that could be done on NetBeans level.
Comment 4 psilvaggio 2011-06-08 19:48:46 UTC
Thank you for your explication, good stuff.

However, I'd like to point out that the language used in the spec is fuzzy at best. Just look at the wide spread usage of my case... even Hibernate proposed this...

5/5