Example usage for java.lang OutOfMemoryError OutOfMemoryError

List of usage examples for java.lang OutOfMemoryError OutOfMemoryError

Introduction

In this page you can find the example usage for java.lang OutOfMemoryError OutOfMemoryError.

Prototype

public OutOfMemoryError(String s) 

Source Link

Document

Constructs an OutOfMemoryError with the specified detail message.

Usage

From source file:LZFInputStream.java

public static byte[] newBytes(int len) {
    try {//from  ww w  . j  a  va  2 s .com
        if (len == 0) {
            return EMPTY_BYTES;
        }
        return new byte[len];
    } catch (OutOfMemoryError e) {
        Error e2 = new OutOfMemoryError("Requested memory: " + len);
        e2.initCause(e);
        throw e2;
    }
}

From source file:net.bull.javamelody.SpringTestFacadeImpl.java

/**
 * {@inheritDoc}
 */
@Override
public void throwError() {
    throw new OutOfMemoryError("test");
}

From source file:org.terasoluna.gfw.web.exception.ExceptionLoggingFilterTest.java

@Test
public void testDoFilter_occur_error() throws IOException, ServletException {

    OutOfMemoryError occurError = new OutOfMemoryError("out of memory error.");

    doThrow(occurError).when(mockFilterChain).doFilter(mockRequest, mockResponse);

    try {/*from w  w w.jav  a2 s  . c  o  m*/
        testTarget.doFilter(mockRequest, mockResponse, mockFilterChain);
    } catch (OutOfMemoryError e) {
        assertSame(occurError, e);
    }

    verify(mockExceptionLogger, times(0)).log((Exception) any());

}

From source file:net.simon04.guavavfs.VirtualFiles.java

/**
 * Reads a file of the given expected size from the given input stream, if
 * it will fit into a byte array. This method handles the case where the file
 * size changes between when the size is read and when the contents are read
 * from the stream./*from  www.jav  a  2  s .co m*/
 */
static byte[] readFile(InputStream in, long expectedSize) throws IOException {
    if (expectedSize > Integer.MAX_VALUE) {
        throw new OutOfMemoryError("file is too large to fit in a byte array: " + expectedSize + " bytes");
    }

    return ByteStreams.toByteArray(in);
}

From source file:mitm.application.djigzo.james.mailets.QuarantineTest.java

@Test
public void testError() throws Exception {
    MimeMessage message = loadMessage("html-alternative.eml");

    MockMailetConfig mailetConfig = new MockMailetConfig();

    Quarantine mailet = new Quarantine();

    mailetConfig.setInitParameter("errorProcessor", "error");

    mailet.init(mailetConfig);/*  w w w . jav a 2 s .  c om*/

    // override the MailStorer with one that always fails
    mailet.setQuarantineMailStorer(new MailStorer() {
        @Override
        public void store(Mail mail) throws MessagingException, IOException {
            throw new OutOfMemoryError("Expected error");
        }
    });

    Mail mail = new MailImpl("test", new MailAddress("sender@example.com"),
            Arrays.asList(new MailAddress("test1@example.com"), new MailAddress("test2@example.com")), message);

    assertEquals("root", mail.getState());

    assertEquals(0, proxy.getItems().size());

    DjigzoMailAttributes attributes = new DjigzoMailAttributesImpl(mail);

    MimeMessage org = mail.getMessage();

    mailet.service(mail);

    assertTrue(org == mail.getMessage());

    List<? extends MailRepositoryItem> items = proxy.getItems();

    assertEquals(0, items.size());

    attributes = new DjigzoMailAttributesImpl(mail);

    assertNull(attributes.getMailRepositoryID());

    assertEquals("error", mail.getState());
    assertEquals(new MailAddress("sender@example.com"), mail.getSender());
    assertEquals("test1@example.com,test2@example.com", StringUtils.join(mail.getRecipients(), ","));
}

From source file:com.google.acre.script.HostEnv.java

@SuppressWarnings("null")
@JSFunction//www.  j a  va2  s. co  m
public String dev_test_internal(String name) {
    // the js entry point shouldn't be visible to user scripts
    // unless developer mode is enabled, but double-check it
    // here too.
    if (!ACRE_DEVELOPER_MODE) {
        return "";
    }

    if (name.equals("OutOfMemoryError")) {
        throw new OutOfMemoryError("this is an OutOfMemoryError message");
    }
    if (name.equals("StackOverflowError")) {
        throw new StackOverflowError("this is an StackOverflowError message");
    }
    if (name.equals("ThreadDeath")) {
        throw new ThreadDeath();
    }
    if (name.equals("RuntimeException")) {
        throw new RuntimeException("this is a RuntimeException message");
    }
    if (name.equals("Error")) {
        throw new Error("this is an Error message");
    }
    if (name.equals("AcreScriptError")) {
        throw new AcreScriptError("AcreScriptError - faked script was taking too long");
    }
    if (name.equals("NullPointerException")) {
        Object n = null;
        n.toString();
    }

    // not really "throw", so the different naming style is deliberate
    if (name.equals("java_infinite_loop")) {
        boolean a = true;
        while (a) {
        }
    }

    // quick-and-dirty reflecton of options to this function
    //  so they aren't duplicated in test code
    if (name.equals("list")) {
        return "OutOfMemoryError StackOverflowError ThreadDeath RuntimeException Error AcreScriptError NullPointerException java_infinite_loop";
    }

    // TODO add more options to test potential java failures
    //  log_spew   to try to overwhelm the log system
    // ...

    // if you add more cases, update the "list" case above too!

    return "";
}

