[prev in list] [next in list] [prev in thread] [next in thread] 

List:       openjdk-compiler-dev
Subject:    Re: JDK 10 RFR of JDK-8062385: Remove @SuppressWarnings("cast") and casts for NIO related usages whe
From:       Maurizio Cimadamore <maurizio.cimadamore () oracle ! com>
Date:       2017-10-24 8:10:30
Message-ID: 0f33c598-0207-7fa2-6918-8b011f105782 () oracle ! com
[Download RAW message or body]

Looks good

Maurizio


On 19/10/17 22:32, joe darcy wrote:
> Hello,
>
> With the bootstrap of JDK 10 updated to JDK 9, please review the small 
> patch below to address
>
>     JDK-8062385: Remove @SuppressWarnings("cast") and casts for NIO 
> related usages when JDK 9 becomes the bootstrap JDK
>
> For background, quoting the description of JDK-8062385:
>
>> The fix for JDK-4774077 introduced covariant return types in the NIO 
>> buffer hierarchy.
>>
>> As a consequence that fix introduced redundant casts (and because of 
>> -Werror a build failure) in langtools when compiling with JDK 9, but 
>> the casts are still required when bootstrapping with JDK 8.
>>
>> The fix for JDK-8062376 added @SuppressWarnings("cast") annotations 
>> to ensure no build failure.
>>
>> When JDK 9 becomes the default bootstrap JDK the 
>> @SuppressWarnings("cast") and casts can be removed. 
>
> Thanks,
>
> -Joe
>
> diff -r 92f08900cb3c 
> src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java
> --- 
> a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java 
> Thu Oct 19 17:47:04 2017 +0200
> +++ 
> b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java 
> Thu Oct 19 14:28:21 2017 -0700
> @@ -304,7 +304,6 @@
>          return (encodingName != null) ? encodingName : 
> getDefaultEncodingName();
>      }
>
> -    @SuppressWarnings("cast")
>      public CharBuffer decode(ByteBuffer inbuf, boolean 
> ignoreEncodingErrors) {
>          String encName = getEncodingName();
>          CharsetDecoder decoder;
> @@ -312,7 +311,7 @@
>              decoder = getDecoder(encName, ignoreEncodingErrors);
>          } catch (IllegalCharsetNameException | 
> UnsupportedCharsetException e) {
>              log.error(Errors.UnsupportedEncoding(encName));
> -            return (CharBuffer)CharBuffer.allocate(1).flip();
> +            return CharBuffer.allocate(1).flip();
>          }
>
>          // slightly overestimate the buffer size to avoid reallocation.
> @@ -389,7 +388,6 @@
>       * @return a byte buffer containing the contents of the stream
>       * @throws IOException if an error occurred while reading the stream
>       */
> -    @SuppressWarnings("cast")
>      public ByteBuffer makeByteBuffer(InputStream in)
>          throws IOException {
>          int limit = in.available();
> @@ -401,14 +399,14 @@
>                  // expand buffer
>                  result = ByteBuffer.
>                      allocate(limit <<= 1).
> -                    put((ByteBuffer)result.flip());
> +                    put(result.flip());
>              int count = in.read(result.array(),
>                  position,
>                  limit - position);
>              if (count < 0) break;
>              result.position(position += count);
>          }
> -        return (ByteBuffer)result.flip();
> +        return result.flip();
>      }
>
>      public void recycleByteBuffer(ByteBuffer bb) {
> @@ -418,14 +416,13 @@
>      /**
>       * A single-element cache of direct byte buffers.
>       */
> -    @SuppressWarnings("cast")
>      private static class ByteBufferCache {
>          private ByteBuffer cached;
>          ByteBuffer get(int capacity) {
>              if (capacity < 20480) capacity = 20480;
>              ByteBuffer result =
>                  (cached != null && cached.capacity() >= capacity)
> -                ? (ByteBuffer)cached.clear()
> +                ? cached.clear()
>                  : ByteBuffer.allocate(capacity + capacity>>1);
>              cached = null;
>              return result;
> diff -r 92f08900cb3c 
> src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java
> --- 
> a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java 
> Thu Oct 19 17:47:04 2017 +0200
> +++ 
> b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java 
> Thu Oct 19 14:28:21 2017 -0700
> @@ -98,10 +98,9 @@
>   */
>  public class JavacFileManager extends BaseFileManager implements 
> StandardJavaFileManager {
>
> -    @SuppressWarnings("cast")
>      public static char[] toArray(CharBuffer buffer) {
>          if (buffer.hasArray())
> -            return ((CharBuffer)buffer.compact().flip()).array();
> +            return buffer.compact().flip().array();
>          else
>              return buffer.toString().toCharArray();
>      }
>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic