changeset 14920:4d9881c6049d

Merge
author andrew
date Tue, 19 Jan 2021 20:49:30 +0000
parents 90cbca4d2c6b (current diff) d8cb8035b8f3 (diff)
children 46d30306b027
files
diffstat 4 files changed, 23 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/.hgtags	Wed Aug 28 14:22:56 2019 +0200
+++ b/.hgtags	Tue Jan 19 20:49:30 2021 +0000
@@ -1069,3 +1069,5 @@
 25cd39ef5b983c7199ce9954b7e2723eae097fe0 jdk8u282-b05
 ef358e4669db1e22ae8939683e6801f4a9d5369b jdk8u282-b06
 aa9f038a703421ab7e3daf7bb3190fab1ab11681 jdk8u282-b07
+6fe9792e7893a43c0718cf6d5082f62f9bc52787 jdk8u282-b08
+6fe9792e7893a43c0718cf6d5082f62f9bc52787 jdk8u282-ga
--- a/src/share/classes/java/nio/Buffer.java	Wed Aug 28 14:22:56 2019 +0200
+++ b/src/share/classes/java/nio/Buffer.java	Tue Jan 19 20:49:30 2021 +0000
@@ -242,8 +242,8 @@
     public final Buffer position(int newPosition) {
         if ((newPosition > limit) || (newPosition < 0))
             throw new IllegalArgumentException();
+        if (mark > newPosition) mark = -1;
         position = newPosition;
-        if (mark > position) mark = -1;
         return this;
     }
 
@@ -388,7 +388,8 @@
      * @return  The number of elements remaining in this buffer
      */
     public final int remaining() {
-        return limit - position;
+        int rem = limit - position;
+        return rem > 0 ? rem : 0;
     }
 
     /**
--- a/src/share/classes/java/nio/Heap-X-Buffer.java.template	Wed Aug 28 14:22:56 2019 +0200
+++ b/src/share/classes/java/nio/Heap-X-Buffer.java.template	Tue Jan 19 20:49:30 2021 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2020, 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
@@ -234,7 +234,9 @@
     public $Type$Buffer compact() {
 #if[rw]
         int pos = position();
-        int rem = limit() - pos;
+        int lim = limit();
+        assert (pos <= lim);
+        int rem = (pos <= lim ? lim - pos : 0);
         System.arraycopy(hb, ix(pos), hb, ix(0), rem);
         position(rem);
         limit(capacity());
--- a/src/share/classes/java/nio/X-Buffer.java.template	Wed Aug 28 14:22:56 2019 +0200
+++ b/src/share/classes/java/nio/X-Buffer.java.template	Tue Jan 19 20:49:30 2021 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2020, 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
@@ -414,15 +414,23 @@
      */
     public int read(CharBuffer target) throws IOException {
         // Determine the number of bytes n that can be transferred
+        int limit = limit();
+        int pos = position();
+        int remaining = limit - pos;
+        assert remaining >= 0;
+        if (remaining <= 0) // include equality condition when remaining == 0
+            return -1;
+
         int targetRemaining = target.remaining();
-        int limit = limit();
-        int remaining = limit - position();
-        if (remaining == 0)
-            return -1;
+        assert targetRemaining >= 0;
+        if (targetRemaining <= 0) // include condition targetRemaining == 0
+            return 0;
+
         int n = Math.min(remaining, targetRemaining);
+
         // Set source limit to prevent target overflow
         if (targetRemaining < remaining)
-            limit(position() + n);
+            limit(pos + n);
         try {
             if (n > 0)
                 target.put(this);