#fixed code
                                private static void manyLongToggles(@NotNull DirectStore store1, int lockCount, int from, int to) {
        long id = Thread.currentThread().getId();
        assertEquals(0, id >>> 32);
        System.out.println("Thread " + id);

        DirectBytes slice1 = store1.bytes();

        int records = 64;
        for (int i = 0; i < lockCount; i += records) {
            for (long j = 0; j < records * 64; j += 64) {
                slice1.positionAndSize(j, 64);
                boolean condition = false;
                for (int k = 0; k < 20; k++) {
                    condition = slice1.tryLockLong(0L) || slice1.tryLockNanosLong(0L, 5 * 1000 * 1000);
                    if (condition)
                        break;
                    if (k > 0)
                        System.out.println("k: " + (5 + k * 5));
                }
                if (!condition)
                    assertTrue("i= " + i, condition);
                long toggle1 = slice1.readLong(8);
                if (toggle1 == from) {
                    slice1.writeLong(8L, to);
                } else {
                    // noinspection AssignmentToForLoopParameter,AssignmentToForLoopParameter
                    i--;
                }
                slice1.unlockLong(0L);
                System.currentTimeMillis(); // small delay
            }
        }
    }
#vulnerable code 
                                private static void manyLongToggles(@NotNull DirectStore store1, int lockCount, int from, int to) {
        long id = Thread.currentThread().getId();
        assertEquals(0, id >>> 32);
        System.out.println("Thread " + id);

        DirectBytes slice1 = store1.createSlice();

        int records = 64;
        for (int i = 0; i < lockCount; i += records) {
            for (long j = 0; j < records * 64; j += 64) {
                slice1.positionAndSize(j, 64);
                boolean condition = false;
                for (int k = 0; k < 20; k++) {
                    condition = slice1.tryLockLong(0L) || slice1.tryLockNanosLong(0L, 5 * 1000 * 1000);
                    if (condition)
                        break;
                    if (k > 0)
                        System.out.println("k: " + (5 + k * 5));
                }
                if (!condition)
                    assertTrue("i= " + i, condition);
                long toggle1 = slice1.readLong(8);
                if (toggle1 == from) {
                    slice1.writeLong(8L, to);
                } else {
                    // noinspection AssignmentToForLoopParameter,AssignmentToForLoopParameter
                    i--;
                }
                slice1.unlockLong(0L);
                System.currentTimeMillis(); // small delay
            }
        }
    } 
                            #location 19 
                            #vulnerability type RESOURCE_LEAK