changeset 47644:fd458b0b7749

8062385: Remove @SuppressWarnings("cast") and casts for NIO related usages when JDK 9 becomes the bootstrap JDK Reviewed-by: mcimadamore
author darcy
date Wed, 25 Oct 2017 10:40:45 -0700
parents 599bd0aa4433
children 9887d1bc3e9c
files src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java
diffstat 2 files changed, 5 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java	Tue Oct 17 12:17:17 2017 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/BaseFileManager.java	Wed Oct 25 10:40:45 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;
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Tue Oct 17 12:17:17 2017 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/file/JavacFileManager.java	Wed Oct 25 10:40:45 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();
     }