From source file:org.apache.flink.runtime.io.network.bufferprovider.GlobalBufferPool.java

public GlobalBufferPool(int numBuffers, int bufferSize) {
    this.numBuffers = numBuffers;
    this.bufferSize = bufferSize;

    buffers = new ArrayBlockingQueue<MemorySegment>(numBuffers);

    final int mb = 1 << 20;
    final int memRequiredMb = (numBuffers * bufferSize) / mb;

    for (int i = 0; i < numBuffers; i++) {
        try {/*from w w  w  .j a v a  2  s. c o m*/
            byte[] buf = new byte[bufferSize];
            buffers.add(new MemorySegment(buf));
        } catch (OutOfMemoryError err) {
            int memAllocatedMb = ((i + 1) * bufferSize) / mb;

            String msg = String.format(
                    "Tried to allocate %d buffers of size %d bytes each (total: %d MB) "
                            + "and ran out of memory after %d buffers (%d MB).",
                    numBuffers, bufferSize, memRequiredMb, i + 1, memAllocatedMb);
            throw new OutOfMemoryError(msg);
        }
    }

    LOG.info(String.format("Allocated %d buffers of size %d bytes each (total: %d MB).", numBuffers, bufferSize,
            memRequiredMb));
}

From source file:org.apache.hadoop.ha.TestHealthMonitor.java

@Before
public void setupHM() throws InterruptedException, IOException {
    Configuration conf = new Configuration();
    conf.setInt(CommonConfigurationKeys.IPC_CLIENT_CONNECT_MAX_RETRIES_KEY, 1);
    conf.setInt(CommonConfigurationKeys.HA_HM_CHECK_INTERVAL_KEY, 50);
    conf.setInt(CommonConfigurationKeys.HA_HM_CONNECT_RETRY_INTERVAL_KEY, 50);
    conf.setInt(CommonConfigurationKeys.HA_HM_SLEEP_AFTER_DISCONNECT_KEY, 50);

    svc = createDummyHAService();//  w  w w . j  a  v a2  s.c  o m
    hm = new HealthMonitor(conf, svc) {
        @Override
        protected HAServiceProtocol createProxy() throws IOException {
            createProxyCount.incrementAndGet();
            if (throwOOMEOnCreate) {
                throw new OutOfMemoryError("oome");
            }
            return super.createProxy();
        }
    };
    LOG.info("Starting health monitor");
    hm.start();

    LOG.info("Waiting for HEALTHY signal");
    waitForState(hm, HealthMonitor.State.SERVICE_HEALTHY);
}

From source file:org.apache.hadoop.hive.llap.cache.BuddyAllocator.java

private ByteBuffer preallocateArenaBuffer(int arenaSize) {
    if (isMapped) {
        RandomAccessFile rwf = null;
        File rf = null;/* www. j av a 2  s.  c o m*/
        Preconditions.checkArgument(isDirect, "All memory mapped allocations have to be direct buffers");
        try {
            rf = File.createTempFile("arena-", ".cache", cacheDir.toFile());
            rwf = new RandomAccessFile(rf, "rw");
            rwf.setLength(arenaSize); // truncate (TODO: posix_fallocate?)
            // Use RW, not PRIVATE because the copy-on-write is irrelevant for a deleted file
            // see discussion in YARN-5551 for the memory accounting discussion
            ByteBuffer rwbuf = rwf.getChannel().map(MapMode.READ_WRITE, 0, arenaSize);
            return rwbuf;
        } catch (IOException ioe) {
            LlapIoImpl.LOG.warn("Failed trying to allocate memory mapped arena", ioe);
            // fail similarly when memory allocations fail
            throw new OutOfMemoryError("Failed trying to allocate memory mapped arena: " + ioe.getMessage());
        } finally {
            // A mapping, once established, is not dependent upon the file channel that was used to
            // create it. delete file and hold onto the map
            IOUtils.closeQuietly(rwf);
            if (rf != null) {
                rf.delete();
            }
        }
    }
    return isDirect ? ByteBuffer.allocateDirect(arenaSize) : ByteBuffer.allocate(arenaSize);
}

From source file:org.eclipse.dataset.ByteDataset.java

protected static byte[] createArray(final int size) { // PRIM_TYPE
    byte[] array = null; // PRIM_TYPE

    try {//w  w w  .  j a v  a 2 s  . c o  m
        array = new byte[size]; // PRIM_TYPE
    } catch (OutOfMemoryError e) {
        logger.error("The size of the dataset ({}) that is being created is too large "
                + "and there is not enough memory to hold it.", size);
        throw new OutOfMemoryError("The dimensions given are too large, and there is "
                + "not enough memory available in the Java Virtual Machine");
    }
    return array;
}