output
stringlengths 64
73.2k
| input
stringlengths 208
73.3k
| instruction
stringclasses 1
value |
---|---|---|
#fixed code
@Test
public void testUpdateAllWithParameterFourRuns() {
try (Database db = db()) {
db.update("update person set score=?") //
.parameters(1, 2, 3, 4) //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(3, 3, 3, 3) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateAllWithParameterFourRuns() {
db().update("update person set score=?") //
.parameters(1, 2, 3, 4) //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(3, 3, 3, 3) //
.assertComplete();
}
#location 4
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectTransactedChained() throws Exception {
try (Database db = db()) {
db //
.select("select score from person where name=?") //
.parameters("FRED", "JOSEPH") //
.transacted() //
.transactedValuesOnly() //
.getAs(Integer.class) //
.doOnNext(tx -> log
.debug(tx.isComplete() ? "complete" : String.valueOf(tx.value())))//
.flatMap(tx -> tx //
.select("select name from person where score = ?") //
.parameter(tx.value()) //
.valuesOnly() //
.getAs(String.class)) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoErrors() //
.assertValues("FRED", "JOSEPH") //
.assertComplete();
}
} | #vulnerable code
@Test
public void testSelectTransactedChained() throws Exception {
Database db = db();
db //
.select("select score from person where name=?") //
.parameters("FRED", "JOSEPH") //
.transacted() //
.transactedValuesOnly() //
.getAs(Integer.class) //
.doOnNext(
tx -> log.debug(tx.isComplete() ? "complete" : String.valueOf(tx.value())))//
.flatMap(tx -> tx //
.select("select name from person where score = ?") //
.parameter(tx.value()) //
.valuesOnly() //
.getAs(String.class)) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoErrors() //
.assertValues("FRED", "JOSEPH") //
.assertComplete();
}
#location 6
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectTransactedTuple4() {
try (Database db = db()) {
Tx<Tuple4<String, Integer, String, Integer>> t = db //
.select("select name, score, name, score from person where name=?") //
.parameters("FRED") //
.transacted() //
.getAs(String.class, Integer.class, String.class, Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(2) //
.assertComplete() //
.values().get(0);
assertEquals("FRED", t.value()._1());
assertEquals(21, (int) t.value()._2());
assertEquals("FRED", t.value()._3());
assertEquals(21, (int) t.value()._4());
}
} | #vulnerable code
@Test
public void testSelectTransactedTuple4() {
Tx<Tuple4<String, Integer, String, Integer>> t = db() //
.select("select name, score, name, score from person where name=?") //
.parameters("FRED") //
.transacted() //
.getAs(String.class, Integer.class, String.class, Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(2) //
.assertComplete() //
.values().get(0);
assertEquals("FRED", t.value()._1());
assertEquals(21, (int) t.value()._2());
assertEquals("FRED", t.value()._3());
assertEquals(21, (int) t.value()._4());
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectDependsOnCompletable() {
try (Database db = db()) {
Completable a = db.update("update person set score=100 where name=?") //
.parameter("FRED") //
.counts().ignoreElements();
db.select("select score from person where name=?") //
.parameter("FRED") //
.dependsOn(a) //
.getAs(Integer.class)//
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(100) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testSelectDependsOnCompletable() {
Database db = db();
Completable a = db.update("update person set score=100 where name=?") //
.parameter("FRED") //
.counts().ignoreElements();
db.select("select score from person where name=?") //
.parameter("FRED") //
.dependsOn(a) //
.getAs(Integer.class)//
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(100) //
.assertComplete();
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testFewerColumnsMappedThanAvailable() {
try (Database db = db()) {
db.select("select name, score from person where name='FRED'") //
.getAs(String.class) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues("FRED") //
.assertComplete();
}
} | #vulnerable code
@Test
public void testFewerColumnsMappedThanAvailable() {
db().select("select name, score from person where name='FRED'") //
.getAs(String.class) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues("FRED") //
.assertComplete();
}
#location 4
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public static Database test(int maxPoolSize) {
return Database.from( //
Pools.nonBlocking() //
.connectionProvider(testConnectionProvider()) //
.maxPoolSize(maxPoolSize) //
.build());
} | #vulnerable code
public static Database test(int maxPoolSize) {
return Database.from(new NonBlockingConnectionPool(testConnectionProvider(), maxPoolSize, 1000));
}
#location 2
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateWithParameterTwoRuns() {
try (Database db = db()) {
db.update("update person set score=20 where name=?") //
.parameters("FRED", "JOSEPH").counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(1, 1) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateWithParameterTwoRuns() {
db().update("update person set score=20 where name=?") //
.parameters("FRED", "JOSEPH").counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(1, 1) //
.assertComplete();
}
#location 4
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
@Ignore
// TODO fix test
public void testMaxIdleTime() throws InterruptedException {
TestScheduler s = new TestScheduler();
AtomicInteger count = new AtomicInteger();
AtomicInteger disposed = new AtomicInteger();
MemberFactory<Integer, NonBlockingPool<Integer>> memberFactory = pool -> new NonBlockingMember<Integer>(pool,
null);
Pool<Integer> pool = NonBlockingPool.factory(() -> count.incrementAndGet()) //
.healthy(n -> true) //
.disposer(n -> {
}) //
.maxSize(3) //
.maxIdleTime(1, TimeUnit.MINUTES) //
.returnToPoolDelayAfterHealthCheckFailure(1, TimeUnit.SECONDS) //
.disposer(n -> disposed.incrementAndGet()) //
.memberFactory(memberFactory) //
.scheduler(s) //
.build();
TestSubscriber<Member<Integer>> ts = pool //
.member() //
.repeat() //
.doOnNext(m -> m.checkin()) //
.doOnNext(System.out::println) //
.doOnRequest(t -> System.out.println("test request=" + t)) //
.test(1);
s.triggerActions();
ts.assertValueCount(1);
assertEquals(0, disposed.get());
s.advanceTimeBy(1, TimeUnit.MINUTES);
s.triggerActions();
assertEquals(1, disposed.get());
} | #vulnerable code
@Test
@Ignore
// TODO fix test
public void testMaxIdleTime() throws InterruptedException {
TestScheduler s = new TestScheduler();
AtomicInteger count = new AtomicInteger();
AtomicInteger disposed = new AtomicInteger();
MemberFactory2<Integer, NonBlockingPool2<Integer>> memberFactory = pool -> new NonBlockingMember2<Integer>(pool,
null);
Pool2<Integer> pool = NonBlockingPool2.factory(() -> count.incrementAndGet()) //
.healthy(n -> true) //
.disposer(n -> {
}) //
.maxSize(3) //
.maxIdleTime(1, TimeUnit.MINUTES) //
.returnToPoolDelayAfterHealthCheckFailure(1, TimeUnit.SECONDS) //
.disposer(n -> disposed.incrementAndGet()) //
.memberFactory(memberFactory) //
.scheduler(s) //
.build();
TestSubscriber<Member2<Integer>> ts = pool //
.member() //
.repeat() //
.doOnNext(m -> m.checkin()) //
.doOnNext(System.out::println) //
.doOnRequest(t -> System.out.println("test request=" + t)) //
.test(1);
s.triggerActions();
ts.assertValueCount(1);
assertEquals(0, disposed.get());
s.advanceTimeBy(1, TimeUnit.MINUTES);
s.triggerActions();
assertEquals(1, disposed.get());
}
#location 22
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
@Ignore
public void testCallableApi() {
Database db = DatabaseCreator.createDerbyWithStoredProcs(1);
db //
.call("call getPersonCount(?,?)") //
.in() //
.out(Type.INTEGER, Integer.class) //
.in(0, 10, 20) //
.build() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(2) //
.assertComplete();
} | #vulnerable code
@Test
@Ignore
public void testCallableApi() {
Database db = DatabaseCreator.createDerbyWithStoredProcs(1);
db //
.call("call getPersonCount(?,?)") //
.in() //
.out(Type.INTEGER, Integer.class) //
.build() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(2) //
.assertComplete();
}
#location 10
#vulnerability type NULL_DEREFERENCE | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectWithFetchSize() {
try (Database db = db()) {
db.select("select score from person order by name") //
.fetchSize(2) //
.getAs(Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoErrors() //
.assertValues(21, 34, 25) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testSelectWithFetchSize() {
db().select("select score from person order by name") //
.fetchSize(2) //
.getAs(Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoErrors() //
.assertValues(21, 34, 25) //
.assertComplete();
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectAutomappedTransactedValuesOnly() {
try (Database db = db()) {
db //
.select("select name, score from person") //
.transacted() //
.valuesOnly() //
.autoMap(Person2.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(3) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testSelectAutomappedTransactedValuesOnly() {
db() //
.select("select name, score from person") //
.transacted() //
.valuesOnly() //
.autoMap(Person2.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(3) //
.assertComplete();
}
#location 7
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectTransactedTuple5() {
try (Database db = db()) {
Tx<Tuple5<String, Integer, String, Integer, String>> t = db //
.select("select name, score, name, score, name from person where name=?") //
.parameters("FRED") //
.transacted() //
.getAs(String.class, Integer.class, String.class, Integer.class, String.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(2) //
.assertComplete() //
.values().get(0);
assertEquals("FRED", t.value()._1());
assertEquals(21, (int) t.value()._2());
assertEquals("FRED", t.value()._3());
assertEquals(21, (int) t.value()._4());
assertEquals("FRED", t.value()._5());
}
} | #vulnerable code
@Test
public void testSelectTransactedTuple5() {
Tx<Tuple5<String, Integer, String, Integer, String>> t = db() //
.select("select name, score, name, score, name from person where name=?") //
.parameters("FRED") //
.transacted() //
.getAs(String.class, Integer.class, String.class, Integer.class, String.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(2) //
.assertComplete() //
.values().get(0);
assertEquals("FRED", t.value()._1());
assertEquals(21, (int) t.value()._2());
assertEquals("FRED", t.value()._3());
assertEquals(21, (int) t.value()._4());
assertEquals("FRED", t.value()._5());
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateClobWithReader() throws FileNotFoundException {
try (Database db = db()) {
Reader reader = new FileReader(new File("src/test/resources/big.txt"));
insertNullClob(db);
db //
.update("update person_clob set document = :doc") //
.parameter("doc", reader) //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateClobWithReader() throws FileNotFoundException {
Database db = db();
Reader reader = new FileReader(new File("src/test/resources/big.txt"));
insertNullClob(db);
db //
.update("update person_clob set document = :doc") //
.parameter("doc", reader) //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
}
#location 9
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testInsertBlobAndReadBlobAsInputStream() {
try (Database db = db()) {
byte[] bytes = "some text here".getBytes();
db.update("insert into person_blob(name,document) values(?,?)") //
.parameters("FRED", new ByteArrayInputStream(bytes)) //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
db.select("select document from person_blob where name='FRED'") //
.getAs(InputStream.class) //
.map(is -> read(is)) //
.map(b -> new String(b)) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue("some text here") //
.assertComplete();
}
} | #vulnerable code
@Test
public void testInsertBlobAndReadBlobAsInputStream() {
Database db = db();
byte[] bytes = "some text here".getBytes();
db.update("insert into person_blob(name,document) values(?,?)") //
.parameters("FRED", new ByteArrayInputStream(bytes)) //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
db.select("select document from person_blob where name='FRED'") //
.getAs(InputStream.class) //
.map(is -> read(is)) //
.map(b -> new String(b)) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue("some text here") //
.assertComplete();
}
#location 12
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateWithBatchSize3GreaterThanNumRecords() {
try (Database db = db()) {
db.update("update person set score=?") //
.batchSize(3) //
.parameters(1, 2, 3, 4) //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(3, 3, 3, 3) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateWithBatchSize3GreaterThanNumRecords() {
db().update("update person set score=?") //
.batchSize(3) //
.parameters(1, 2, 3, 4) //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(3, 3, 3, 3) //
.assertComplete();
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testTuple3() {
try (Database db = db()) {
db //
.select("select name, score, name from person order by name") //
.getAs(String.class, Integer.class, String.class) //
.firstOrError() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertComplete() //
.assertValue(Tuple3.create("FRED", 21, "FRED")); //
}
} | #vulnerable code
@Test
public void testTuple3() {
db() //
.select("select name, score, name from person order by name") //
.getAs(String.class, Integer.class, String.class) //
.firstOrError() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertComplete() //
.assertValue(Tuple3.create("FRED", 21, "FRED")); //
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testAutoMapToInterfaceWithIndexTooLarge() {
try (Database db = db()) {
db //
.select("select name, score from person order by name") //
.autoMap(Person6.class) //
.firstOrError() //
.map(Person6::examScore) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoValues() //
.assertError(ColumnIndexOutOfRangeException.class);
}
} | #vulnerable code
@Test
public void testAutoMapToInterfaceWithIndexTooLarge() {
db() //
.select("select name, score from person order by name") //
.autoMap(Person6.class) //
.firstOrError() //
.map(Person6::examScore) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoValues() //
.assertError(ColumnIndexOutOfRangeException.class);
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectUsingNamedParameterList() {
try (Database db = db()) {
db.select("select score from person where name=:name") //
.parameters(Parameter.named("name", "FRED").value("JOSEPH").list()) //
.getAs(Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoErrors() //
.assertValues(21, 34) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testSelectUsingNamedParameterList() {
db().select("select score from person where name=:name") //
.parameters(Parameter.named("name", "FRED").value("JOSEPH").list()) //
.getAs(Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoErrors() //
.assertValues(21, 34) //
.assertComplete();
}
#location 4
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateBlobWithNull() {
try (Database db = db()) {
insertPersonBlob(db);
db //
.update("update person_blob set document = :doc") //
.parameter("doc", Database.NULL_BLOB) //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateBlobWithNull() {
Database db = db();
insertPersonBlob(db);
db //
.update("update person_blob set document = :doc") //
.parameter("doc", Database.NULL_BLOB) //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
}
#location 8
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testComplete() throws InterruptedException {
try (Database db = db(1)) {
Completable a = db //
.update("update person set score=-3 where name='FRED'") //
.complete();
db.update("update person set score=-4 where score = -3") //
.dependsOn(a) //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testComplete() throws InterruptedException {
Database db = db(1);
Completable a = db //
.update("update person set score=-3 where name='FRED'") //
.complete();
db.update("update person set score=-4 where score = -3") //
.dependsOn(a) //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
}
#location 8
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectTransactedTupleN() {
try (Database db = db()) {
List<Tx<TupleN<Object>>> list = db //
.select("select name, score from person where name=?") //
.parameters("FRED") //
.transacted() //
.getTupleN() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(2) //
.assertComplete() //
.values();
assertEquals("FRED", list.get(0).value().values().get(0));
assertEquals(21, (int) list.get(0).value().values().get(1));
assertTrue(list.get(1).isComplete());
assertEquals(2, list.size());
}
} | #vulnerable code
@Test
public void testSelectTransactedTupleN() {
List<Tx<TupleN<Object>>> list = db() //
.select("select name, score from person where name=?") //
.parameters("FRED") //
.transacted() //
.getTupleN() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(2) //
.assertComplete() //
.values();
assertEquals("FRED", list.get(0).value().values().get(0));
assertEquals(21, (int) list.get(0).value().values().get(1));
assertTrue(list.get(1).isComplete());
assertEquals(2, list.size());
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testMoreColumnsMappedThanAvailable() {
try (Database db = db()) {
db //
.select("select name, score from person where name='FRED'") //
.getAs(String.class, Integer.class, String.class) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoValues() //
.assertError(MoreColumnsRequestedThanExistException.class);
}
} | #vulnerable code
@Test
public void testMoreColumnsMappedThanAvailable() {
db() //
.select("select name, score from person where name='FRED'") //
.getAs(String.class, Integer.class, String.class) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoValues() //
.assertError(MoreColumnsRequestedThanExistException.class);
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testTuple6() {
try (Database db = db()) {
db //
.select("select name, score, name, score, name, score from person order by name") //
.getAs(String.class, Integer.class, String.class, Integer.class, String.class,
Integer.class) //
.firstOrError() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertComplete()
.assertValue(Tuple6.create("FRED", 21, "FRED", 21, "FRED", 21)); //
}
} | #vulnerable code
@Test
public void testTuple6() {
db() //
.select("select name, score, name, score, name, score from person order by name") //
.getAs(String.class, Integer.class, String.class, Integer.class, String.class,
Integer.class) //
.firstOrError() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertComplete().assertValue(Tuple6.create("FRED", 21, "FRED", 21, "FRED", 21)); //
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
@SuppressFBWarnings
public void testTupleSupport() {
try (Database db = db()) {
db.select("select name, score from person") //
.getAs(String.class, Integer.class) //
.forEach(System.out::println);
}
} | #vulnerable code
@Test
@SuppressFBWarnings
public void testTupleSupport() {
db().select("select name, score from person") //
.getAs(String.class, Integer.class) //
.forEach(System.out::println);
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testCountsOnlyInTransaction() {
try (Database db = db()) {
db.update("update person set score = -3") //
.transacted() //
.countsOnly() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(3) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testCountsOnlyInTransaction() {
db().update("update person set score = -3") //
.transacted() //
.countsOnly() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(3) //
.assertComplete();
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectUsingName() {
try (Database db = db()) {
db //
.select("select score from person where name=:name") //
.parameter("name", "FRED") //
.parameter("name", "JOSEPH") //
.getAs(Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(21, 34) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testSelectUsingName() {
db() //
.select("select score from person where name=:name") //
.parameter("name", "FRED") //
.parameter("name", "JOSEPH") //
.getAs(Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(21, 34) //
.assertComplete();
}
#location 7
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testAutoMapWithUnmappableColumnType() {
try (Database db = db()) {
db //
.select("select name from person order by name") //
.autoMap(Person8.class) //
.map(p -> p.name()) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoValues() //
.assertError(ClassCastException.class);
}
} | #vulnerable code
@Test
public void testAutoMapWithUnmappableColumnType() {
db() //
.select("select name from person order by name") //
.autoMap(Person8.class) //
.map(p -> p.name()) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoValues() //
.assertError(ClassCastException.class);
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testInsertNullClobAndReadClobAsString() {
try (Database db = db()) {
insertNullClob(db);
db.select("select document from person_clob where name='FRED'") //
.getAsOptional(String.class) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(Optional.<String>empty()) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testInsertNullClobAndReadClobAsString() {
Database db = db();
insertNullClob(db);
db.select("select document from person_clob where name='FRED'") //
.getAsOptional(String.class) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(Optional.<String>empty()) //
.assertComplete();
}
#location 6
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateOneRow() {
try (Database db = db()) {
db.update("update person set score=20 where name='FRED'") //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateOneRow() {
db().update("update person set score=20 where name='FRED'") //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
}
#location 4
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testReleasedMemberIsRecreated() throws Exception {
TestScheduler s = new TestScheduler();
AtomicInteger count = new AtomicInteger();
AtomicInteger disposed = new AtomicInteger();
Pool<Integer> pool = NonBlockingPool //
.factory(() -> count.incrementAndGet()) //
.healthy(n -> true) //
.disposer(Consumers.doNothing()) //
.maxSize(1) //
.maxIdleTime(1, TimeUnit.MINUTES) //
.returnToPoolDelayAfterHealthCheckFailure(1, TimeUnit.SECONDS) //
.disposer(n -> disposed.incrementAndGet()) //
.scheduler(s) //
.build();
{
TestSubscriber<Member<Integer>> ts = pool //
.member() //
.repeat() //
.doOnNext(m -> m.checkin()) //
.doOnNext(System.out::println) //
.doOnRequest(t -> System.out.println("test request=" + t)) //
.test(1);
s.triggerActions();
ts.assertValueCount(1);
assertEquals(0, disposed.get());
s.advanceTimeBy(1, TimeUnit.MINUTES);
s.triggerActions();
assertEquals(1, disposed.get());
ts.cancel();
assertEquals(1, disposed.get());
}
{
TestSubscriber<Member<Integer>> ts = pool //
.member() //
.repeat() //
.doOnNext(m -> m.checkin()) //
.doOnNext(System.out::println) //
.doOnRequest(t -> System.out.println("test request=" + t)) //
.test(1);
s.triggerActions();
ts.assertValueCount(1);
assertEquals(1, disposed.get());
s.advanceTimeBy(1, TimeUnit.MINUTES);
s.triggerActions();
assertEquals(2, disposed.get());
}
{
TestSubscriber<Member<Integer>> ts = pool //
.member() //
.repeat() //
.doOnNext(m -> m.checkin()) //
.doOnNext(System.out::println) //
.doOnRequest(t -> System.out.println("test request=" + t)) //
.test(1);
s.triggerActions();
ts.assertValueCount(1);
assertEquals(2, disposed.get());
}
pool.close();
assertEquals(3, disposed.get());
} | #vulnerable code
@Test
public void testReleasedMemberIsRecreated() throws InterruptedException {
TestScheduler s = new TestScheduler();
AtomicInteger count = new AtomicInteger();
AtomicInteger disposed = new AtomicInteger();
Pool<Integer> pool = NonBlockingPool //
.factory(() -> count.incrementAndGet()) //
.healthy(n -> true) //
.disposer(Consumers.doNothing()) //
.maxSize(1) //
.maxIdleTime(1, TimeUnit.MINUTES) //
.returnToPoolDelayAfterHealthCheckFailure(1, TimeUnit.SECONDS) //
.disposer(n -> disposed.incrementAndGet()) //
.scheduler(s) //
.build();
{
TestSubscriber<Member<Integer>> ts = pool //
.member() //
.repeat() //
.doOnNext(m -> m.checkin()) //
.doOnNext(System.out::println) //
.doOnRequest(t -> System.out.println("test request=" + t)) //
.test(1);
s.triggerActions();
ts.assertValueCount(1);
assertEquals(0, disposed.get());
s.advanceTimeBy(1, TimeUnit.MINUTES);
s.triggerActions();
assertEquals(1, disposed.get());
ts.cancel();
assertEquals(1, disposed.get());
}
{
TestSubscriber<Member<Integer>> ts = pool //
.member() //
.repeat() //
.doOnNext(m -> m.checkin()) //
.doOnNext(System.out::println) //
.doOnRequest(t -> System.out.println("test request=" + t)) //
.test(1);
s.triggerActions();
ts.assertValueCount(1);
assertEquals(1, disposed.get());
s.advanceTimeBy(1, TimeUnit.MINUTES);
s.triggerActions();
assertEquals(2, disposed.get());
}
}
#location 18
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectTimestampAsDate() {
try (Database db = db()) {
db //
.select("select registered from person where name='FRED'") //
.getAs(Date.class) //
.map(d -> d.getTime()) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(FRED_REGISTERED_TIME) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testSelectTimestampAsDate() {
db() //
.select("select registered from person where name='FRED'") //
.getAs(Date.class) //
.map(d -> d.getTime()) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(FRED_REGISTERED_TIME) //
.assertComplete();
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectTimestampAsInstant() {
try (Database db = db()) {
db //
.select("select registered from person where name='FRED'") //
.getAs(Instant.class) //
.map(d -> d.toEpochMilli()) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(FRED_REGISTERED_TIME) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testSelectTimestampAsInstant() {
db() //
.select("select registered from person where name='FRED'") //
.getAs(Instant.class) //
.map(d -> d.toEpochMilli()) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(FRED_REGISTERED_TIME) //
.assertComplete();
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectTransactedTuple6() {
try (Database db = db()) {
Tx<Tuple6<String, Integer, String, Integer, String, Integer>> t = db //
.select("select name, score, name, score, name, score from person where name=?") //
.parameters("FRED") //
.transacted() //
.getAs(String.class, Integer.class, String.class, Integer.class, String.class,
Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(2) //
.assertComplete() //
.values().get(0);
assertEquals("FRED", t.value()._1());
assertEquals(21, (int) t.value()._2());
assertEquals("FRED", t.value()._3());
assertEquals(21, (int) t.value()._4());
assertEquals("FRED", t.value()._5());
assertEquals(21, (int) t.value()._6());
}
} | #vulnerable code
@Test
public void testSelectTransactedTuple6() {
Tx<Tuple6<String, Integer, String, Integer, String, Integer>> t = db() //
.select("select name, score, name, score, name, score from person where name=?") //
.parameters("FRED") //
.transacted() //
.getAs(String.class, Integer.class, String.class, Integer.class, String.class,
Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(2) //
.assertComplete() //
.values().get(0);
assertEquals("FRED", t.value()._1());
assertEquals(21, (int) t.value()._2());
assertEquals("FRED", t.value()._3());
assertEquals(21, (int) t.value()._4());
assertEquals("FRED", t.value()._5());
assertEquals(21, (int) t.value()._6());
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testTransactedReturnGeneratedKeys() {
try (Database db = db()) {
// note is a table with auto increment
db.update("insert into note(text) values(?)") //
.parameters("HI", "THERE") //
.transacted() //
.returnGeneratedKeys() //
.valuesOnly() //
.getAs(Integer.class)//
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(1, 2) //
.assertComplete();
db.update("insert into note(text) values(?)") //
.parameters("ME", "TOO") //
.transacted() //
.returnGeneratedKeys() //
.valuesOnly() //
.getAs(Integer.class)//
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(3, 4) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testTransactedReturnGeneratedKeys() {
Database db = db();
// note is a table with auto increment
db.update("insert into note(text) values(?)") //
.parameters("HI", "THERE") //
.transacted() //
.returnGeneratedKeys() //
.valuesOnly() //
.getAs(Integer.class)//
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(1, 2) //
.assertComplete();
db.update("insert into note(text) values(?)") //
.parameters("ME", "TOO") //
.transacted() //
.returnGeneratedKeys() //
.valuesOnly() //
.getAs(Integer.class)//
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(3, 4) //
.assertComplete();
}
#location 17
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testReturnGeneratedKeys() {
try (Database db = db()) {
// note is a table with auto increment
db.update("insert into note(text) values(?)") //
.parameters("HI", "THERE") //
.returnGeneratedKeys() //
.getAs(Integer.class)//
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(1, 2) //
.assertComplete();
db.update("insert into note(text) values(?)") //
.parameters("ME", "TOO") //
.returnGeneratedKeys() //
.getAs(Integer.class)//
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(3, 4) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testReturnGeneratedKeys() {
Database db = db();
// note is a table with auto increment
db.update("insert into note(text) values(?)") //
.parameters("HI", "THERE") //
.returnGeneratedKeys() //
.getAs(Integer.class)//
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(1, 2) //
.assertComplete();
db.update("insert into note(text) values(?)") //
.parameters("ME", "TOO") //
.returnGeneratedKeys() //
.getAs(Integer.class)//
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(3, 4) //
.assertComplete();
}
#location 15
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectDependsOnObservable() {
try (Database db = db()) {
Observable<Integer> a = db.update("update person set score=100 where name=?") //
.parameter("FRED") //
.counts().toObservable();
db.select("select score from person where name=?") //
.parameter("FRED") //
.dependsOn(a) //
.getAs(Integer.class)//
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(100) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testSelectDependsOnObservable() {
Database db = db();
Observable<Integer> a = db.update("update person set score=100 where name=?") //
.parameter("FRED") //
.counts().toObservable();
db.select("select score from person where name=?") //
.parameter("FRED") //
.dependsOn(a) //
.getAs(Integer.class)//
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(100) //
.assertComplete();
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testTuple5() {
try (Database db = db()) {
db //
.select("select name, score, name, score, name from person order by name") //
.getAs(String.class, Integer.class, String.class, Integer.class, String.class) //
.firstOrError() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertComplete().assertValue(Tuple5.create("FRED", 21, "FRED", 21, "FRED")); //
}
} | #vulnerable code
@Test
public void testTuple5() {
db() //
.select("select name, score, name, score, name from person order by name") //
.getAs(String.class, Integer.class, String.class, Integer.class, String.class) //
.firstOrError() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertComplete().assertValue(Tuple5.create("FRED", 21, "FRED", 21, "FRED")); //
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testInsert() {
try (Database db = db()) {
db.update("insert into person(name, score) values(?,?)") //
.parameters("DAVE", 12, "ANNE", 18) //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(1, 1) //
.assertComplete();
List<Tuple2<String, Integer>> list = db.select("select name, score from person") //
.getAs(String.class, Integer.class) //
.toList() //
.timeout(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.blockingGet();
assertTrue(list.contains(Tuple2.create("DAVE", 12)));
assertTrue(list.contains(Tuple2.create("ANNE", 18)));
}
} | #vulnerable code
@Test
public void testInsert() {
Database db = db();
db.update("insert into person(name, score) values(?,?)") //
.parameters("DAVE", 12, "ANNE", 18) //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(1, 1) //
.assertComplete();
List<Tuple2<String, Integer>> list = db.select("select name, score from person") //
.getAs(String.class, Integer.class) //
.toList() //
.timeout(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.blockingGet();
assertTrue(list.contains(Tuple2.create("DAVE", 12)));
assertTrue(list.contains(Tuple2.create("ANNE", 18)));
}
#location 11
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testDrivingSelectWithoutParametersUsingParameterStream() {
try (Database db = db()) {
db.select("select count(*) from person") //
.parameters(1, 2, 3) //
.getAs(Integer.class) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(3, 3, 3) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testDrivingSelectWithoutParametersUsingParameterStream() {
db().select("select count(*) from person") //
.parameters(1, 2, 3) //
.getAs(Integer.class) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(3, 3, 3) //
.assertComplete();
}
#location 4
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSimplePool() throws InterruptedException {
TestScheduler s = new TestScheduler();
AtomicInteger count = new AtomicInteger();
MemberFactory<Integer, NonBlockingPool<Integer>> memberFactory = pool -> new NonBlockingMember<Integer>(pool,
null);
Pool<Integer> pool = NonBlockingPool.factory(() -> count.incrementAndGet()) //
.healthy(n -> true) //
.disposer(n -> {
}) //
.maxSize(3) //
.returnToPoolDelayAfterHealthCheckFailureMs(1000) //
.memberFactory(memberFactory) //
.scheduler(s) //
.build();
TestObserver<Member<Integer>> ts = pool.member() //
.doOnSuccess(m -> m.checkin()) //
.test();
s.triggerActions();
ts.assertValueCount(1) //
.assertComplete();
} | #vulnerable code
@Test
public void testSimplePool() throws InterruptedException {
TestScheduler s = new TestScheduler();
AtomicInteger count = new AtomicInteger();
MemberFactory2<Integer, NonBlockingPool2<Integer>> memberFactory = pool -> new NonBlockingMember2<Integer>(pool,
null);
Pool2<Integer> pool = NonBlockingPool2.factory(() -> count.incrementAndGet()) //
.healthy(n -> true) //
.disposer(n -> {
}) //
.maxSize(3) //
.returnToPoolDelayAfterHealthCheckFailureMs(1000) //
.memberFactory(memberFactory) //
.scheduler(s) //
.build();
TestObserver<Member2<Integer>> ts = pool.member() //
.doOnSuccess(m -> m.checkin()) //
.test();
s.triggerActions();
ts.assertValueCount(1) //
.assertComplete();
}
#location 16
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateWithinTransactionBatchSize0() {
try (Database db = db()) {
db //
.select("select name from person") //
.transactedValuesOnly() //
.getAs(String.class) //
.doOnNext(System.out::println) //
.flatMap(tx -> tx//
.update("update person set score=-1 where name=:name") //
.batchSize(0) //
.parameter("name", tx.value()) //
.valuesOnly() //
.counts()) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(1, 1, 1) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateWithinTransactionBatchSize0() {
db() //
.select("select name from person") //
.transactedValuesOnly() //
.getAs(String.class) //
.doOnNext(System.out::println) //
.flatMap(tx -> tx//
.update("update person set score=-1 where name=:name") //
.batchSize(0) //
.parameter("name", tx.value()) //
.valuesOnly() //
.counts()) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(1, 1, 1) //
.assertComplete();
}
#location 6
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateWithBatchSize2() {
try (Database db = db()) {
db.update("update person set score=?") //
.batchSize(2) //
.parameters(1, 2, 3, 4) //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(3, 3, 3, 3) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateWithBatchSize2() {
db().update("update person set score=?") //
.batchSize(2) //
.parameters(1, 2, 3, 4) //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(3, 3, 3, 3) //
.assertComplete();
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testCallableApiNoParameters() {
Database db = DatabaseCreator.createDerbyWithStoredProcs(1);
db //
.call("call zero()") //
.once() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertComplete();
} | #vulnerable code
@Test
public void testCallableApiNoParameters() {
Database db = DatabaseCreator.createDerbyWithStoredProcs(1);
db //
.call("call zero()") //
.once().test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertComplete();
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectTimestamp() {
try (Database db = db()) {
db //
.select("select registered from person where name='FRED'") //
.getAs(Long.class) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(FRED_REGISTERED_TIME) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testSelectTimestamp() {
db() //
.select("select registered from person where name='FRED'") //
.getAs(Long.class) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(FRED_REGISTERED_TIME) //
.assertComplete();
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test(expected = IllegalArgumentException.class)
public void testSelectUsingNameWithoutSpecifyingNameThrowsImmediately() {
try (Database db = db()) {
db //
.select("select score from person where name=:name") //
.parameters("FRED", "JOSEPH");
}
} | #vulnerable code
@Test(expected = IllegalArgumentException.class)
public void testSelectUsingNameWithoutSpecifyingNameThrowsImmediately() {
db() //
.select("select score from person where name=:name") //
.parameters("FRED", "JOSEPH");
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testAutoMapToInterfaceWithIndexTooSmall() {
try (Database db = db()) {
db //
.select("select name, score from person order by name") //
.autoMap(Person7.class) //
.firstOrError() //
.map(Person7::examScore) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoValues() //
.assertError(ColumnIndexOutOfRangeException.class);
}
} | #vulnerable code
@Test
public void testAutoMapToInterfaceWithIndexTooSmall() {
db() //
.select("select name, score from person order by name") //
.autoMap(Person7.class) //
.firstOrError() //
.map(Person7::examScore) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoValues() //
.assertError(ColumnIndexOutOfRangeException.class);
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateTimestampAsInstant() {
try (Database db = db()) {
db.update("update person set registered=? where name='FRED'") //
.parameter(Instant.ofEpochMilli(FRED_REGISTERED_TIME)) //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
db.select("select registered from person where name='FRED'") //
.getAs(Long.class) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(FRED_REGISTERED_TIME) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateTimestampAsInstant() {
Database db = db();
db.update("update person set registered=? where name='FRED'") //
.parameter(Instant.ofEpochMilli(FRED_REGISTERED_TIME)) //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
db.select("select registered from person where name='FRED'") //
.getAs(Long.class) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(FRED_REGISTERED_TIME) //
.assertComplete();
}
#location 11
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testConnectionPoolRecylesAlternating() {
TestScheduler s = new TestScheduler();
AtomicInteger count = new AtomicInteger();
Pool<Integer> pool = NonBlockingPool //
.factory(() -> count.incrementAndGet()) //
.healthCheck(n -> true) //
.maxSize(2) //
.maxIdleTime(1, TimeUnit.MINUTES) //
.scheduler(s) //
.build();
TestSubscriber<Integer> ts = new FlowableSingleDeferUntilRequest<>(pool.member()) //
.repeat() //
.doOnNext(m -> m.checkin()) //
.map(m -> m.value()) //
.test(4); //
s.triggerActions();
ts.assertValueCount(4) //
.assertNotTerminated();
List<Object> list = ts.getEvents().get(0);
// all 4 connections released were the same
assertTrue(list.get(0) == list.get(1));
assertTrue(list.get(1) == list.get(2));
assertTrue(list.get(2) == list.get(3));
} | #vulnerable code
@Test
public void testConnectionPoolRecylesAlternating() {
TestScheduler s = new TestScheduler();
Database db = DatabaseCreator.create(2, s);
TestSubscriber<Connection> ts = db.connections() //
.doOnNext(System.out::println) //
.doOnNext(c -> {
// release connection for reuse straight away
c.close();
}) //
.test(4); //
s.triggerActions();
ts.assertValueCount(4) //
.assertNotTerminated();
List<Object> list = ts.getEvents().get(0);
// all 4 connections released were the same
System.out.println(list);
assertTrue(list.get(0).hashCode() == list.get(1).hashCode());
assertTrue(list.get(1).hashCode() == list.get(2).hashCode());
assertTrue(list.get(2).hashCode() == list.get(3).hashCode());
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateTxPerformed() {
Database db = db(1);
db.update("update person set score = 1000") //
.transacted() //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertComplete() //
.assertValueCount(2); // value and complete
db.select("select count(*) from person where score=1000") //
.getAs(Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertComplete() //
.assertValue(3);
} | #vulnerable code
@Test
public void testUpdateTxPerformed() {
Database db = db();
db.update("update person set score = 1000") //
.transacted() //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertComplete() //
.assertValueCount(2); //value and complete
db.select("select count(*) from person where score=1000") //
.getAs(Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertComplete() //
.assertValue(3);
}
#location 13
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public static Database create(int maxSize, boolean big, Scheduler scheduler) {
NonBlockingConnectionPool pool = Pools.nonBlocking() //
.connectionProvider(connectionProvider(nextUrl(), big)) //
.maxPoolSize(maxSize) //
.scheduler(scheduler) //
.build();
return Database.from(pool, () -> {
pool.close();
scheduler.shutdown();
});
} | #vulnerable code
public static Database create(int maxSize, boolean big, Scheduler scheduler) {
return Database.from(Pools.nonBlocking() //
.connectionProvider(connectionProvider(nextUrl(), big)) //
.maxPoolSize(maxSize) //
.scheduler(scheduler) //
.build(), () -> scheduler.shutdown());
}
#location 2
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateBlobWithBlob() throws SQLException {
try (Database db = db()) {
Blob blob = new JDBCBlobFile(new File("src/test/resources/big.txt"));
insertPersonBlob(db);
db //
.update("update person_blob set document = :doc") //
.parameter("doc", blob) //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateBlobWithBlob() throws SQLException {
Database db = db();
Blob blob = new JDBCBlobFile(new File("src/test/resources/big.txt"));
insertPersonBlob(db);
db //
.update("update person_blob set document = :doc") //
.parameter("doc", blob) //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
}
#location 9
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectTransactedTuple3() {
try (Database db = db()) {
Tx<Tuple3<String, Integer, String>> t = db //
.select("select name, score, name from person where name=?") //
.parameters("FRED") //
.transacted() //
.getAs(String.class, Integer.class, String.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(2) //
.assertComplete() //
.values().get(0);
assertEquals("FRED", t.value()._1());
assertEquals(21, (int) t.value()._2());
assertEquals("FRED", t.value()._3());
}
} | #vulnerable code
@Test
public void testSelectTransactedTuple3() {
Tx<Tuple3<String, Integer, String>> t = db() //
.select("select name, score, name from person where name=?") //
.parameters("FRED") //
.transacted() //
.getAs(String.class, Integer.class, String.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(2) //
.assertComplete() //
.values().get(0);
assertEquals("FRED", t.value()._1());
assertEquals(21, (int) t.value()._2());
assertEquals("FRED", t.value()._3());
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testHealthCheck() throws InterruptedException {
AtomicBoolean once = new AtomicBoolean(true);
testHealthCheck(c -> {
log.debug("doing health check");
return !once.compareAndSet(true, false);
});
} | #vulnerable code
@Test
public void testHealthCheck() throws InterruptedException {
TestScheduler scheduler = new TestScheduler();
AtomicBoolean once = new AtomicBoolean(true);
NonBlockingConnectionPool pool = Pools //
.nonBlocking() //
.connectionProvider(DatabaseCreator.connectionProvider()) //
.maxIdleTime(10, TimeUnit.MINUTES) //
.idleTimeBeforeHealthCheck(0, TimeUnit.MINUTES) //
.healthy(c -> {
log.debug("doing health check");
return !once.compareAndSet(true, false);
}) //
.returnToPoolDelayAfterHealthCheckFailure(1, TimeUnit.MINUTES) //
.scheduler(scheduler) //
.maxPoolSize(1) //
.build();
try (Database db = Database.from(pool)) {
db.select( //
"select score from person where name=?") //
.parameters("FRED") //
.getAs(Integer.class) //
.test() //
.assertValueCount(1) //
.assertComplete();
TestSubscriber<Integer> ts = db
.select( //
"select score from person where name=?") //
.parameters("FRED") //
.getAs(Integer.class) //
.test() //
.assertValueCount(0);
scheduler.advanceTimeBy(1, TimeUnit.MINUTES);
Thread.sleep(200);
ts.assertValueCount(1);
Thread.sleep(200);
ts.assertValue(21) //
.assertComplete();
}
}
#location 19
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateTimestampParameter() {
try (Database db = db()) {
Timestamp t = new Timestamp(1234);
db.update("update person set registered=?") //
.parameter(t) //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(3) //
.assertComplete();
db.select("select registered from person") //
.getAs(Long.class) //
.firstOrError() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1234L) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateTimestampParameter() {
Database db = db();
Timestamp t = new Timestamp(1234);
db.update("update person set registered=?") //
.parameter(t) //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(3) //
.assertComplete();
db.select("select registered from person") //
.getAs(Long.class) //
.firstOrError() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1234L) //
.assertComplete();
}
#location 13
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test(expected = IllegalArgumentException.class)
public void testSelectWithFetchSizeNegative() {
try (Database db = db()) {
db.select("select score from person order by name") //
.fetchSize(-1);
}
} | #vulnerable code
@Test(expected = IllegalArgumentException.class)
public void testSelectWithFetchSizeNegative() {
db().select("select score from person order by name") //
.fetchSize(-1);
}
#location 4
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectUsingQuestionMark() {
try (Database db = db()) {
db.select("select score from person where name=?") //
.parameters("FRED", "JOSEPH") //
.getAs(Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoErrors() //
.assertValues(21, 34) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testSelectUsingQuestionMark() {
db().select("select score from person where name=?") //
.parameters("FRED", "JOSEPH") //
.getAs(Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoErrors() //
.assertValues(21, 34) //
.assertComplete();
}
#location 4
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testCallableStatementReturningResultSets() {
Database db = DatabaseCreator.createDerbyWithStoredProcs(1);
db.apply(con -> {
try (Statement stmt = con.createStatement()) {
CallableStatement st = con.prepareCall("call returnResultSets(?)");
st.setInt(1, 0);
boolean hasResultSets = st.execute();
if (hasResultSets) {
ResultSet rs1 = st.getResultSet();
st.getMoreResults(Statement.KEEP_CURRENT_RESULT);
ResultSet rs2 = st.getResultSet();
rs1.next();
assertEquals("FRED", rs1.getString(1));
rs2.next();
assertEquals("SARAH", rs2.getString(1));
}
}
}).blockingAwait(TIMEOUT_SECONDS, TimeUnit.SECONDS);
} | #vulnerable code
@Test
public void testCallableStatementReturningResultSets() {
Database db = DatabaseCreator.createDerby(1);
db.apply(con -> {
try (Statement stmt = con.createStatement()) {
stmt.execute(
"create table app.person (name varchar(50) primary key, score int not null)");
stmt.execute("insert into app.person(name, score) values('FRED', 24)");
stmt.execute("insert into app.person(name, score) values('SARAH', 26)");
stmt.execute(
"call sqlj.install_jar('target/rxjava2-jdbc-stored-procedure.jar', 'APP.examples',0)");
String sql = "CREATE PROCEDURE APP.RETURNRESULTSETS(in min_score integer)" //
+ " PARAMETER STYLE JAVA" //
+ " LANGUAGE JAVA" //
+ " READS SQL DATA" //
+ " DYNAMIC RESULT SETS 2" //
+ " EXTERNAL NAME" //
+ " 'org.davidmoten.rx.jdbc.StoredProcExample.returnResultSets'";
stmt.execute(sql);
stmt.execute("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY("
+ "'derby.database.classpath', 'APP.examples')");
CallableStatement st = con.prepareCall("call returnResultSets(?)");
st.setInt(1, 0);
boolean hasResultSets = st.execute();
if (hasResultSets) {
ResultSet rs1 = st.getResultSet();
st.getMoreResults(Statement.KEEP_CURRENT_RESULT);
ResultSet rs2 = st.getResultSet();
rs1.next();
assertEquals("FRED", rs1.getString(1));
rs2.next();
assertEquals("SARAH", rs2.getString(1));
}
}
}).blockingAwait(TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
#location 4
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public static Database test(int maxPoolSize) {
Preconditions.checkArgument(maxPoolSize > 0, "maxPoolSize must be greater than 0");
return Database.from( //
Pools.nonBlocking() //
.connectionProvider(testConnectionProvider()) //
.maxPoolSize(maxPoolSize) //
.build());
} | #vulnerable code
public static Database test(int maxPoolSize) {
Preconditions.checkArgument(maxPoolSize > 0, "maxPoolSize must be greater than 0");
return Database.from( //
Pools.nonBlocking() //
.connectionProvider(testConnectionProvider()) //
.maxPoolSize(maxPoolSize) //
.scheduler(Schedulers.from(Executors.newFixedThreadPool(maxPoolSize))) //
.build());
}
#location 3
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testCompleteCompletes() {
try (Database db = db(1)) {
db //
.update("update person set score=-3 where name='FRED'") //
.complete() //
.timeout(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.blockingAwait();
int score = db.select("select score from person where name='FRED'") //
.getAs(Integer.class) //
.timeout(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.blockingFirst();
assertEquals(-3, score);
}
} | #vulnerable code
@Test
public void testCompleteCompletes() {
Database db = db(1);
db //
.update("update person set score=-3 where name='FRED'") //
.complete() //
.timeout(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.blockingAwait();
int score = db.select("select score from person where name='FRED'") //
.getAs(Integer.class) //
.timeout(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.blockingFirst();
assertEquals(-3, score);
}
#location 11
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testAutoMapToInterface() {
try (Database db = db()) {
db //
.select("select name from person") //
.autoMap(Person.class) //
.map(p -> p.name()) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(3) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testAutoMapToInterface() {
db() //
.select("select name from person") //
.autoMap(Person.class) //
.map(p -> p.name()) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(3) //
.assertComplete();
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test(expected = IllegalArgumentException.class)
public void testReturnGeneratedKeysWithBatchSizeShouldThrow() {
try (Database db = db()) {
// note is a table with auto increment
db.update("insert into note(text) values(?)") //
.parameters("HI", "THERE") //
.batchSize(2) //
.returnGeneratedKeys();
}
} | #vulnerable code
@Test(expected = IllegalArgumentException.class)
public void testReturnGeneratedKeysWithBatchSizeShouldThrow() {
Database db = db();
// note is a table with auto increment
db.update("insert into note(text) values(?)") //
.parameters("HI", "THERE") //
.batchSize(2) //
.returnGeneratedKeys();
}
#location 6
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateThreeRows() {
try (Database db = db()) {
db.update("update person set score=20") //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(3) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateThreeRows() {
db().update("update person set score=20") //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(3) //
.assertComplete();
}
#location 4
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testAutoMapWithQueryInAnnotation() {
try (Database db = db()) {
db.select(Person10.class) //
.get() //
.firstOrError() //
.map(Person10::score) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(21) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testAutoMapWithQueryInAnnotation() {
db().select(Person10.class) //
.get() //
.firstOrError() //
.map(Person10::score) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(21) //
.assertComplete();
}
#location 4
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectDependsOnOnSingle() {
try (Database db = db()) {
Single<Long> a = db.update("update person set score=100 where name=?") //
.parameter("FRED") //
.counts().count();
db.select("select score from person where name=?") //
.parameter("FRED") //
.dependsOn(a) //
.getAs(Integer.class)//
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(100) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testSelectDependsOnOnSingle() {
Database db = db();
Single<Long> a = db.update("update person set score=100 where name=?") //
.parameter("FRED") //
.counts().count();
db.select("select score from person where name=?") //
.parameter("FRED") //
.dependsOn(a) //
.getAs(Integer.class)//
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(100) //
.assertComplete();
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testAutoMapToInterfaceWithTwoMethods() {
try (Database db = db()) {
db //
.select("select name, score from person order by name") //
.autoMap(Person2.class) //
.firstOrError() //
.map(Person2::score) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(21) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testAutoMapToInterfaceWithTwoMethods() {
db() //
.select("select name, score from person order by name") //
.autoMap(Person2.class) //
.firstOrError() //
.map(Person2::score) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(21) //
.assertComplete();
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateUtilDateParameter() {
try (Database db = db()) {
Date d = new Date(1234);
db.update("update person set registered=?") //
.parameter(d) //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(3) //
.assertComplete();
db.select("select registered from person") //
.getAs(Long.class) //
.firstOrError() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1234L) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateUtilDateParameter() {
Database db = db();
Date d = new Date(1234);
db.update("update person set registered=?") //
.parameter(d) //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(3) //
.assertComplete();
db.select("select registered from person") //
.getAs(Long.class) //
.firstOrError() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1234L) //
.assertComplete();
}
#location 13
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectAutomappedTransacted() {
try (Database db = db()) {
db //
.select("select name, score from person") //
.transacted() //
.autoMap(Person2.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(4) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testSelectAutomappedTransacted() {
db() //
.select("select name, score from person") //
.transacted() //
.autoMap(Person2.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(4) //
.assertComplete();
}
#location 6
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateWithinTransaction() {
try (Database db = db()) {
db //
.select("select name from person") //
.transactedValuesOnly() //
.getAs(String.class) //
.doOnNext(System.out::println) //
.flatMap(tx -> tx//
.update("update person set score=-1 where name=:name") //
.batchSize(1) //
.parameter("name", tx.value()) //
.valuesOnly() //
.counts()) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(1, 1, 1) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateWithinTransaction() {
db() //
.select("select name from person") //
.transactedValuesOnly() //
.getAs(String.class) //
.doOnNext(System.out::println) //
.flatMap(tx -> tx//
.update("update person set score=-1 where name=:name") //
.batchSize(1) //
.parameter("name", tx.value()) //
.valuesOnly() //
.counts()) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(1, 1, 1) //
.assertComplete();
}
#location 6
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectTransactedTuple7() {
try (Database db = db()) {
Tx<Tuple7<String, Integer, String, Integer, String, Integer, String>> t = db //
.select("select name, score, name, score, name, score, name from person where name=?") //
.parameters("FRED") //
.transacted() //
.getAs(String.class, Integer.class, String.class, Integer.class, String.class,
Integer.class, String.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(2) //
.assertComplete() //
.values().get(0);
assertEquals("FRED", t.value()._1());
assertEquals(21, (int) t.value()._2());
assertEquals("FRED", t.value()._3());
assertEquals(21, (int) t.value()._4());
assertEquals("FRED", t.value()._5());
assertEquals(21, (int) t.value()._6());
assertEquals("FRED", t.value()._7());
}
} | #vulnerable code
@Test
public void testSelectTransactedTuple7() {
Tx<Tuple7<String, Integer, String, Integer, String, Integer, String>> t = db() //
.select("select name, score, name, score, name, score, name from person where name=?") //
.parameters("FRED") //
.transacted() //
.getAs(String.class, Integer.class, String.class, Integer.class, String.class,
Integer.class, String.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(2) //
.assertComplete() //
.values().get(0);
assertEquals("FRED", t.value()._1());
assertEquals(21, (int) t.value()._2());
assertEquals("FRED", t.value()._3());
assertEquals(21, (int) t.value()._4());
assertEquals("FRED", t.value()._5());
assertEquals(21, (int) t.value()._6());
assertEquals("FRED", t.value()._7());
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testInsertBlobAndReadBlobAsByteArray() {
try (Database db = db()) {
insertPersonBlob(db);
db.select("select document from person_blob where name='FRED'") //
.getAs(byte[].class) //
.map(b -> new String(b)) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue("some text here") //
.assertComplete();
}
} | #vulnerable code
@Test
public void testInsertBlobAndReadBlobAsByteArray() {
Database db = db();
insertPersonBlob(db);
db.select("select document from person_blob where name='FRED'") //
.getAs(byte[].class) //
.map(b -> new String(b)) //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue("some text here") //
.assertComplete();
}
#location 6
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testTupleN() {
try (Database db = db()) {
db //
.select("select name, score, name from person order by name") //
.getTupleN() //
.firstOrError().test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertComplete() //
.assertValue(TupleN.create("FRED", 21, "FRED")); //
}
} | #vulnerable code
@Test
public void testTupleN() {
db() //
.select("select name, score, name from person order by name") //
.getTupleN() //
.firstOrError().test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertComplete() //
.assertValue(TupleN.create("FRED", 21, "FRED")); //
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectWithFetchSizeZero() {
try (Database db = db()) {
db.select("select score from person order by name") //
.fetchSize(0) //
.getAs(Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoErrors() //
.assertValues(21, 34, 25) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testSelectWithFetchSizeZero() {
db().select("select score from person order by name") //
.fetchSize(0) //
.getAs(Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertNoErrors() //
.assertValues(21, 34, 25) //
.assertComplete();
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateClobWithClob() throws SQLException {
try (Database db = db()) {
Clob clob = new JDBCClobFile(new File("src/test/resources/big.txt"));
insertNullClob(db);
db //
.update("update person_clob set document = :doc") //
.parameter("doc", clob) //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateClobWithClob() throws SQLException {
Database db = db();
Clob clob = new JDBCClobFile(new File("src/test/resources/big.txt"));
insertNullClob(db);
db //
.update("update person_clob set document = :doc") //
.parameter("doc", clob) //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
}
#location 9
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectUsingNonBlockingBuilder() {
NonBlockingConnectionPool pool = Pools //
.nonBlocking() //
.connectionProvider(DatabaseCreator.connectionProvider()) //
.maxIdleTime(1, TimeUnit.MINUTES) //
.idleTimeBeforeHealthCheck(1, TimeUnit.MINUTES) //
.healthy(c -> c.prepareStatement("select 1").execute()) //
.maxPoolSize(3) //
.build();
try (Database db = Database.from(pool)) {
db.select("select score from person where name=?") //
.parameters("FRED", "JOSEPH") //
.getAs(Integer.class) //
.test() //
.assertNoErrors() //
.assertValues(21, 34) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testSelectUsingNonBlockingBuilder() {
NonBlockingConnectionPool pool = Pools //
.nonBlocking() //
.connectionProvider(DatabaseCreator.connectionProvider()) //
.maxIdleTime(1, TimeUnit.MINUTES) //
.idleTimeBeforeHealthCheck(1, TimeUnit.MINUTES) //
.healthy(c -> c.prepareStatement("select 1").execute()) //
.maxPoolSize(3) //
.build();
Database.from(pool) //
.select("select score from person where name=?") //
.parameters("FRED", "JOSEPH") //
.getAs(Integer.class) //
.test() //
.assertNoErrors() //
.assertValues(21, 34) //
.assertComplete();
}
#location 12
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectTransactedGetAsOptional() {
try (Database db = db()) {
List<Tx<Optional<String>>> list = db //
.select("select name from person where name=?") //
.parameters("FRED") //
.transacted() //
.getAsOptional(String.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(2) //
.assertComplete() //
.values();
assertTrue(list.get(0).isValue());
assertEquals("FRED", list.get(0).value().get());
assertTrue(list.get(1).isComplete());
}
} | #vulnerable code
@Test
public void testSelectTransactedGetAsOptional() {
List<Tx<Optional<String>>> list = db() //
.select("select name from person where name=?") //
.parameters("FRED") //
.transacted() //
.getAsOptional(String.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(2) //
.assertComplete() //
.values();
assertTrue(list.get(0).isValue());
assertEquals("FRED", list.get(0).value().get());
assertTrue(list.get(1).isComplete());
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateCalendarParameter() {
Calendar c = GregorianCalendar.from(ZonedDateTime.parse("2017-03-25T15:37Z"));
try (Database db = db()) {
db.update("update person set registered=?") //
.parameter(c) //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(3) //
.assertComplete();
db.select("select registered from person") //
.getAs(Long.class) //
.firstOrError() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(c.getTimeInMillis()) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateCalendarParameter() {
Calendar c = GregorianCalendar.from(ZonedDateTime.parse("2017-03-25T15:37Z"));
Database db = db();
db.update("update person set registered=?") //
.parameter(c) //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(3) //
.assertComplete();
db.select("select registered from person") //
.getAs(Long.class) //
.firstOrError() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(c.getTimeInMillis()) //
.assertComplete();
}
#location 13
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test(expected = NullPointerException.class)
public void testSelectUsingNullNameInParameter() {
try (Database db = db()) {
db //
.select("select score from person where name=:name") //
.parameter(null, "FRED"); //
}
} | #vulnerable code
@Test(expected = NullPointerException.class)
public void testSelectUsingNullNameInParameter() {
db() //
.select("select score from person where name=:name") //
.parameter(null, "FRED"); //
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testSelectTransactedTuple2() {
try (Database db = db()) {
Tx<Tuple2<String, Integer>> t = db //
.select("select name, score from person where name=?") //
.parameters("FRED") //
.transacted() //
.getAs(String.class, Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(2) //
.assertComplete() //
.values().get(0);
assertEquals("FRED", t.value()._1());
assertEquals(21, (int) t.value()._2());
}
} | #vulnerable code
@Test
public void testSelectTransactedTuple2() {
Tx<Tuple2<String, Integer>> t = db() //
.select("select name, score from person where name=?") //
.parameters("FRED") //
.transacted() //
.getAs(String.class, Integer.class) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValueCount(2) //
.assertComplete() //
.values().get(0);
assertEquals("FRED", t.value()._1());
assertEquals(21, (int) t.value()._2());
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testUpdateSqlDateParameter() {
try (Database db = db()) {
java.sql.Date t = new java.sql.Date(1234);
db.update("update person set registered=?") //
.parameter(t) //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(3) //
.assertComplete();
db.select("select registered from person") //
.getAs(Long.class) //
.firstOrError() //
.test() //
.awaitDone(TIMEOUT_SECONDS * 10000, TimeUnit.SECONDS) //
// TODO make a more accurate comparison using the current TZ
.assertValue(x -> Math.abs(x - 1234) <= TimeUnit.HOURS.toMillis(24)) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testUpdateSqlDateParameter() {
Database db = db();
java.sql.Date t = new java.sql.Date(1234);
db.update("update person set registered=?") //
.parameter(t) //
.counts() //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(3) //
.assertComplete();
db.select("select registered from person") //
.getAs(Long.class) //
.firstOrError() //
.test() //
.awaitDone(TIMEOUT_SECONDS * 10000, TimeUnit.SECONDS) //
// TODO make a more accurate comparison using the current TZ
.assertValue(x -> Math.abs(x - 1234) <= TimeUnit.HOURS.toMillis(24)) //
.assertComplete();
}
#location 14
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testInsertClobAndReadClobUsingReader() {
try (Database db = db()) {
db.update("insert into person_clob(name,document) values(?,?)") //
.parameters("FRED", "some text here") //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
db.select("select document from person_clob where name='FRED'") //
.getAs(Reader.class) //
.map(r -> read(r)).test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue("some text here") //
.assertComplete();
}
} | #vulnerable code
@Test
public void testInsertClobAndReadClobUsingReader() {
Database db = db();
db.update("insert into person_clob(name,document) values(?,?)") //
.parameters("FRED", "some text here") //
.counts() //
.test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue(1) //
.assertComplete();
db.select("select document from person_clob where name='FRED'") //
.getAs(Reader.class) //
.map(r -> read(r)).test().awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValue("some text here") //
.assertComplete();
}
#location 11
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void testTransactedReturnGeneratedKeys2() {
try (Database db = db()) {
// note is a table with auto increment
Flowable<Integer> a = db.update("insert into note(text) values(?)") //
.parameters("HI", "THERE") //
.transacted() //
.returnGeneratedKeys() //
.valuesOnly() //
.getAs(Integer.class);
db.update("insert into note(text) values(?)") //
.parameters("ME", "TOO") //
.transacted() //
.returnGeneratedKeys() //
.valuesOnly() //
.getAs(Integer.class)//
.startWith(a) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(1, 2, 3, 4) //
.assertComplete();
}
} | #vulnerable code
@Test
public void testTransactedReturnGeneratedKeys2() {
Database db = db();
// note is a table with auto increment
Flowable<Integer> a = db.update("insert into note(text) values(?)") //
.parameters("HI", "THERE") //
.transacted() //
.returnGeneratedKeys() //
.valuesOnly() //
.getAs(Integer.class);
db.update("insert into note(text) values(?)") //
.parameters("ME", "TOO") //
.transacted() //
.returnGeneratedKeys() //
.valuesOnly() //
.getAs(Integer.class)//
.startWith(a) //
.test() //
.awaitDone(TIMEOUT_SECONDS, TimeUnit.SECONDS) //
.assertValues(1, 2, 3, 4) //
.assertComplete();
}
#location 13
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void sendMessage(CommandIssuer issuer, MessageType type, MessageKeyProvider key, String... replacements) {
String message = formatMessage(issuer, type, key, replacements);
for (String msg : ACFPatterns.NEWLINE.split(message)) {
issuer.sendMessageInternal(ACFUtil.rtrim(msg));
}
} | #vulnerable code
public void sendMessage(CommandIssuer issuer, MessageType type, MessageKeyProvider key, String... replacements) {
String message = getLocales().getMessage(issuer, key.getMessageKey());
if (replacements.length > 0) {
message = ACFUtil.replaceStrings(message, replacements);
}
message = getCommandReplacements().replace(message);
MessageFormatter formatter = formatters.getOrDefault(type, defaultFormatter);
if (formatter != null) {
message = formatter.format(message);
}
for (String msg : ACFPatterns.NEWLINE.split(message)) {
issuer.sendMessageInternal(msg);
}
}
#location 11
#vulnerability type NULL_DEREFERENCE | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public List<String> tabComplete(CommandIssuer issuer, String commandLabel, String[] args) {
return tabComplete(issuer, commandLabel, args, false);
} | #vulnerable code
public List<String> tabComplete(CommandIssuer issuer, String commandLabel, String[] args)
throws IllegalArgumentException {
commandLabel = commandLabel.toLowerCase();
try {
CommandOperationContext commandOperationContext = preCommandOperation(issuer, commandLabel, args);
final CommandSearch search = findSubCommand(args, true);
String argString = ApacheCommonsLangUtil.join(args, " ").toLowerCase();
final List<String> cmds = new ArrayList<>();
if (search != null) {
cmds.addAll(completeCommand(commandOperationContext, issuer, search.cmd, Arrays.copyOfRange(args, search.argIndex, args.length), commandLabel));
} else if (subCommands.get(UNKNOWN).size() == 1) {
cmds.addAll(completeCommand(commandOperationContext, issuer, Iterables.getOnlyElement(subCommands.get(UNKNOWN)), args, commandLabel));
}
for (Map.Entry<String, RegisteredCommand> entry : subCommands.entries()) {
final String key = entry.getKey();
if (key.startsWith(argString) && !UNKNOWN.equals(key) && !DEFAULT.equals(key)) {
final RegisteredCommand value = entry.getValue();
if (!value.hasPermission(issuer)) {
continue;
}
String prefCommand = value.prefSubCommand;
final String[] psplit = ACFPatterns.SPACE.split(prefCommand);
cmds.add(psplit[args.length - 1]);
}
}
return filterTabComplete(args[args.length - 1], cmds);
} finally {
postCommandOperation();
}
}
#location 10
#vulnerability type NULL_DEREFERENCE | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void stop()
{
if (State.TRANSCRIBING.equals(this.state))
{
if (logger.isDebugEnabled())
logger.debug("Transcriber is now finishing up");
updateDDClient(DD_ASPECT_STOP);
this.state = State.FINISHING_UP;
this.executorService.shutdown();
TranscriptEvent event = this.transcript.ended();
fireTranscribeEvent(event);
ActionServicesHandler.getInstance()
.notifyActionServices(this, event);
checkIfFinishedUp();
}
else
{
logger.warn("Trying to stop Transcriber while it is " +
"already stopped");
}
} | #vulnerable code
public void stop()
{
if (State.TRANSCRIBING.equals(this.state))
{
if (logger.isDebugEnabled())
logger.debug("Transcriber is now finishing up");
StatsDClient dClient = JigasiBundleActivator.getDataDogClient();
if(dClient != null)
{
dClient.increment(DD_ASPECT_STOP);
if(logger.isDebugEnabled())
{
logger.debug("thrown stat: " + DD_ASPECT_STOP);
}
}
this.state = State.FINISHING_UP;
this.executorService.shutdown();
TranscriptEvent event = this.transcript.ended();
fireTranscribeEvent(event);
ActionServicesHandler.getInstance()
.notifyActionServices(this, event);
checkIfFinishedUp();
}
else
{
logger.warn("Trying to stop Transcriber while it is " +
"already stopped");
}
}
#location 21
#vulnerability type THREAD_SAFETY_VIOLATION | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
private void updatePresenceStatusForXmppProviders()
{
Collection<ServiceReference<ProtocolProviderService>> refs
= ServiceUtils.getServiceReferences(
osgiContext,
ProtocolProviderService.class);
for (ServiceReference<ProtocolProviderService> ref : refs)
{
updatePresenceStatusForXmppProvider(osgiContext.getService(ref));
}
} | #vulnerable code
private void updatePresenceStatusForXmppProviders()
{
SipGateway gateway = ServiceUtils.getService(
osgiContext, SipGateway.class);
int participants = 0;
for(SipGatewaySession ses : gateway.getActiveSessions())
{
participants += ses.getJvbChatRoom().getMembersCount();
}
Collection<ServiceReference<ProtocolProviderService>> refs
= ServiceUtils.getServiceReferences(
osgiContext,
ProtocolProviderService.class);
for (ServiceReference<ProtocolProviderService> ref : refs)
{
updatePresenceStatusForXmppProvider(
gateway, osgiContext.getService(ref), participants);
}
}
#location 9
#vulnerability type NULL_DEREFERENCE | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void start()
{
if (State.NOT_STARTED.equals(this.state))
{
if (logger.isDebugEnabled())
logger.debug("Transcriber is now transcribing");
updateDDClient(DD_ASPECT_START);
this.state = State.TRANSCRIBING;
this.executorService = Executors.newSingleThreadExecutor();
TranscriptEvent event
= this.transcript.started(roomName, roomUrl, getParticipants());
if (event != null)
{
fireTranscribeEvent(event);
}
}
else
{
logger.warn("Trying to start Transcriber while it is" +
"already started");
}
} | #vulnerable code
public void start()
{
if (State.NOT_STARTED.equals(this.state))
{
if (logger.isDebugEnabled())
logger.debug("Transcriber is now transcribing");
StatsDClient dClient = JigasiBundleActivator.getDataDogClient();
if(dClient != null)
{
dClient.increment(DD_ASPECT_START);
if(logger.isDebugEnabled())
{
logger.debug("thrown stat: " + DD_ASPECT_START);
}
}
this.state = State.TRANSCRIBING;
this.executorService = Executors.newSingleThreadExecutor();
List<Participant> participantsClone;
synchronized (this.participants)
{
participantsClone = new ArrayList<>(this.participants.size());
participantsClone.addAll(this.participants.values());
}
TranscriptEvent event
= this.transcript.started(roomName, roomUrl, participantsClone);
if (event != null)
{
fireTranscribeEvent(event);
}
}
else
{
logger.warn("Trying to start Transcriber while it is" +
"already started");
}
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
void notifyCallEnded(String callResource)
{
GatewaySession session;
synchronized (sessions)
{
session = sessions.remove(callResource);
if (session == null)
{
// FIXME: print some gateway ID or provider here
logger.error(
"Call resource not exists for session " + callResource);
return;
}
}
logger.info("Removed session for call " + callResource);
} | #vulnerable code
void notifyCallEnded(String callResource)
{
GatewaySession session;
synchronized (sessions)
{
session = sessions.remove(callResource);
if (session == null)
{
// FIXME: print some gateway ID or provider here
logger.error(
"Call resource not exists for session " + callResource);
return;
}
}
logger.info("Removed session for call " + callResource);
if (callsControl != null)
{
callsControl.callEnded(this, session.getCallResource());
}
}
#location 22
#vulnerability type THREAD_SAFETY_VIOLATION | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void stop()
{
if (State.TRANSCRIBING.equals(this.state))
{
if (logger.isDebugEnabled())
logger.debug("Transcriber is now finishing up");
updateDDClient(DD_ASPECT_STOP);
this.state = State.FINISHING_UP;
this.executorService.shutdown();
TranscriptEvent event = this.transcript.ended();
fireTranscribeEvent(event);
ActionServicesHandler.getInstance()
.notifyActionServices(this, event);
checkIfFinishedUp();
}
else
{
logger.warn("Trying to stop Transcriber while it is " +
"already stopped");
}
} | #vulnerable code
public void stop()
{
if (State.TRANSCRIBING.equals(this.state))
{
if (logger.isDebugEnabled())
logger.debug("Transcriber is now finishing up");
StatsDClient dClient = JigasiBundleActivator.getDataDogClient();
if(dClient != null)
{
dClient.increment(DD_ASPECT_STOP);
if(logger.isDebugEnabled())
{
logger.debug("thrown stat: " + DD_ASPECT_STOP);
}
}
this.state = State.FINISHING_UP;
this.executorService.shutdown();
TranscriptEvent event = this.transcript.ended();
fireTranscribeEvent(event);
ActionServicesHandler.getInstance()
.notifyActionServices(this, event);
checkIfFinishedUp();
}
else
{
logger.warn("Trying to stop Transcriber while it is " +
"already stopped");
}
}
#location 19
#vulnerability type THREAD_SAFETY_VIOLATION | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void stop()
{
if (State.TRANSCRIBING.equals(this.state))
{
if (logger.isDebugEnabled())
logger.debug("Transcriber is now finishing up");
updateDDClient(DD_ASPECT_STOP);
this.state = State.FINISHING_UP;
this.executorService.shutdown();
TranscriptEvent event = this.transcript.ended();
fireTranscribeEvent(event);
ActionServicesHandler.getInstance()
.notifyActionServices(this, event);
checkIfFinishedUp();
}
else
{
logger.warn("Trying to stop Transcriber while it is " +
"already stopped");
}
} | #vulnerable code
public void stop()
{
if (State.TRANSCRIBING.equals(this.state))
{
if (logger.isDebugEnabled())
logger.debug("Transcriber is now finishing up");
StatsDClient dClient = JigasiBundleActivator.getDataDogClient();
if(dClient != null)
{
dClient.increment(DD_ASPECT_STOP);
if(logger.isDebugEnabled())
{
logger.debug("thrown stat: " + DD_ASPECT_STOP);
}
}
this.state = State.FINISHING_UP;
this.executorService.shutdown();
TranscriptEvent event = this.transcript.ended();
fireTranscribeEvent(event);
ActionServicesHandler.getInstance()
.notifyActionServices(this, event);
checkIfFinishedUp();
}
else
{
logger.warn("Trying to stop Transcriber while it is " +
"already stopped");
}
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
void sendPresenceExtension(ExtensionElement extension)
{
if (mucRoom != null)
{
// Send presence update
OperationSetJitsiMeetTools jitsiMeetTools
= xmppProvider.getOperationSet(
OperationSetJitsiMeetTools.class);
jitsiMeetTools.sendPresenceExtension(mucRoom, extension);
}
} | #vulnerable code
void setPresenceStatus(String statusMsg)
{
if (mucRoom != null)
{
// Send presence status update
OperationSetJitsiMeetTools jitsiMeetTools
= xmppProvider.getOperationSet(
OperationSetJitsiMeetTools.class);
jitsiMeetTools.setPresenceStatus(mucRoom, statusMsg);
}
}
#location 7
#vulnerability type THREAD_SAFETY_VIOLATION | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
void checkIfFinishedUp()
{
if (State.FINISHING_UP.equals(this.state))
{
synchronized (this.participants)
{
for (Participant participant : participants.values())
{
if (!participant.isCompleted())
{
logger.debug(
participant.getDebugName()
+ " is still not finished");
return;
}
}
}
if (logger.isDebugEnabled())
logger.debug(getDebugName() + ": transcriber is now finished");
this.state = State.FINISHED;
for (TranscriptionListener listener : listeners)
{
listener.completed();
}
}
} | #vulnerable code
void checkIfFinishedUp()
{
if (State.FINISHING_UP.equals(this.state))
{
synchronized (this.participants)
{
for (Participant participant : participants.values())
{
if (!participant.isCompleted())
{
return;
}
}
}
if (logger.isDebugEnabled())
logger.debug(getDebugName() + ": transcriber is now finished");
this.state = State.FINISHED;
for (TranscriptionListener listener : listeners)
{
listener.completed();
}
}
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
void sendPresenceExtension(ExtensionElement extension)
{
if (mucRoom != null)
{
// Send presence update
OperationSetJitsiMeetTools jitsiMeetTools
= xmppProvider.getOperationSet(
OperationSetJitsiMeetTools.class);
jitsiMeetTools.sendPresenceExtension(mucRoom, extension);
}
} | #vulnerable code
void setPresenceStatus(String statusMsg)
{
if (mucRoom != null)
{
// Send presence status update
OperationSetJitsiMeetTools jitsiMeetTools
= xmppProvider.getOperationSet(
OperationSetJitsiMeetTools.class);
jitsiMeetTools.setPresenceStatus(mucRoom, statusMsg);
}
}
#location 10
#vulnerability type THREAD_SAFETY_VIOLATION | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public synchronized void stop()
{
if (!started)
{
logger.error(this.callContext + " Already stopped !");
return;
}
started = false;
JigasiBundleActivator.osgiContext.removeServiceListener(this);
if (telephony != null)
{
telephony.removeCallListener(callListener);
telephony = null;
}
if (muteIqHandler != null)
{
// we need to remove it from the connection, or we break some Smack
// weak references map where the key is connection and the value
// holds a connection and we leak connection/conferences.
XMPPConnection connection = getConnection();
if (connection != null)
{
connection.unregisterIQRequestHandler(muteIqHandler);
}
}
gatewaySession.onJvbConferenceWillStop(this, endReasonCode, endReason);
leaveConferenceRoom();
if (jvbCall != null)
{
CallManager.hangupCall(jvbCall, true);
}
if (xmppProvider != null)
{
xmppProvider.removeRegistrationStateChangeListener(this);
// in case we were not able to create jvb call, unit tests case
if (jvbCall == null)
{
logger.info(
callContext + " Removing account " + xmppAccount);
xmppProviderFactory.unloadAccount(xmppAccount);
}
xmppProviderFactory = null;
xmppAccount = null;
xmppProvider = null;
}
gatewaySession.onJvbConferenceStopped(this, endReasonCode, endReason);
setJvbCall(null);
} | #vulnerable code
public synchronized void stop()
{
if (!started)
{
logger.error(this.callContext + " Already stopped !");
return;
}
started = false;
JigasiBundleActivator.osgiContext.removeServiceListener(this);
if (telephony != null)
{
telephony.removeCallListener(callListener);
telephony = null;
}
if (muteIqHandler != null)
{
// we need to remove it from the connection, or we break some Smack
// weak references map where the key is connection and the value
// holds a connection and we leak connection/conferences.
getConnection().unregisterIQRequestHandler(muteIqHandler);
}
gatewaySession.onJvbConferenceWillStop(this, endReasonCode, endReason);
leaveConferenceRoom();
if (jvbCall != null)
{
CallManager.hangupCall(jvbCall, true);
}
if (xmppProvider != null)
{
xmppProvider.removeRegistrationStateChangeListener(this);
// in case we were not able to create jvb call, unit tests case
if (jvbCall == null)
{
logger.info(
callContext + " Removing account " + xmppAccount);
xmppProviderFactory.unloadAccount(xmppAccount);
}
xmppProviderFactory = null;
xmppAccount = null;
xmppProvider = null;
}
gatewaySession.onJvbConferenceStopped(this, endReasonCode, endReason);
setJvbCall(null);
}
#location 24
#vulnerability type NULL_DEREFERENCE | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void start()
{
if (State.NOT_STARTED.equals(this.state))
{
if (logger.isDebugEnabled())
logger.debug("Transcriber is now transcribing");
updateDDClient(DD_ASPECT_START);
this.state = State.TRANSCRIBING;
this.executorService = Executors.newSingleThreadExecutor();
TranscriptEvent event
= this.transcript.started(roomName, roomUrl, getParticipants());
if (event != null)
{
fireTranscribeEvent(event);
}
}
else
{
logger.warn("Trying to start Transcriber while it is" +
"already started");
}
} | #vulnerable code
public void start()
{
if (State.NOT_STARTED.equals(this.state))
{
if (logger.isDebugEnabled())
logger.debug("Transcriber is now transcribing");
StatsDClient dClient = JigasiBundleActivator.getDataDogClient();
if(dClient != null)
{
dClient.increment(DD_ASPECT_START);
if(logger.isDebugEnabled())
{
logger.debug("thrown stat: " + DD_ASPECT_START);
}
}
this.state = State.TRANSCRIBING;
this.executorService = Executors.newSingleThreadExecutor();
List<Participant> participantsClone;
synchronized (this.participants)
{
participantsClone = new ArrayList<>(this.participants.size());
participantsClone.addAll(this.participants.values());
}
TranscriptEvent event
= this.transcript.started(roomName, roomUrl, participantsClone);
if (event != null)
{
fireTranscribeEvent(event);
}
}
else
{
logger.warn("Trying to start Transcriber while it is" +
"already started");
}
}
#location 29
#vulnerability type THREAD_SAFETY_VIOLATION | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void start()
{
if (State.NOT_STARTED.equals(this.state))
{
if (logger.isDebugEnabled())
logger.debug("Transcriber is now transcribing");
updateDDClient(DD_ASPECT_START);
this.state = State.TRANSCRIBING;
this.executorService = Executors.newSingleThreadExecutor();
TranscriptEvent event
= this.transcript.started(roomName, roomUrl, getParticipants());
if (event != null)
{
fireTranscribeEvent(event);
}
}
else
{
logger.warn("Trying to start Transcriber while it is" +
"already started");
}
} | #vulnerable code
public void start()
{
if (State.NOT_STARTED.equals(this.state))
{
if (logger.isDebugEnabled())
logger.debug("Transcriber is now transcribing");
StatsDClient dClient = JigasiBundleActivator.getDataDogClient();
if(dClient != null)
{
dClient.increment(DD_ASPECT_START);
if(logger.isDebugEnabled())
{
logger.debug("thrown stat: " + DD_ASPECT_START);
}
}
this.state = State.TRANSCRIBING;
this.executorService = Executors.newSingleThreadExecutor();
List<Participant> participantsClone;
synchronized (this.participants)
{
participantsClone = new ArrayList<>(this.participants.size());
participantsClone.addAll(this.participants.values());
}
TranscriptEvent event
= this.transcript.started(roomName, roomUrl, participantsClone);
if (event != null)
{
fireTranscribeEvent(event);
}
}
else
{
logger.warn("Trying to start Transcriber while it is" +
"already started");
}
}
#location 18
#vulnerability type THREAD_SAFETY_VIOLATION | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
void onConferenceCallInvited(Call incomingCall)
{
// Incoming SIP connection mode sets common conference here
if (destination == null)
{
incomingCall.setConference(sipCall.getConference());
boolean useTranslator = incomingCall.getProtocolProvider()
.getAccountID().getAccountPropertyBoolean(
ProtocolProviderFactory.USE_TRANSLATOR_IN_CONFERENCE,
false);
CallPeer peer = incomingCall.getCallPeers().next();
// if use translator is enabled add a ssrc rewriter
if (useTranslator && !addSsrcRewriter(peer))
{
peer.addCallPeerListener(new CallPeerAdapter()
{
@Override
public void peerStateChanged(CallPeerChangeEvent evt)
{
CallPeer peer = evt.getSourceCallPeer();
CallPeerState peerState = peer.getState();
if (CallPeerState.CONNECTED.equals(peerState))
{
peer.removeCallPeerListener(this);
addSsrcRewriter(peer);
}
}
});
}
}
Exception error = this.onConferenceCallStarted(incomingCall);
if (error != null)
{
logger.error(this.callContext + " " + error, error);
}
} | #vulnerable code
void onJvbConferenceStopped(JvbConference jvbConference,
int reasonCode, String reason)
{
this.jvbConference = null;
if (sipCall != null)
{
hangUp(reasonCode, reason);
}
else
{
allCallsEnded();
}
}
#location 8
#vulnerability type NULL_DEREFERENCE | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void start()
{
if (State.NOT_STARTED.equals(this.state))
{
if (logger.isDebugEnabled())
logger.debug("Transcriber is now transcribing");
updateDDClient(DD_ASPECT_START);
this.state = State.TRANSCRIBING;
this.executorService = Executors.newSingleThreadExecutor();
TranscriptEvent event
= this.transcript.started(roomName, roomUrl, getParticipants());
if (event != null)
{
fireTranscribeEvent(event);
}
}
else
{
logger.warn("Trying to start Transcriber while it is" +
"already started");
}
} | #vulnerable code
public void start()
{
if (State.NOT_STARTED.equals(this.state))
{
if (logger.isDebugEnabled())
logger.debug("Transcriber is now transcribing");
StatsDClient dClient = JigasiBundleActivator.getDataDogClient();
if(dClient != null)
{
dClient.increment(DD_ASPECT_START);
if(logger.isDebugEnabled())
{
logger.debug("thrown stat: " + DD_ASPECT_START);
}
}
this.state = State.TRANSCRIBING;
this.executorService = Executors.newSingleThreadExecutor();
List<Participant> participantsClone;
synchronized (this.participants)
{
participantsClone = new ArrayList<>(this.participants.size());
participantsClone.addAll(this.participants.values());
}
TranscriptEvent event
= this.transcript.started(roomName, roomUrl, participantsClone);
if (event != null)
{
fireTranscribeEvent(event);
}
}
else
{
logger.warn("Trying to start Transcriber while it is" +
"already started");
}
}
#location 29
#vulnerability type THREAD_SAFETY_VIOLATION | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
void onConferenceCallInvited(Call incomingCall)
{
// Incoming SIP connection mode sets common conference here
if (destination == null)
{
call.setConference(incomingCall.getConference());
boolean useTranslator = incomingCall.getProtocolProvider()
.getAccountID().getAccountPropertyBoolean(
ProtocolProviderFactory.USE_TRANSLATOR_IN_CONFERENCE,
false);
CallPeer peer = incomingCall.getCallPeers().next();
// if use translator is enabled add a ssrc rewriter
if (useTranslator && !addSsrcRewriter(peer))
{
peer.addCallPeerListener(new CallPeerAdapter()
{
@Override
public void peerStateChanged(CallPeerChangeEvent evt)
{
CallPeer peer = evt.getSourceCallPeer();
CallPeerState peerState = peer.getState();
if (CallPeerState.CONNECTED.equals(peerState))
{
peer.removeCallPeerListener(this);
addSsrcRewriter(peer);
}
}
});
}
}
} | #vulnerable code
void onJvbConferenceStopped(JvbConference jvbConference,
int reasonCode, String reason)
{
this.jvbConference = null;
if (call != null)
{
hangUp(reasonCode, reason);
}
else
{
allCallsEnded();
}
}
#location 8
#vulnerability type NULL_DEREFERENCE | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public String pay(final String target, final Cash amount,
final String details) throws IOException {
final Props props = new Props(this.farm);
final Coinbase base = new CoinbaseBuilder().withApiKey(
props.get("//coinbase/key"), props.get("//coinbase/secret")
).build();
this.fund(base, props.get("//coinbase/account"));
final Transaction trn = new Transaction();
trn.setTo(target);
trn.setAmount(
Money.parse(
String.format(
"USD %.2f",
amount.exchange(Currency.USD).decimal().doubleValue()
)
)
);
trn.setNotes(details);
trn.setInstantBuy(true);
try {
return base.sendMoney(trn).getId();
} catch (final CoinbaseException ex) {
throw new IOException(
String.format(
"Failed to send %s to %s: %s",
trn.getAmount(), trn.getTo(), trn.getNotes()
),
ex
);
}
} | #vulnerable code
@Override
public String pay(final String target, final Cash amount,
final String details) throws IOException {
if (amount.compareTo(new Cash.S("$20")) < 0) {
throw new SoftException(
new Par(
"The amount %s is too small,",
"we won't send now to avoid big %s commission"
).say(amount, this.currency)
);
}
final Props props = new Props(this.farm);
final Coinbase base = new CoinbaseBuilder().withApiKey(
props.get("//coinbase/key"), props.get("//coinbase/secret")
).build();
this.fund(base, props.get("//coinbase/account"));
final Transaction trn = new Transaction();
trn.setTo(target);
trn.setAmount(
Money.parse(
String.format(
"USD %.2f",
amount.exchange(Currency.USD).decimal().doubleValue()
)
)
);
trn.setNotes(details);
trn.setInstantBuy(true);
try {
return base.sendMoney(trn).getId();
} catch (final CoinbaseException ex) {
throw new IOException(
String.format(
"Failed to send %s to %s: %s",
trn.getAmount(), trn.getTo(), trn.getNotes()
),
ex
);
}
}
#location 9
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public String pay(final Project project,
final String login, final Cash amount,
final String reason) throws IOException {
final People people = new People(this.farm).bootstrap();
final String wallet = people.wallet(login);
if (wallet.isEmpty()) {
throw new SoftException(
new Par(
"@%s doesn't have payment method configured, we can't pay"
).say(login)
);
}
final String method = people.bank(login);
if (!this.banks.containsKey(method)) {
throw new SoftException(
new Par(
"@%s has an unsupported payment method \"%s\""
).say(login, method)
);
}
final Bank bank = this.banks.get(method);
final Cash commission = bank.fee(amount);
final String pid = bank.pay(
wallet, amount, new Par.ToText(reason).toString()
);
new Ledger(project).bootstrap().add(
new Ledger.Transaction(
amount.add(commission),
"liabilities", method,
"assets", "cash",
String.format(
"%s (amount:%s, commission:%s, PID:%s)",
new Par.ToText(reason).toString(),
amount, commission, pid
)
),
new Ledger.Transaction(
commission,
"expenses", "jobs",
"liabilities", method,
String.format(
"%s (commission)",
new Par.ToText(reason).toString()
)
),
new Ledger.Transaction(
amount,
"expenses", "jobs",
"liabilities", String.format("@%s", login),
reason
)
);
return pid;
} | #vulnerable code
public String pay(final Project project,
final String login, final Cash amount,
final String reason) throws IOException {
final People people = new People(this.farm).bootstrap();
final String wallet = people.wallet(login);
if (wallet.isEmpty()) {
throw new SoftException(
new Par(
"@%s doesn't have payment method configured, we can't pay"
).say(login)
);
}
final String method = people.bank(login);
final Bank bank;
if ("paypal".equals(method)) {
bank = new Paypal(this.farm);
} else {
throw new SoftException(
new Par(
"@%s has an unsupported payment method \"%s\""
).say(login, method)
);
}
final Cash commission = bank.fee(amount);
final String pid = bank.pay(
wallet, amount, new Par.ToText(reason).toString()
);
new Ledger(project).bootstrap().add(
new Ledger.Transaction(
amount.add(commission),
"liabilities", method,
"assets", "cash",
String.format(
"%s (amount:%s, commission:%s, PID:%s)",
new Par.ToText(reason).toString(),
amount, commission, pid
)
),
new Ledger.Transaction(
commission,
"expenses", "jobs",
"liabilities", method,
String.format(
"%s (commission)",
new Par.ToText(reason).toString()
)
),
new Ledger.Transaction(
amount,
"expenses", "jobs",
"liabilities", String.format("@%s", login),
reason
)
);
return pid;
}
#location 21
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.