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 216994 - A public class generated by an annotation is not visible outside its module.
Summary: A public class generated by an annotation is not visible outside its module.
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 7.2
Hardware: PC Windows 7
: P2 normal (vote)
Assignee: Tomas Zezula
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-08-17 06:01 UTC by pjdm
Modified: 2012-10-01 12:07 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Example project that demonstrates a non-visible public generated class. (45.08 KB, application/x-zip-compressed)
2012-08-17 06:01 UTC, pjdm
Details
Annotations Suite (1.16 MB, application/octet-stream)
2012-09-27 17:59 UTC, Tomas Zezula
Details

Note You need to log in before you can comment on or make changes to this bug.
Description pjdm 2012-08-17 06:01:28 UTC
Created attachment 123221 [details]
Example project that demonstrates a non-visible public generated class.

If use an annotation processor to generate a public class in module A, then module B with a dependency on module A cannot see that class, even though the generated class is public and in a module public package.

See the attachment for an example project containing an annotation processor that generates a class in one module that is not visible from another module. See the README.txt for details.
Comment 1 Jaroslav Tulach 2012-08-20 16:57:17 UTC
Interesting case. I talk to the Java guys about this tomorrow.
Comment 2 pjdm 2012-09-25 11:53:54 UTC
So how interesting is it? :-) I'd like to be able to do this.
Comment 3 Tomas Zezula 2012-09-26 13:57:19 UTC
In fact it's not very interesting case. :-)
The thing is that the project containing the AnnotationProcessor (AP) is not built when the projects are opened in the IDE and indexed. The JavaCustomIndexer cannot execute the AP as it does not exist. If you build the project containing the AP before you open the projects there are no errors. This behaviour is correct but the IDE should reindex (rescan) the source roots having the AP on the annotation processor path which currently does not happen which is a bug.
Comment 4 Tomas Zezula 2012-09-26 14:04:49 UTC
Fixed jet-main 2ecb86354a59.
The APTUtils.verify now detects creation of an root containing the built AP and forces reindex of the affected source root.
For NB 7.2 you can resolve the problem by coping the jar containing the AP and adding the copied jar to processor path rather than the project reference.
Comment 5 pjdm 2012-09-27 13:36:52 UTC
Sorry, I'll try to find more interesting problems. :-)

"For NB 7.2 you can resolve the problem by coping the jar containing the AP and
adding the copied jar to processor path rather than the project reference."

I removed the Annotations module and put the annotation code in a separate Java project to create a JAR, then added the JAR in Libraries -> Wrapped Jars for the Services module. Since this is being done in a framework application, there is no "processor-path libraries" option, so I added "-processor ex.annotations.processors.MyServiceProcessor -processorpath /path/to/AP.jar" to the "Additional Compiler Options" field for the Services module.

The ex.services.MyServiceName class is successfully generated as before, so the annotation processor is being found and is working. However the source in the Display module still can't see the generated ex.services.MyServiceNames, so the problem remains with your workaround, unless I'm misunderstanding.

Can you please explain your workaround a little more. Thanks.
Comment 6 Tomas Zezula 2012-09-27 17:57:31 UTC
Fixed for NB 7.3:
Please do not change the status for older releases it makes the issue tracking difficult for QE.


For NB 7.2 :
The first steps you have described sounds good to me, copy jar (it's important to have a copy outside the build), create a library wrapper for it and use it instead of the library. So far so good. Now comes the problem, the project is API Support project not regular Ant project and it does not have annotation processing path, right. You have added the AP to the additional compiler options, but these options are just the Ant options they are not used by the editor or compile on save. These features don't know about them, so the IDE in fact does not run the AP only the Ant runs it when it's built. Fortunately when the processor path is not given javac uses classpath to resolve APs (adding the library wrapper module to classpath instread of the Annotations project is enough). Just removing the additional compiler options should fix the problem.

As single example is better than tons of comments I am attaching your Annotations Suite which is changed to use library module wrapper. I've tried it in NB 7.2 and it works fine for me, the actions correctly see the generated MyServiceName.
Comment 7 Tomas Zezula 2012-09-27 17:59:27 UTC
Created attachment 125025 [details]
Annotations Suite
Comment 8 pjdm 2012-10-01 06:39:59 UTC
It took me a while, but I made it work. The thing I think I was missing was that I had moved my annotation processor to a Java class library project which no longer had "@ServiceProvider(Service=Processor.class)", so the "META-INF/services/javax.annotation.processing.Processor" file wasn't in the JAR. The annotation processor was still working, but presumably the service file is required for NetBeans to take the extra step of noticing the generated class.

I built the JAR by hand from the Annotations Module build directory, but my MANIFEST.MF is much simpler than yours. How did you build your annotations.jar file?
Comment 9 Tomas Zezula 2012-10-01 11:49:44 UTC
>How did you build your annotations.jar file?
I let the IDE built it and then copy it to /tmp and point the New Library Wrapper Module Wizard to this copy. It was copied by the wizard into the new library wrapper project.
Comment 10 Quality Engineering 2012-10-01 12:07:30 UTC
Integrated into 'main-golden', will be available in build *201210010929* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/2ecb86354a59
User: Tomas Zezula <tzezula@netbeans.org>
Log: #216994:A public class generated by an annotation is not visible outside its module.