JDK 9 RFR for JDK-8028543 Add SourceVersion.RELEASE_9

Jeremy Manson jeremymanson at google.com
Fri Dec 6 20:15:03 PST 2013


The down side of claiming that you always support latest is that lambdas
come around, and you don't support them, but you claim to do so.  That's
fine when you control the whole codebase, but less than ideal for public
releases.

Jeremy


On Fri, Dec 6, 2013 at 6:00 PM, Martin Buchholz <martinrb at google.com> wrote:

> Our experience has been that our software is far more likely to break
> because we did not claim to support latest.  Java's compatibility is still
> high, and if a JDK update does eventually break things, then we just have
> to fix them for the new JDK version anyways - so my recommendation is to
> return SourceVersion.latest() always.
>
>
> On Fri, Dec 6, 2013 at 5:41 PM, Joseph Darcy <joe.darcy at oracle.com> wrote:
>
>>  Hi Martin,
>>
>>
>> On 12/6/2013 2:31 PM, Martin Buchholz wrote:
>>
>> We have found as users of this API, that these incrementing RELEASE_
>> constants were not helpful.  If code supported jdkN and jdkN+1, it couldn't
>> claim to support jdkN+1 because that would not compile with jdkN, since the
>> corresponding RELEASE_N+1 symbol was not defined in jdkN.  We felt
>> compelled to rewrite code to always claim to support the "latest" release.
>>
>>  Perhaps it would work if you added RELEASE_XX for releases far into the
>> future.  But you can't go back and update all the old JDKs now.  They've
>> left the barn.
>>
>>  Or perhaps we were using the API incorrectly.  Are we missing something
>> obvious?  I'm hardly the expert...
>>
>>
>> If you have taken the trouble to make a processor robust in the face of
>> unknown future language versions, then returning latest is the right thing
>> to do. However, this can be a nontrivial amount of extra work.
>>
>> If you are in a situation where you are supporting N and N+1 only and
>> want to run on either N or N+1 (and nothing else), you would just need to
>> use a construct without direct reference to N+1 for the processor to
>> communicate with the environment. You could so something a bit ugly like
>>
>> if (SourceVersion.latest() > RELEASE_N)
>>     // Return RELEASE_(N+1) with a direct reference to RELEASE_(N+1)
>>     return SourceVersion.value()[RELEASE_N.ordinal()+1];
>> else
>>     return RELEASE_N;
>>
>> HTH,
>>
>> -Joe
>>
>>
>>
>>
>>
>> On Fri, Dec 6, 2013 at 2:11 PM, Joseph Darcy <joe.darcy at oracle.com>wrote:
>>
>>> Hello,
>>>
>>> With JDK 9 going to get underway soon, please review the patch below to
>>> address
>>>
>>>     JDK-8028543 Add SourceVersion.RELEASE_9
>>>     https://bugs.openjdk.java.net/browse/JDK-8028543
>>>
>>>     http://cr.openjdk.java.net/~darcy/8028543.0/
>>>
>>> Thanks,
>>>
>>> -Joe
>>>
>>> --- old/src/share/classes/javax/lang/model/SourceVersion.java 2013-12-06
>>> 14:06:51.000000000 -0800
>>> +++ new/src/share/classes/javax/lang/model/SourceVersion.java 2013-12-06
>>> 14:06:51.000000000 -0800
>>> @@ -55,6 +55,7 @@
>>>       * 1.6: no changes
>>>       * 1.7: diamond syntax, try-with-resources, etc.
>>>       * 1.8: lambda expressions and default methods
>>> +     * 1.9: To be determined
>>>       */
>>>
>>>      /**
>>> @@ -138,7 +139,15 @@
>>>       * Additions in this release include lambda expressions and default
>>> methods.
>>>       * @since 1.8
>>>       */
>>> -    RELEASE_8;
>>> +    RELEASE_8,
>>> +
>>> +    /**
>>> +     * The version recognized by the Java Platform, Standard Edition
>>> +     * 9.
>>> +     *
>>> +     * @since 1.9
>>> +     */
>>> +     RELEASE_9;
>>>
>>>      // Note that when adding constants for newer releases, the
>>>      // behavior of latest() and latestSupported() must be updated too.
>>> @@ -149,21 +158,23 @@
>>>       * @return the latest source version that can be modeled
>>>       */
>>>      public static SourceVersion latest() {
>>> -        return RELEASE_8;
>>> +        return RELEASE_9;
>>>      }
>>>
>>>      private static final SourceVersion latestSupported =
>>> getLatestSupported();
>>>
>>>      private static SourceVersion getLatestSupported() {
>>>          try {
>>> -            String specVersion =
>>> System.getProperty("java.specification.version");
>>> -
>>> -            if ("1.8".equals(specVersion))
>>> +            switch (System.getProperty("java.specification.version")) {
>>> +            case "1.9":
>>> +                return RELEASE_9;
>>> +            case "1.8":
>>>                  return RELEASE_8;
>>> -            else if("1.7".equals(specVersion))
>>> +            case "1.7":
>>>                  return RELEASE_7;
>>> -            else if("1.6".equals(specVersion))
>>> +            case "1.6":
>>>                  return RELEASE_6;
>>> +            }
>>>          } catch (SecurityException se) {}
>>>
>>>          return RELEASE_5;
>>> @@ -269,7 +280,6 @@
>>>       * @return {@code true} if {@code s} is a keyword or literal,
>>> {@code false} otherwise.
>>>       */
>>>      public static boolean isKeyword(CharSequence s) {
>>> -        String keywordOrLiteral = s.toString();
>>> -        return keywords.contains(keywordOrLiteral);
>>> +        return keywords.contains(s.toString());
>>>      }
>>>  }
>>> --- old/test/tools/javac/processing/model/TestSourceVersion.java
>>> 2013-12-06 14:06:51.000000000 -0800
>>> +++ new/test/tools/javac/processing/model/TestSourceVersion.java
>>> 2013-12-06 14:06:51.000000000 -0800
>>> @@ -1,5 +1,5 @@
>>>  /*
>>> - * Copyright (c) 2011, Oracle and/or its affiliates. All rights
>>> reserved.
>>> + * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights
>>> reserved.
>>>   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
>>>   *
>>>   * This code is free software; you can redistribute it and/or modify it
>>> @@ -23,7 +23,7 @@
>>>
>>>  /*
>>>   * @test
>>> - * @bug 7025809
>>> + * @bug 7025809 8028543
>>>   * @summary Test latest and latestSupported
>>>   * @author  Joseph D. Darcy
>>>   */
>>> @@ -36,8 +36,8 @@
>>>   */
>>>  public class TestSourceVersion {
>>>      public static void main(String... args) {
>>> -        if (SourceVersion.latest() != RELEASE_8 ||
>>> -            SourceVersion.latestSupported() != RELEASE_8)
>>> +        if (SourceVersion.latest() != RELEASE_9 ||
>>> +            SourceVersion.latestSupported() != RELEASE_9)
>>>              throw new RuntimeException("Unexpected release value(s)
>>> found:\n" +
>>>                                         "latest:\t" +
>>> SourceVersion.latest() + "\n" +
>>>                                         "latestSupported:\t" +
>>> SourceVersion.latestSupported());
>>>
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20131206/8e32357a/attachment.html 


More information about the compiler-dev mailing list