diff --git a/src/share/classes/java/nio/Buffer.java b/src/share/classes/java/nio/Buffer.java index 2a90de846105c65483258639d7caaa66f5303f09..e45e05fe0eac2b282dbb1636adba5fae8f4a11aa 100644 --- a/src/share/classes/java/nio/Buffer.java +++ b/src/share/classes/java/nio/Buffer.java @@ -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 @@ -274,8 +274,8 @@ public abstract class Buffer { if ((newLimit > capacity) || (newLimit < 0)) throw new IllegalArgumentException(); limit = newLimit; - if (position > limit) position = limit; - if (mark > limit) mark = -1; + if (position > newLimit) position = newLimit; + if (mark > newLimit) mark = -1; return this; } @@ -496,16 +496,18 @@ public abstract class Buffer { * @return The current position value, before it is incremented */ final int nextGetIndex() { // package-private - if (position >= limit) + int p = position; + if (p >= limit) throw new BufferUnderflowException(); - return position++; + position = p + 1; + return p; } final int nextGetIndex(int nb) { // package-private - if (limit - position < nb) - throw new BufferUnderflowException(); int p = position; - position += nb; + if (limit - p < nb) + throw new BufferUnderflowException(); + position = p + nb; return p; } @@ -517,16 +519,18 @@ public abstract class Buffer { * @return The current position value, before it is incremented */ final int nextPutIndex() { // package-private - if (position >= limit) + int p = position; + if (p >= limit) throw new BufferOverflowException(); - return position++; + position = p + 1; + return p; } final int nextPutIndex(int nb) { // package-private - if (limit - position < nb) - throw new BufferOverflowException(); int p = position; - position += nb; + if (limit - p < nb) + throw new BufferOverflowException(); + position = p + nb; return p; }