#vulnerable code 
                                @Test
    public void testWrite_dataExceedingMinBufferSize() throws IOException {
        final File file = File.createTempFile("log4j2", "test");
        file.deleteOnExit();
        final RandomAccessFile raf = new RandomAccessFile(file, "rw");
        final OutputStream os = NullOutputStream.NULL_OUTPUT_STREAM;
        final int bufferSize = 1;
        final RandomAccessFileManager manager = new RandomAccessFileManager(raf, file.getName(), os,
                false, bufferSize, null, null);

        final int size = bufferSize * 3 + 1;
        final byte[] data = new byte[size];
        manager.write(data); // no exception
        assertEquals(bufferSize * 3, raf.length());

        manager.flush();
        assertEquals(size, raf.length()); // all data written to file now
    } 
                            #location 17 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                @Test
    public void testWrite_dataExceedingMinBufferSize() throws IOException {
        final File file = File.createTempFile("log4j2", "test");
        file.deleteOnExit();
        try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) {
            final OutputStream os = NullOutputStream.NULL_OUTPUT_STREAM;
            final int bufferSize = 1;
            final RandomAccessFileManager manager = new RandomAccessFileManager(raf, file.getName(), os, false,
                    bufferSize, null, null);

            final int size = bufferSize * 3 + 1;
            final byte[] data = new byte[size];
            manager.write(data); // no exception
            assertEquals(bufferSize * 3, raf.length());

            manager.flush();
            assertEquals(size, raf.length()); // all data written to file now
        }}