RFR 7199353: Allow ConstructorProperties annotation from any package

Peter Levart peter.levart at gmail.com
Fri Oct 9 17:47:47 UTC 2015



On 10/09/2015 06:54 PM, Alan Bateman wrote:
>
>
> On 09/10/2015 16:36, Peter Levart wrote:
>> :
>>
>>
>> Sorry, but I must be missing something.
>>
>> When you compile a class (not an MXBean as Daniel pointed out, but a 
>> data object class) with JDK9, it can't be used on JDK8 because of 
>> class file version.
>>
>> When you compile a class with JDK8, it can't contain new @CS 
>> annotation, because it is not part of the official Java SE API on the 
>> Java 8 platform.
>>
>>
>> So I still don't see how one could compile a data class so that it 
>> could be used on JDK8 as well as on JDK9 without java.desktop module?
> I think you have it right as there isn't a @CP that works for this 
> scenario. The compiling with JDK 8 and trying to deploy on runtime 
> that only has a subset of the standard modules is essentially the 
> scenario that is already warned about in the javadoc:
>
> "Rule 2 is not applicable to subset Profiles of Java SE that do not 
> include the java.beans package. When targeting a runtime that does not 
> include the java.beans package, and where there is a mismatch between 
> the compile-time and runtime environment whereby J is compiled with a 
> public constructor and the ConstructorProperties annotation, then J is 
> not reconstructible unless another rule applies."
>
> A solution that updates Java SE 8 to specify the new @CP or having it 
> using method parameters would require doing a MR of Java SE 8 and I 
> doubt it's important enough to go justify that.
>
> Possible workarounds are to compile on JDK 8 with "-profile compact3" 
> as this should fail if there is code using @beans.CP. Another one 
> would to just define a static "from" method.
>
> -Alan.

Another one would be to use yet another hack: add equivalent 
self-written /javax/management/annotation/ConstructorProperties.java 
annotation to the project sources and compile it with data classes that 
use both annotations, using JDK8. Then just package data classes.

Peter



More information about the jigsaw-dev mailing list