use of java.nio.BufferOverflowException in project robovm by robovm.
the class FloatBufferTest method testPutfloat.
/*
* Class under test for java.nio.FloatBuffer put(float)
*/
public void testPutfloat() {
buf.clear();
for (int i = 0; i < buf.capacity(); i++) {
assertEquals(buf.position(), i);
FloatBuffer ret = buf.put((float) i);
assertEquals(buf.get(i), (float) i, 0.0);
assertSame(ret, buf);
}
try {
buf.put(0);
//$NON-NLS-1$
fail("Should throw Exception");
} catch (BufferOverflowException e) {
// expected
}
}
use of java.nio.BufferOverflowException in project platform_frameworks_base by android.
the class AndroidKeyStoreCipherSpiBase method engineDoFinal.
@Override
protected final int engineDoFinal(ByteBuffer input, ByteBuffer output) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException {
if (input == null) {
throw new NullPointerException("input == null");
}
if (output == null) {
throw new NullPointerException("output == null");
}
int inputSize = input.remaining();
byte[] outputArray;
if (input.hasArray()) {
outputArray = engineDoFinal(input.array(), input.arrayOffset() + input.position(), inputSize);
input.position(input.position() + inputSize);
} else {
byte[] inputArray = new byte[inputSize];
input.get(inputArray);
outputArray = engineDoFinal(inputArray, 0, inputSize);
}
int outputSize = (outputArray != null) ? outputArray.length : 0;
if (outputSize > 0) {
int outputBufferAvailable = output.remaining();
try {
output.put(outputArray);
} catch (BufferOverflowException e) {
throw new ShortBufferException("Output buffer too small. Produced: " + outputSize + ", available: " + outputBufferAvailable);
}
}
return outputSize;
}
use of java.nio.BufferOverflowException in project platform_frameworks_base by android.
the class RouterAdvertisementDaemon method assembleRaLocked.
private void assembleRaLocked() {
final ByteBuffer ra = ByteBuffer.wrap(mRA);
ra.order(ByteOrder.BIG_ENDIAN);
boolean shouldSendRA = false;
try {
putHeader(ra, mRaParams != null && mRaParams.hasDefaultRoute);
putSlla(ra, mHwAddr);
mRaLength = ra.position();
if (mRaParams != null) {
putMtu(ra, mRaParams.mtu);
mRaLength = ra.position();
for (IpPrefix ipp : mRaParams.prefixes) {
putPio(ra, ipp, DEFAULT_LIFETIME, DEFAULT_LIFETIME);
mRaLength = ra.position();
shouldSendRA = true;
}
if (mRaParams.dnses.size() > 0) {
putRdnss(ra, mRaParams.dnses, DEFAULT_LIFETIME);
mRaLength = ra.position();
shouldSendRA = true;
}
}
for (IpPrefix ipp : mDeprecatedInfoTracker.getPrefixes()) {
putPio(ra, ipp, 0, 0);
mRaLength = ra.position();
shouldSendRA = true;
}
final Set<Inet6Address> deprecatedDnses = mDeprecatedInfoTracker.getDnses();
if (!deprecatedDnses.isEmpty()) {
putRdnss(ra, deprecatedDnses, 0);
mRaLength = ra.position();
shouldSendRA = true;
}
} catch (BufferOverflowException e) {
// The packet up to mRaLength is valid, since it has been updated
// progressively as the RA was built. Log an error, and continue
// on as best as possible.
Log.e(TAG, "Could not construct new RA: " + e);
}
// We have nothing worth announcing; indicate as much to maybeSendRA().
if (!shouldSendRA) {
mRaLength = 0;
}
}
use of java.nio.BufferOverflowException in project flink by apache.
the class MemorySegmentTestBase method testByteBufferOutOfBounds.
// ------------------------------------------------------------------------
// ByteBuffer overflow / underflow and out of bounds
// ------------------------------------------------------------------------
@Test
public void testByteBufferOutOfBounds() {
try {
final int bbCapacity = pageSize / 10;
final int[] validOffsets = { 0, 1, pageSize / 10 * 9 };
final int[] invalidOffsets = { -1, pageSize + 1, -pageSize, Integer.MAX_VALUE, Integer.MIN_VALUE };
final int[] validLengths = { 0, 1, bbCapacity, pageSize };
final int[] invalidLengths = { -1, -pageSize, Integer.MAX_VALUE, Integer.MIN_VALUE };
final MemorySegment seg = createSegment(pageSize);
for (ByteBuffer bb : new ByteBuffer[] { ByteBuffer.allocate(bbCapacity), ByteBuffer.allocateDirect(bbCapacity) }) {
for (int off : validOffsets) {
for (int len : invalidLengths) {
try {
seg.put(off, bb, len);
fail("should fail with an IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException | BufferUnderflowException ignored) {
}
try {
seg.get(off, bb, len);
fail("should fail with an IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException | BufferOverflowException ignored) {
}
// position/limit may not have changed
assertEquals(0, bb.position());
assertEquals(bb.capacity(), bb.limit());
}
}
for (int off : invalidOffsets) {
for (int len : validLengths) {
try {
seg.put(off, bb, len);
fail("should fail with an IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException | BufferUnderflowException ignored) {
}
try {
seg.get(off, bb, len);
fail("should fail with an IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException | BufferOverflowException ignored) {
}
// position/limit may not have changed
assertEquals(0, bb.position());
assertEquals(bb.capacity(), bb.limit());
}
}
for (int off : validOffsets) {
for (int len : validLengths) {
if (off + len > pageSize) {
try {
seg.put(off, bb, len);
fail("should fail with an IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException | BufferUnderflowException ignored) {
}
try {
seg.get(off, bb, len);
fail("should fail with an IndexOutOfBoundsException");
} catch (IndexOutOfBoundsException | BufferOverflowException ignored) {
}
// position/limit may not have changed
assertEquals(0, bb.position());
assertEquals(bb.capacity(), bb.limit());
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of java.nio.BufferOverflowException in project bazel by bazelbuild.
the class DexFileAggregator method merge.
private Dex merge(Dex... dexes) throws IOException {
switch(dexes.length) {
case 0:
return new Dex(0);
case 1:
return dexes[0];
default:
try {
DexMerger dexMerger = new DexMerger(dexes, CollisionPolicy.FAIL);
dexMerger.setCompactWasteThreshold(wasteThresholdPerDex);
return dexMerger.merge();
} catch (BufferOverflowException e) {
// Bug in dx can cause this for ~1500 or more classes
Dex[] left = Arrays.copyOf(dexes, dexes.length / 2);
Dex[] right = Arrays.copyOfRange(dexes, left.length, dexes.length);
System.err.printf("Couldn't merge %d classes, trying %d%n", dexes.length, left.length);
try {
return merge(merge(left), merge(right));
} catch (RuntimeException e2) {
e2.addSuppressed(e);
throw e2;
}
}
}
}
Aggregations