Hi David,

> On May 21, 2018, at 5:05 PM, David Holmes <david.hol...@oracle.com> wrote:
> 
> Hi Paul,
> 
> On 22/05/2018 2:39 AM, Paul Sandoz wrote:
>>> On May 20, 2018, at 11:32 PM, David Holmes <david.hol...@oracle.com> wrote:
>>> 
>>>> 3984     public Class<?>[] getNestMembers() {
>>>> I still think not removing dups is a mistake as it could be a source of 
>>>> subtle bugs. But i doubt at this point i can persuade you or others to 
>>>> change it :-)
>>> 
>>> Unlikely. :) Again well-formed programs just won't encounter this and it 
>>> would penalize all well-formed programs.
>>> 
>> Although those well-formed programs may need to check for dups themselves 
>> because they don’t want to rely in implementation details (and they are not 
>> aware of the probability of implementations deviating).
> 
> I'm quite concerned about your level of concern with "dups". This just 
> shouldn't be an issue. While the spec allows for dups javac will never 
> produce them - and file a bug on it if it ever does! Similarly for other 
> compilers - there is no reason to generate duplicate entries.
> 

Perhaps i am obsessing a little too much, i thought there might be a slight 
window of opportunity while other related reviews are progressing :-) but i 
don’t want to block things for 11.

My concern, placing my library/API designer hat on, is the specification is 
saying something very clear and yet on the other hand it's as if we are saying 
“oh you can ignore that, the specification does not matter, it will never 
happen in practice”. It feels like the JVM world is intruding too much into the 
reflection world (see below).


> Looking through the JVMS and the defined classfile attributes it seems to me 
> that the annotations[] of RuntimeVisibleAnnotations (et al) doesn't preclude 
> duplicates either. And the bootstrap_methods[] of the 
> BootstrapMethodsAttribute. Also look at the parameters[] of the 
> MethodParametersAttribute**. Do you agree?
> 
> ** Which even has an explicit note this is not something a JVM implementation 
> has to check.
> 

I don’t dispute there may be duplicate information in class file bytes, nor am 
i suggesting the class file bytes for nestmates be changed, nor that the 
verifier get involved. However, the reflection API is not a direct reflection 
of those class file bytes. It provides a runtime view of a class and often 
performs its own computation from and validation of information in the class 
file bytes.

Not all information in the class file bytes is directly accessible via the 
reflection API, such as BootstrapMethodsAttribute, or 
MethodParametersAttribute, the latter of which AFAICT is exposed via the 
Reflection API indirectly via a Parameter[] array returned by 
Method.getParameters(). 

I am less sure about RuntimeVisibleAnnotations but there is quite a lot of 
processing performed by the Java reflection code before annotations reach the 
hands of the developer, and a quick look at some code shows the use of maps 
keyed by annotation class to the annotation value. And see for example here in 
AnnotationParser:

    if (AnnotationType.getInstance(klass).retention() == 
RetentionPolicy.RUNTIME &&
        result.put(klass, a) != null) {
            throw new AnnotationFormatError(
                "Duplicate annotation for class: "+klass+": " + a);

http://hg.openjdk.java.net/jdk/jdk/file/95ba3a1dc2b2/src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java#l110



>> Here’s a thought: did you consider caching the nest members in the 
>> ReflectionData class? that may be worth doing regardless of dups.
> 
> No that was not considered. Caching, as you know, is a space-time trade off 
> and we have no data to use to determine whether caching would be of any 
> benefit here. To me that would be a future RFE regardless. (And I don't 
> expect these introspective nest methods to be used much in any case.)
> 

Yes, agreed, caching can be possible future work.

Paul,

Reply via email to