package-info

Joe Darcy Joe.Darcy at Sun.COM
Tue Nov 3 16:15:10 PST 2009


On 11/03/09 02:35 PM, Jonathan Gibbons wrote:
> Andrew John Hughes wrote:
>> 2009/11/3 Jonathan Gibbons <Jonathan.Gibbons at sun.com>:
>>   
>>> Currently, javac does not generate package-info.class when package-info.java
>>> contains no annotations.
>>>
>>> This can cause issues for build systems that assume that for every *.java
>>> file, the compiler ought to generate a corresponding *.class file.
>>>
>>> It appears that Ant 1.8 has apparently taken it upon itself to "work around"
>>> this issue, by generating package-info.class if javac does not. Does anyone
>>> have any opinions as to whether this is a good or bad idea? Is this
>>> something that should really be fixed in javac, perhaps as an optional
>>> behavior?
>>>
>>> -- Jon
>>>
>>>
>>>
>>>     
>>
>> What would such a class contain? Presumably it would be just an empty
>> shell, with just a single no-argument constructor?
>>
>> The package-info.java (and module-info.java) are a bit of a hack as
>> pseudo-Java classes to begin with, so it doesn't surprise me all that
>> much that another hack is needed to make them indistinguishable from
>> normal classes.
>>   
> Yes, it would presumably be an empty shell class.
>
> -- Jon

Yes, no constructor need be present; here is the verbose javap output 
from a package-info file with an annotation:

javap -verbose package-info.class
Classfile /home/darcy/Scratch/package-info.class
  Last modified Nov 3, 2009; size 109 bytes
  MD5 checksum dfc45af5b7a94a2f4bdf5c42ba29eafc
  Compiled from "package-info.java"
interface foo.package-info
  SourceFile: "package-info.java"
  minor version: 0
  major version: 51
  flags: ACC_INTERFACE, ACC_ABSTRACT, ACC_SYNTHETIC
Constant pool:
  #1 = Class              #5              //  "foo/package-info"
  #2 = Class              #6              //  java/lang/Object
  #3 = Utf8               SourceFile
  #4 = Utf8               package-info.java
  #5 = Utf8               foo/package-info
  #6 = Utf8               java/lang/Object
{
}

-Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20091103/dc31be45/attachment.html 


More information about the compiler-dev mailing list