Make release(int)
methods handle errors better
Exception types and error messages are now unified and more descriptive.
This commit is contained in:
parent
db7ac99699
commit
a48a12794d
@ -1678,13 +1678,14 @@ public final class ByteBufAdaptor extends ByteBuf {
|
||||
|
||||
@Override
|
||||
public boolean release(int decrement) {
|
||||
if (!buffer.isAccessible() || decrement > 1 + Statics.countBorrows((ResourceSupport<?, ?>) buffer)) {
|
||||
throw new IllegalReferenceCountException();
|
||||
int refCount = 1 + Statics.countBorrows((ResourceSupport<?, ?>) buffer);
|
||||
if (!buffer.isAccessible() || decrement > refCount) {
|
||||
throw new IllegalReferenceCountException(refCount, -decrement);
|
||||
}
|
||||
for (int i = 0; i < decrement; i++) {
|
||||
try {
|
||||
buffer.close();
|
||||
} catch (IllegalStateException e) {
|
||||
} catch (RuntimeException e) {
|
||||
throw new IllegalReferenceCountException(e);
|
||||
}
|
||||
}
|
||||
|
@ -1246,11 +1246,16 @@ class NioBuffer extends ResourceSupport<Buffer, NioBuffer> implements Buffer, Re
|
||||
|
||||
@Override
|
||||
public boolean release(int decrement) {
|
||||
if (!isAccessible() || decrement > 1 + countBorrows()) {
|
||||
throw new IllegalReferenceCountException();
|
||||
int refCount = 1 + countBorrows();
|
||||
if (!isAccessible() || decrement > refCount) {
|
||||
throw new IllegalReferenceCountException(refCount, -decrement);
|
||||
}
|
||||
for (int i = 0; i < decrement; i++) {
|
||||
close();
|
||||
try {
|
||||
close();
|
||||
} catch (RuntimeException e) {
|
||||
throw new IllegalReferenceCountException(e);
|
||||
}
|
||||
}
|
||||
return !isAccessible();
|
||||
}
|
||||
|
@ -1661,11 +1661,16 @@ class UnsafeBuffer extends ResourceSupport<Buffer, UnsafeBuffer> implements Buff
|
||||
|
||||
@Override
|
||||
public boolean release(int decrement) {
|
||||
if (!isAccessible() || decrement > 1 + countBorrows()) {
|
||||
throw new IllegalReferenceCountException();
|
||||
int refCount = 1 + countBorrows();
|
||||
if (!isAccessible() || decrement > refCount) {
|
||||
throw new IllegalReferenceCountException(refCount, -decrement);
|
||||
}
|
||||
for (int i = 0; i < decrement; i++) {
|
||||
close();
|
||||
try {
|
||||
close();
|
||||
} catch (RuntimeException e) {
|
||||
throw new IllegalReferenceCountException(e);
|
||||
}
|
||||
}
|
||||
return !isAccessible();
|
||||
}
|
||||
|
@ -1267,11 +1267,16 @@ class MemSegBuffer extends ResourceSupport<Buffer, MemSegBuffer> implements Buff
|
||||
|
||||
@Override
|
||||
public boolean release(int decrement) {
|
||||
if (!isAccessible() || decrement > 1 + countBorrows()) {
|
||||
throw new IllegalReferenceCountException();
|
||||
int refCount = 1 + countBorrows();
|
||||
if (!isAccessible() || decrement > refCount) {
|
||||
throw new IllegalReferenceCountException(refCount, -decrement);
|
||||
}
|
||||
for (int i = 0; i < decrement; i++) {
|
||||
close();
|
||||
try {
|
||||
close();
|
||||
} catch (RuntimeException e) {
|
||||
throw new IllegalReferenceCountException(e);
|
||||
}
|
||||
}
|
||||
return !isAccessible();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user