# HG changeset patch # User bpb # Date 1584572715 25200 # Node ID e5707e56381b5f01a2c6754a7a8ea7b8eae6c3ad # Parent f08f26ff2669ef9c71e728ed6599b2e49344d495 8238920: Better Buffer support Reviewed-by: alanb, ahgross, rhalade, psandoz, mbalao, andrew diff -r f08f26ff2669 -r e5707e56381b src/share/classes/java/nio/Buffer.java --- a/src/share/classes/java/nio/Buffer.java Wed Mar 25 16:26:21 2020 -0700 +++ b/src/share/classes/java/nio/Buffer.java Wed Mar 18 16:05:15 2020 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2011, 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 @@ -266,8 +266,8 @@ 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; } @@ -488,16 +488,18 @@ * @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) + int p = position; + if (limit - p < nb) throw new BufferUnderflowException(); - int p = position; - position += nb; + position = p + nb; return p; } @@ -509,16 +511,18 @@ * @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) + int p = position; + if (limit - p < nb) throw new BufferOverflowException(); - int p = position; - position += nb; + position = p + nb; return p; }