output
stringlengths 64
73.2k
| input
stringlengths 208
73.3k
| instruction
stringclasses 1
value |
---|---|---|
#fixed code
@Test
public void redirectOnError() throws Exception {
// @checkstyle MethodBodyCommentsCheck (30 lines)
//final Take take = new TkApp(new PropsFarm(new FkFarm()));
//final String message = "Internal application error";
//MatcherAssert.assertThat(
// "Could not redirect on error",
// new TextOf(
// take.act(new RqFake("GET", "/?PsByFlag=PsGithub")).body()
// ).asString(),
// new IsNot<>(
// new StringContains(message)
// )
//);
//MatcherAssert.assertThat(
// "Could not redirect on error (with code)",
// new TextOf(
// take.act(
// new RqFake(
// "GET",
// "/?PsByFlag=PsGithub&code=1257b773ba07221e7eb5"
// )
// ).body()
// ).asString(),
// new IsNot<>(
// new StringContains(message)
// )
//);
} | #vulnerable code
@Test
public void redirectOnError() throws Exception {
final Take take = new TkApp(new PropsFarm(new FkFarm()));
final String message = "Internal application error";
MatcherAssert.assertThat(
"Could not redirect on error",
new TextOf(
take.act(new RqFake("GET", "/?PsByFlag=PsGithub")).body()
).asString(),
new StringContains(message)
);
MatcherAssert.assertThat(
"Could not redirect on error (with code)",
new TextOf(
take.act(
new RqFake(
"GET",
"/?PsByFlag=PsGithub&code=1257b773ba07221e7eb5"
)
).body()
).asString(),
new StringContains(message)
);
}
#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 assignsAndResigns() throws Exception {
final Project project = new FkProject();
final Orders orders = new Orders(new PropsFarm(), project).bootstrap();
final String job = "gh:yegor256/0pdd#13";
new Wbs(project).bootstrap().add(job);
orders.assign(job, "yegor256", UUID.randomUUID().toString());
} | #vulnerable code
@Test
public void assignsAndResigns() throws Exception {
final Project project = new FkProject();
final Orders orders = new Orders(new PropsFarm(), project).bootstrap();
final String job = "gh:yegor256/0pdd#13";
new Wbs(project).bootstrap().add(job);
orders.assign(job, "yegor256", "0");
}
#location 7
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
@SuppressWarnings("unchecked")
public void showsThatUserAlreadyHasMentor() throws IOException {
final Farm farm = FkFarm.props();
final People people = new People(farm).bootstrap();
final String mentor = "yoda";
final String applicant = "luke";
people.touch(mentor);
people.touch(applicant);
people.invite(applicant, mentor, true);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
new RqWithUser(
farm,
new RqFake("GET", "/join-post"),
applicant
),
"personality=INTJ-A&stackoverflow=187242"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/join"),
new HmRsHeader(
"Set-Cookie",
Matchers.hasItems(
Matchers.containsString(
URLEncoder.encode(
new FormattedText(
"You already have a mentor (@%s)",
mentor
).asString(),
StandardCharsets.UTF_8.displayName()
)
)
)
)
)
);
} | #vulnerable code
@Test
@SuppressWarnings("unchecked")
public void showsThatUserAlreadyHasMentor() throws IOException {
final Farm farm = new PropsFarm(new FkFarm());
final People people = new People(farm).bootstrap();
final String mentor = "yoda";
final String applicant = "luke";
people.touch(mentor);
people.touch(applicant);
people.invite(applicant, mentor, true);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
new RqWithUser(
farm,
new RqFake("GET", "/join-post"),
applicant
),
"personality=INTJ-A&stackoverflow=187242"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/join"),
new HmRsHeader(
"Set-Cookie",
Matchers.hasItems(
Matchers.containsString(
URLEncoder.encode(
new FormattedText(
"You already have a mentor (@%s)",
mentor
).asString(),
StandardCharsets.UTF_8.displayName()
)
)
)
)
)
);
}
#location 11
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public Response act(final Request req) throws IOException {
final JsonObject callback = TkViber.json(
new InputStreamReader(req.body(), StandardCharsets.UTF_8)
);
if (callback.isEmpty()) {
throw new HttpException(HttpURLConnection.HTTP_BAD_REQUEST);
}
if (callback.getString("event").equals("message")) {
this.reaction.react(
this.bot, this.farm, new VbEvent.Simple(callback)
);
}
return new RsWithStatus(
HttpURLConnection.HTTP_OK
);
} | #vulnerable code
@Override
public Response act(final Request req) throws IOException {
final JsonObject json = TkViber.json(
new InputStreamReader(req.body(), StandardCharsets.UTF_8)
);
if (json.isEmpty()) {
throw new RsForward(
new RsParFlash(
new Par(
"We expect this URL to be called by Viber",
"with JSON as body of the request"
).say(),
Level.WARNING
)
);
}
if (Objects.equals(json.getString("event"), "message")) {
this.reaction.react(
new VbBot(), this.farm, new VbEvent.Simple(json)
);
}
return new RsWithStatus(
HttpURLConnection.HTTP_OK
);
}
#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 closesClaims() throws Exception {
final AtomicBoolean done = new AtomicBoolean();
final Project raw = new FkProject();
final Flush flush = new Flush(
raw,
Collections.singletonList((pkt, xml) -> done.set(true)),
Executors.newSingleThreadExecutor(new VerboseThreads())
);
final RvProject project = new RvProject(raw, flush);
try (final Claims claims = new Claims(project).lock()) {
claims.add(new ClaimOut().type("hello").token("tt"));
}
flush.close();
try (final Claims claims = new Claims(project).lock()) {
MatcherAssert.assertThat(
claims.iterate(),
Matchers.hasSize(0)
);
}
MatcherAssert.assertThat(done.get(), Matchers.is(true));
} | #vulnerable code
@Test
public void closesClaims() throws Exception {
final AtomicBoolean done = new AtomicBoolean();
final Project raw = new FkProject();
final Spin spin = new Spin(
raw,
Collections.singletonList((pkt, xml) -> done.set(true)),
Executors.newSingleThreadExecutor(new VerboseThreads())
);
final RvProject project = new RvProject(raw, spin);
try (final Claims claims = new Claims(project).lock()) {
claims.add(new ClaimOut().type("hello").token("tt"));
}
spin.close();
try (final Claims claims = new Claims(project).lock()) {
MatcherAssert.assertThat(
claims.iterate(),
Matchers.hasSize(0)
);
}
MatcherAssert.assertThat(done.get(), Matchers.is(true));
}
#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 recordsChangesToClaims() throws Exception {
final Bucket bucket = new FkBucket(
Files.createTempDirectory("").toFile(),
"the-bucket"
);
final Farm farm = new SyncFarm(
new FtFarm(new PropsFarm(new S3Farm(bucket)))
);
final Project project = farm.find("@id='ABCZZFE03'").iterator().next();
final Claims claims = new Claims(project);
final AtomicLong cid = new AtomicLong(1L);
final int threads = 10;
MatcherAssert.assertThat(
inc -> {
final long num = cid.getAndIncrement();
new ClaimOut().cid(num).type("hello").postTo(project);
claims.remove(num);
return true;
},
new RunsInThreads<>(new AtomicInteger(), threads)
);
MatcherAssert.assertThat(
new Footprint(farm, project).collection().count(),
Matchers.equalTo((long) threads)
);
} | #vulnerable code
@Test
public void recordsChangesToClaims() throws Exception {
final Bucket bucket = new FkBucket(
Files.createTempDirectory("").toFile(),
"the-bucket"
);
try (final FakeMongo mongo = new FakeMongo().start()) {
final Project project = new SyncFarm(
new FtFarm(new S3Farm(bucket), mongo.client())
).find("@id='ABCZZFE03'").iterator().next();
final Claims claims = new Claims(project);
final AtomicLong cid = new AtomicLong(1L);
final int threads = 10;
MatcherAssert.assertThat(
inc -> {
final long num = cid.getAndIncrement();
new ClaimOut().cid(num).type("hello").postTo(project);
claims.remove(num);
return true;
},
new RunsInThreads<>(new AtomicInteger(), threads)
);
MatcherAssert.assertThat(
mongo.client().getDatabase("footprint")
.getCollection("claims")
.count(),
Matchers.equalTo((long) threads)
);
}
}
#location 24
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void rechargeIsRequiredIfCashBalanceIsLessThanLocked()
throws Exception {
final Project project = new FkProject();
final String job = "gh:test/test#1";
new Wbs(project).bootstrap().add(job);
final PropsFarm farm = new PropsFarm();
new Orders(farm, project).bootstrap()
.assign(job, "perf", UUID.randomUUID().toString());
new Estimates(farm, project).bootstrap()
.update(job, new Cash.S("$100"));
new Ledger(farm, project).bootstrap().add(
new Ledger.Transaction(
new Cash.S("$10"),
"assets", "cash",
"income", "test",
"Recharge#required test"
)
);
MatcherAssert.assertThat(
new Recharge(new PropsFarm(), project).required(),
new IsEqual<>(true)
);
} | #vulnerable code
@Test
public void rechargeIsRequiredIfCashBalanceIsLessThanLocked()
throws Exception {
final Project project = new FkProject();
final String job = "gh:test/test#1";
new Wbs(project).bootstrap().add(job);
final PropsFarm farm = new PropsFarm();
new Orders(farm, project).bootstrap().assign(job, "perf", "0");
new Estimates(farm, project).bootstrap()
.update(job, new Cash.S("$100"));
new Ledger(farm, project).bootstrap().add(
new Ledger.Transaction(
new Cash.S("$10"),
"assets", "cash",
"income", "test",
"Recharge#required test"
)
);
MatcherAssert.assertThat(
new Recharge(new PropsFarm(), project).required(),
new IsEqual<>(true)
);
}
#location 20
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void rendersIndexPage() throws Exception {
final Farm farm = FkFarm.props();
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(new View(farm, "/").xml()),
XhtmlMatchers.hasXPaths("/page/alive")
);
} | #vulnerable code
@Test
public void rendersIndexPage() throws Exception {
final Farm farm = new FtFarm(new PropsFarm(new FkFarm()));
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(new View(farm, "/").xml()),
XhtmlMatchers.hasXPaths("/page/alive")
);
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@SuppressWarnings("unchecked")
public void exec() throws IOException {
Logger.info(this, "Farm is ready to start");
final ShutdownFarm.Hook shutdown = new ShutdownFarm.Hook();
final ClaimGuts cgts = new ClaimGuts();
final TestLocks locks = new TestLocks();
try (
final MessageSink farm = new MessageSink(
new ShutdownFarm(
new ClaimsFarm(
new TempFiles.Farm(
new SmartFarm(
new S3Farm(new ExtBucket().value(), locks),
locks
)
),
cgts
),
shutdown
),
shutdown
);
final SlackRadar radar = new SlackRadar(farm);
final ClaimsRoutine claims = new ClaimsRoutine(farm)
) {
new ExtMongobee(farm).apply();
farm.start(claims.messages());
cgts.add(claims.messages());
claims.start(shutdown);
new AsyncFunc<>(
input -> {
new ExtTelegram(farm).value();
}
).exec(null);
new AsyncFunc<>(
input -> {
radar.refresh();
}
).exec(null);
new GithubRoutine(farm).start();
new Pings(farm).start();
new FtCli(
new TkApp(
farm,
new FkRegex("/alias", new TkAlias(farm)),
new FkRegex("/slack", new TkSlack(farm, radar)),
new FkRegex("/viber", new TkViber(farm)),
new FkRegex(
"/ghook",
new TkMethods(
new TkSentry(farm, new TkGithub(farm)),
HttpMethod.POST
)
),
new FkRegex(
"/glhook",
new TkMethods(
new TkSentry(farm, new TkGitlab()),
HttpMethod.POST
)
),
new FkRegex(
"/zcallback",
new TkZoldCallback(farm)
)
),
this.arguments
).start(Exit.NEVER);
}
} | #vulnerable code
@SuppressWarnings("unchecked")
public void exec() throws IOException {
final Path temp = Paths.get("./s3farm").normalize();
if (!temp.toFile().mkdir()) {
throw new IllegalStateException(
String.format(
"Failed to mkdir \"%s\"", temp
)
);
}
Logger.info(this, "Farm is ready to start");
final ShutdownFarm.Hook shutdown = new ShutdownFarm.Hook();
final ClaimGuts cgts = new ClaimGuts();
final TestLocks locks = new TestLocks();
try (
final MessageSink farm = new MessageSink(
new ShutdownFarm(
new ClaimsFarm(
new TempFiles.Farm(
new SmartFarm(
new S3Farm(new ExtBucket().value(), locks),
locks
)
),
cgts
),
shutdown
),
shutdown
);
final SlackRadar radar = new SlackRadar(farm);
final ClaimsRoutine claims = new ClaimsRoutine(farm)
) {
new ExtMongobee(farm).apply();
farm.start(claims.messages());
cgts.add(claims.messages());
claims.start(shutdown);
new AsyncFunc<>(
input -> {
new ExtTelegram(farm).value();
}
).exec(null);
new AsyncFunc<>(
input -> {
radar.refresh();
}
).exec(null);
new GithubRoutine(farm).start();
new Pings(farm).start();
new FtCli(
new TkApp(
farm,
new FkRegex("/alias", new TkAlias(farm)),
new FkRegex("/slack", new TkSlack(farm, radar)),
new FkRegex("/viber", new TkViber(farm)),
new FkRegex(
"/ghook",
new TkMethods(
new TkSentry(farm, new TkGithub(farm)),
HttpMethod.POST
)
),
new FkRegex(
"/glhook",
new TkMethods(
new TkSentry(farm, new TkGitlab()),
HttpMethod.POST
)
),
new FkRegex(
"/zcallback",
new TkZoldCallback(farm)
)
),
this.arguments
).start(Exit.NEVER);
}
}
#location 21
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public double take(final String login, final StringBuilder log)
throws IOException {
final int total = new Agenda(this.pmo, login).bootstrap().jobs().size();
final double rate;
final int max = new Options(this.pmo, login).bootstrap()
.maxJobsInAgenda();
if (total >= max) {
rate = 1.0d;
log.append(
String.format(
"%d job(s) already, maxJobsInAgenda option is %d",
total, max
)
);
} else {
rate = 0.0d;
log.append(
String.format(
"%d job(s) out of %d from maxJobsInAgenda option",
total, max
)
);
}
return rate;
} | #vulnerable code
@Override
public double take(final String login, final StringBuilder log)
throws IOException {
final int total = new Agenda(this.pmo, login).bootstrap().jobs().size();
final double rate;
final int max = new Options(this.pmo, login).bootstrap()
.maxJobsInAgenda();
if (total >= max) {
rate = 1.0d;
log.append(
new Par(
"%d job(s) already, maxJobsInAgenda option is %d"
).say(total, max)
);
} else {
rate = 0.0d;
log.append(
new Par(
"%d job(s) out of %d from maxJobsInAgenda option"
).say(total, max)
);
}
return rate;
}
#location 13
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public boolean pause(final String pid) throws IOException {
this.checkExist(pid);
try (final Item item = this.item()) {
return !Boolean.parseBoolean(
new Xocument(item.path()).xpath(
String.format(
"/catalog/project[@id='%s']/alive/text()",
pid
)
).get(0)
);
}
} | #vulnerable code
public boolean pause(final String pid) throws IOException {
if (!this.exists(pid)) {
throw new IllegalArgumentException(
new Par("Project %s doesn't exist").say(pid)
);
}
try (final Item item = this.item()) {
return !Boolean.parseBoolean(
new Xocument(item.path()).xpath(
String.format(
"/catalog/project[@id='%s']/alive/text()",
pid
)
).get(0)
);
}
}
#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 modifiesProject() throws Exception {
final Item item = new FkItem();
final String pid = "34EA54SZZ";
try (final Catalog catalog = new Catalog(item)) {
catalog.bootstrap();
catalog.add("34EA54SW9");
catalog.add("34EA54S87");
catalog.add(pid);
catalog.add("34EA54S8F");
}
try (final Item citem = new CatalogItem(
item, String.format("//project[@id!='%s']", pid)
)) {
new Xocument(citem.path()).modify(
new Directives()
.xpath("/catalog/project")
.add("link")
.attr("rel", "github")
.attr("href", "yegor256/pdd")
);
}
try (final Item citem = new CatalogItem(
item, String.format("//project[@id!='%s' ]", pid)
)) {
MatcherAssert.assertThat(
new Xocument(citem.path()).xpath(
"//project/link[@rel]/@href"
),
Matchers.not(Matchers.emptyIterable())
);
}
MatcherAssert.assertThat(
new Xocument(item.path()).xpath(
"//project[not(link)]/@id"
),
Matchers.not(Matchers.emptyIterable())
);
} | #vulnerable code
@Test
public void modifiesProject() throws Exception {
final Item item = new FkItem();
final Catalog catalog = new Catalog(item);
catalog.bootstrap();
catalog.add("34EA54SW9", "2017/01/34EA54SW9/");
catalog.add("34EA54S87", "2017/01/34EA54S87/");
final String pfx = "2017/01/34EA54SZZ/";
catalog.add("34EA54SZZ", pfx);
final String prefix = "2017/01/44EAFFPW3/";
catalog.add("44EAFFPW3", prefix);
try (final Item citem = new CatalogItem(item, prefix)) {
new Xocument(citem.path()).modify(
new Directives()
.xpath("/catalog/project")
.add("link")
.attr("rel", "github")
.attr("href", "yegor256/pdd")
);
}
try (final Item citem = new CatalogItem(item, prefix)) {
MatcherAssert.assertThat(
new Xocument(citem.path()).xpath(
"//project/link[@rel]/@href"
),
Matchers.not(Matchers.emptyIterable())
);
}
try (final Item citem = new CatalogItem(item, pfx)) {
MatcherAssert.assertThat(
new Xocument(citem.path()).xpath(
"//project[not(link)]/id/text()"
),
Matchers.not(Matchers.emptyIterable())
);
}
}
#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 removesImpediment() throws Exception {
final Project project = new FkProject();
final PropsFarm farm = new PropsFarm();
final Impediments imp = new Impediments(farm, project).bootstrap();
final String job = "gh:test/test#2";
new Wbs(project).bootstrap().add(job);
new Orders(farm, project).bootstrap()
.assign(job, "amihaiemil", UUID.randomUUID().toString());
imp.register(job, "reason");
MatcherAssert.assertThat(
imp.jobs(),
Matchers.contains(job)
);
MatcherAssert.assertThat(
imp.exists(job),
Matchers.is(true)
);
imp.remove(job);
MatcherAssert.assertThat(
imp.jobs(),
Matchers.not(Matchers.contains(job))
);
MatcherAssert.assertThat(
imp.exists(job),
Matchers.is(false)
);
} | #vulnerable code
@Test
public void removesImpediment() throws Exception {
final Project project = new FkProject();
final PropsFarm farm = new PropsFarm();
final Impediments imp = new Impediments(farm, project).bootstrap();
final String job = "gh:test/test#2";
new Wbs(project).bootstrap().add(job);
new Orders(farm, project).bootstrap().assign(job, "amihaiemil", "0");
imp.register(job, "reason");
MatcherAssert.assertThat(
imp.jobs(),
Matchers.contains(job)
);
MatcherAssert.assertThat(
imp.exists(job),
Matchers.is(true)
);
imp.remove(job);
MatcherAssert.assertThat(
imp.jobs(),
Matchers.not(Matchers.contains(job))
);
MatcherAssert.assertThat(
imp.exists(job),
Matchers.is(false)
);
}
#location 15
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void wallet(final String uid, final String bank,
final String wallet) throws IOException {
if (!bank.matches("paypal|btc|bch|eth|ltc")) {
throw new SoftException(
new Par(
"Bank name `%s` is invalid, we accept only",
"`paypal`, `btc`, `bch`, `eth`, or `ltc`, see §20"
).say(bank)
);
}
if ("paypal".equals(wallet)
&& !wallet.matches("\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b")) {
throw new SoftException(
new Par("Email `%s` is not valid").say(wallet)
);
}
if ("btc".equals(wallet)
&& !wallet.matches("(1|3|bc1)[a-zA-Z0-9]{20,40}")) {
throw new SoftException(
new Par("Bitcoin address is not valid: `%s`").say(wallet)
);
}
if ("bch".equals(wallet)
&& !wallet.matches("[pq]{41}")) {
throw new SoftException(
new Par("Bitcoin Cash address is not valid: `%s`").say(wallet)
);
}
if ("eth".equals(wallet)
&& !wallet.matches("[0-9a-f]{42}")) {
throw new SoftException(
new Par("Etherium address is not valid: `%s`").say(wallet)
);
}
if ("ltc".equals(wallet)
&& !wallet.matches("[0-9a-zA-Z]{35}")) {
throw new SoftException(
new Par("Litecoin address is not valid: `%s`").say(wallet)
);
}
try (final Item item = this.item()) {
new Xocument(item.path()).modify(
People.start(uid)
.addIf("wallet")
.set(wallet)
.attr("bank", bank)
);
}
} | #vulnerable code
public void wallet(final String uid, final String bank,
final String wallet) throws IOException {
if (!bank.matches("paypal")) {
throw new SoftException(
new Par(
"Bank name `%s` is invalid,",
"we accept only `paypal`, see §20"
).say(bank)
);
}
final Pattern email = Pattern.compile(
"\\b[\\w.%-]+@[-.\\w]+\\.[A-Za-z]{2,4}\\b"
);
if (!email.matcher(wallet).matches()) {
throw new SoftException(
String.format(
"Email `%s` is not valid",
wallet
)
);
}
try (final Item item = this.item()) {
new Xocument(item.path()).modify(
People.start(uid)
.addIf("wallet")
.set(wallet)
.attr("bank", bank)
);
}
}
#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 rendersAllPossibleUrls() throws Exception {
final Take take = new TkApp(FkFarm.props());
MatcherAssert.assertThat(
this.url,
take.act(new RqFake("GET", this.url)),
Matchers.not(
new HmRsStatus(
HttpURLConnection.HTTP_NOT_FOUND
)
)
);
} | #vulnerable code
@Test
public void rendersAllPossibleUrls() throws Exception {
final Take take = new TkApp(new PropsFarm(new FkFarm()));
MatcherAssert.assertThat(
this.url,
take.act(new RqFake("GET", this.url)),
Matchers.not(
new HmRsStatus(
HttpURLConnection.HTTP_NOT_FOUND
)
)
);
}
#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 acceptRequestAndRedirectOnPost() throws Exception {
final Farm farm = FkFarm.props();
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
new RqWithUser.WithInit(
farm,
new RqFake("POST", "/join-post")
),
"personality=INTJ-A&stackoverflow=187141"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/join")
)
);
} | #vulnerable code
@Test
public void acceptRequestAndRedirectOnPost() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
new RqWithUser.WithInit(
farm,
new RqFake("POST", "/join-post")
),
"personality=INTJ-A&stackoverflow=187141"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/join")
)
);
}
#location 4
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public boolean hasLink(final String pid, final String rel,
final String href) throws IOException {
this.checkExist(pid);
try (final Item item = this.item()) {
return !new Xocument(item.path()).nodes(
String.format(
// @checkstyle LineLength (1 line)
"/catalog/project[@id='%s' and links/link[@rel='%s' and @href='%s']]",
pid, rel, href
)
).isEmpty();
}
} | #vulnerable code
public boolean hasLink(final String pid, final String rel,
final String href) throws IOException {
if (!this.exists(pid)) {
throw new IllegalArgumentException(
new Par(
"Project %s doesn't exist, can't check link"
).say(pid)
);
}
try (final Item item = this.item()) {
return !new Xocument(item.path()).nodes(
String.format(
// @checkstyle LineLength (1 line)
"/catalog/project[@id='%s' and links/link[@rel='%s' and @href='%s']]",
pid, rel, href
)
).isEmpty();
}
}
#location 7
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public Cash fee(final String pid) throws IOException {
this.checkExist(pid);
try (final Item item = this.item()) {
final Iterator<String> fees = new Xocument(item.path()).xpath(
String.format("/catalog/project[@id='%s']/fee/text()", pid)
).iterator();
final Cash fee;
if (fees.hasNext()) {
fee = new Cash.S(fees.next());
} else {
fee = Cash.ZERO;
}
return fee;
}
} | #vulnerable code
public Cash fee(final String pid) throws IOException {
if (!this.exists(pid)) {
throw new IllegalArgumentException(
new Par(
"Project %s doesn't exist, can't get fee"
).say(pid)
);
}
try (final Item item = this.item()) {
final Iterator<String> fees = new Xocument(item.path()).xpath(
String.format("/catalog/project[@id='%s']/fee/text()", pid)
).iterator();
final Cash fee;
if (fees.hasNext()) {
fee = new Cash.S(fees.next());
} else {
fee = Cash.ZERO;
}
return fee;
}
}
#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 parsesJson() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final Take take = new TkGithub(
farm, (frm, github, event) -> "nothing"
);
MatcherAssert.assertThat(
take.act(
new RqWithBody(
new RqFake("POST", "/"),
String.format(
"payload=%s",
URLEncoder.encode(
"{\"foo\": \"bar\"}",
StandardCharsets.UTF_8.displayName()
)
)
)
),
new HmRsStatus(HttpURLConnection.HTTP_OK)
);
} | #vulnerable code
@Test
public void parsesJson() throws Exception {
MatcherAssert.assertThat(
new TkGithub(
new PropsFarm(),
new Rebound.Fake("nothing")
).act(
new RqWithBody(
new RqFake("POST", "/"),
String.format(
"payload=%s",
URLEncoder.encode(
"{\"foo\": \"bar\"}",
StandardCharsets.UTF_8.displayName()
)
)
)
),
new HmRsStatus(HttpURLConnection.HTTP_OK)
);
}
#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 rendersHtmlAwardsPageForFirefox() throws Exception {
final Farm farm = FkFarm.props();
final String user = "yegor256";
final int points = 1234;
new Awards(farm, user).bootstrap()
.add(new FkProject(), points, "none", "reason");
final String html = new View(
farm, String.format("/u/%s/awards", user)
).html();
MatcherAssert.assertThat(
html,
XhtmlMatchers.hasXPaths("//xhtml:html")
);
MatcherAssert.assertThat(
html,
Matchers.containsString(String.format("+%d", points))
);
} | #vulnerable code
@Test
public void rendersHtmlAwardsPageForFirefox() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final String user = "yegor256";
final int points = 1234;
new Awards(farm, user).bootstrap()
.add(new FkProject(), points, "none", "reason");
final String html = new View(
farm, String.format("/u/%s/awards", user)
).html();
MatcherAssert.assertThat(
html,
XhtmlMatchers.hasXPaths("//xhtml:html")
);
MatcherAssert.assertThat(
html,
Matchers.containsString(String.format("+%d", points))
);
}
#location 10
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void retrievesProps() throws Exception {
MatcherAssert.assertThat(
new Props(FkFarm.props()).get("/props/testing"),
Matchers.equalTo("yes")
);
} | #vulnerable code
@Test
public void retrievesProps() throws Exception {
MatcherAssert.assertThat(
new Props(new PropsFarm(new FkFarm())).get("/props/testing"),
Matchers.equalTo("yes")
);
}
#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 givesBonus() throws Exception {
final Speed speed = new Speed(
new FkFarm(new FkProject()), "amihaiemil"
).bootstrap();
final String job = "gh:bonus/fast#1";
speed.add("TST100006", job, Duration.ofDays(1).toMinutes());
MatcherAssert.assertThat(speed.bonus(job), Matchers.equalTo(Tv.FIVE));
} | #vulnerable code
@Test
public void givesBonus() throws Exception {
final FkProject project = new FkProject();
final FkFarm farm = new FkFarm(project);
final Speed speed = new Speed(farm, "amihaiemil").bootstrap();
final String job = "gh:bonus/fast#1";
speed.add("TST100006", job, Tv.THOUSAND);
MatcherAssert.assertThat(speed.bonus(job), Matchers.equalTo(Tv.FIVE));
}
#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 parsesJson() throws Exception {
MatcherAssert.assertThat(
new TkGithub(
new PropsFarm(),
new Rebound.Fake("nothing")
).act(
new RqWithBody(
new RqFake("POST", "/"),
String.format(
"payload=%s",
URLEncoder.encode(
"{\"foo\": \"bar\"}",
StandardCharsets.UTF_8.displayName()
)
)
)
),
new HmRsStatus(HttpURLConnection.HTTP_OK)
);
} | #vulnerable code
@Test
public void parsesJson() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final Take take = new TkGithub(
farm, (frm, github, event) -> "nothing"
);
MatcherAssert.assertThat(
take.act(
new RqWithBody(
new RqFake("POST", "/"),
String.format(
"payload=%s",
URLEncoder.encode(
"{\"foo\": \"bar\"}",
StandardCharsets.UTF_8.displayName()
)
)
)
),
new HmRsStatus(HttpURLConnection.HTTP_OK)
);
}
#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 rejectsIfAlreadyApplied() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final People people = new People(farm).bootstrap();
final String uid = "yegor256";
people.touch(uid);
people.apply(uid, Instant.now());
final RqWithUser req = new RqWithUser(
farm,
new RqFake("POST", "/join-post")
);
people.breakup(uid);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
req,
"personality=INTJ-A&stackoverflow=187241"
)
),
new HmRsHeader("Set-Cookie", Matchers.iterableWithSize(2))
);
} | #vulnerable code
@Test
public void rejectsIfAlreadyApplied() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final People people = new People(farm).bootstrap();
final String uid = "yegor256";
people.touch(uid);
people.apply(uid, new Date());
final RqWithUser req = new RqWithUser(
farm,
new RqFake("POST", "/join-post")
);
people.breakup(uid);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
req,
"personality=INTJ-A&stackoverflow=187241"
)
),
new HmRsHeader("Set-Cookie", Matchers.iterableWithSize(2))
);
}
#location 22
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void registerImpediment() throws Exception {
final Project project = new FkProject();
final Impediments imp = new Impediments(new PropsFarm(), project)
.bootstrap();
final String job = "gh:test/test#1";
new Wbs(project).bootstrap().add(job);
new Orders(new PropsFarm(), project).bootstrap()
.assign(job, "yegor256", UUID.randomUUID().toString());
imp.register(job, "test");
MatcherAssert.assertThat(
imp.jobs(),
Matchers.contains(job)
);
MatcherAssert.assertThat(
imp.exists(job),
Matchers.is(true)
);
} | #vulnerable code
@Test
public void registerImpediment() throws Exception {
final Project project = new FkProject();
final Impediments imp = new Impediments(new PropsFarm(), project)
.bootstrap();
final String job = "gh:test/test#1";
new Wbs(project).bootstrap().add(job);
new Orders(new PropsFarm(), project).bootstrap()
.assign(job, "yegor256", "0");
imp.register(job, "test");
MatcherAssert.assertThat(
imp.jobs(),
Matchers.contains(job)
);
MatcherAssert.assertThat(
imp.exists(job),
Matchers.is(true)
);
}
#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 setsSpeed() throws Exception {
final People people =
new People(new FkFarm(new FkProject())).bootstrap();
final String uid = "speed";
people.invite(uid, uid);
final double speed = 5.5;
people.speed(uid, speed);
MatcherAssert.assertThat(
people.speed(uid),
Matchers.is(speed)
);
} | #vulnerable code
@Test
public void setsSpeed() throws Exception {
final FkFarm farm = new FkFarm(new FkProject());
final People people = new People(farm).bootstrap();
final String uid = "speed";
people.invite(uid, uid);
final double speed = 5.5;
people.speed(uid, speed);
MatcherAssert.assertThat(
people.speed(uid),
Matchers.is(speed)
);
}
#location 4
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public int reputation(final String uid) throws IOException {
this.checkExisting(uid);
try (final Item item = this.item()) {
return new NumberOf(
new Xocument(item.path()).xpath(
String.format(
"/people/person[@id='%s']/reputation/text()",
uid
),
"0"
)
).intValue();
}
} | #vulnerable code
public int reputation(final String uid) throws IOException {
if (!this.exists(uid)) {
throw new IllegalArgumentException(
new Par("Person @%s doesn't exist").say(uid)
);
}
try (final Item item = this.item()) {
return new NumberOf(
new Xocument(item.path()).xpath(
String.format(
"/people/person[@id='%s']/reputation/text()",
uid
),
"0"
)
).intValue();
}
}
#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 estimatesJobs() throws Exception {
final Project project = new FkProject();
final PropsFarm farm = new PropsFarm();
new Ledger(farm, project).bootstrap().add(
new Ledger.Transaction(
new Cash.S("$500"),
"assets", "cash",
"income", "sponsor",
"Funded by Stripe customer"
)
);
final Estimates estimates = new Estimates(farm, project).bootstrap();
final String first = "gh:yegor256/pdd#4";
new Wbs(project).bootstrap().add(first);
new Orders(farm, project).bootstrap()
.assign(first, "yegor256", UUID.randomUUID().toString());
estimates.update(first, new Cash.S("$45"));
MatcherAssert.assertThat(
estimates.get(first),
Matchers.equalTo(new Cash.S("$45.00"))
);
final String second = "gh:yegor256/pdd#1";
new Wbs(project).bootstrap().add(second);
new Orders(farm, project).bootstrap()
.assign(second, "yegor", UUID.randomUUID().toString());
estimates.update(second, new Cash.S("$100"));
MatcherAssert.assertThat(
estimates.total(),
Matchers.equalTo(new Cash.S("$145.00"))
);
} | #vulnerable code
@Test
public void estimatesJobs() throws Exception {
final Project project = new FkProject();
final PropsFarm farm = new PropsFarm();
new Ledger(farm, project).bootstrap().add(
new Ledger.Transaction(
new Cash.S("$500"),
"assets", "cash",
"income", "sponsor",
"Funded by Stripe customer"
)
);
final Estimates estimates = new Estimates(farm, project).bootstrap();
final String first = "gh:yegor256/pdd#4";
new Wbs(project).bootstrap().add(first);
new Orders(farm, project).bootstrap().assign(first, "yegor256", "0");
estimates.update(first, new Cash.S("$45"));
MatcherAssert.assertThat(
estimates.get(first),
Matchers.equalTo(new Cash.S("$45.00"))
);
final String second = "gh:yegor256/pdd#1";
new Wbs(project).bootstrap().add(second);
new Orders(farm, project).bootstrap().assign(second, "yegor", "0");
estimates.update(second, new Cash.S("$100"));
MatcherAssert.assertThat(
estimates.total(),
Matchers.equalTo(new Cash.S("$145.00"))
);
}
#location 27
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public String title(final String pid) throws IOException {
this.checkExist(pid);
try (final Item item = this.item()) {
final Iterator<String> items = new Xocument(item.path())
.xpath(
String.format(
"/catalog/project[@id = '%s']/title/text()",
pid
)
).iterator();
String title = pid;
if (items.hasNext()) {
title = items.next();
}
return title;
}
} | #vulnerable code
public String title(final String pid) throws IOException {
if (!this.exists(pid)) {
throw new IllegalArgumentException(
new Par(
"Project %s doesn't exist, can't get title"
).say(pid)
);
}
try (final Item item = this.item()) {
final Iterator<String> items = new Xocument(item.path())
.xpath(
String.format(
"/catalog/project[@id = '%s']/title/text()",
pid
)
).iterator();
String title = pid;
if (items.hasNext()) {
title = items.next();
}
return title;
}
}
#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 acceptsRelease() throws Exception {
final int id = 1;
final String tag = "0.0.1";
final Farm farm = new PropsFarm();
final Github github = new MkGithub().relogin("test");
github.repos().create(new Repos.RepoCreate("one", false));
MatcherAssert.assertThat(
new RbRelease().react(
farm,
github,
Json.createObjectBuilder()
.add(
"release",
Json.createObjectBuilder()
.add("tag_name", tag)
.add("id", id)
.add("published_at", "2018-04-06T07:00:00Z")
)
.add(
"repository",
Json.createObjectBuilder()
.add("full_name", "test/one")
).build()
),
Matchers.is(
String.format(
"Release published: %d (tag: %s)", id, tag
)
)
);
} | #vulnerable code
@Test
public void acceptsRelease() throws Exception {
final int id = 1;
final String tag = "0.0.1";
MatcherAssert.assertThat(
new RbRelease().react(
new FkFarm(),
new MkGithub(),
Json.createObjectBuilder()
.add(
"release",
Json.createObjectBuilder()
.add("tag_name", tag)
.add("id", id)
.add("published_at", "2018-04-06T07:00:00Z")
.build()
).build()
),
Matchers.is(
String.format(
"Release published: %d (tag: %s)", id, tag
)
)
);
}
#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 recordsChangesToClaims() throws Exception {
final Bucket bucket = new FkBucket(
Files.createTempDirectory("").toFile(),
"the-bucket"
);
final Farm farm = new SyncFarm(
new FtFarm(new PropsFarm(new S3Farm(bucket)))
);
final Project project = farm.find("@id='ABCZZFE03'").iterator().next();
final Claims claims = new Claims(project);
final AtomicLong cid = new AtomicLong(1L);
final int threads = 10;
MatcherAssert.assertThat(
inc -> {
final long num = cid.getAndIncrement();
new ClaimOut().cid(num).type("hello").postTo(project);
claims.remove(num);
return true;
},
new RunsInThreads<>(new AtomicInteger(), threads)
);
MatcherAssert.assertThat(
new Footprint(farm, project).collection().count(),
Matchers.equalTo((long) threads)
);
} | #vulnerable code
@Test
public void recordsChangesToClaims() throws Exception {
final Bucket bucket = new FkBucket(
Files.createTempDirectory("").toFile(),
"the-bucket"
);
try (final FakeMongo mongo = new FakeMongo().start()) {
final Project project = new SyncFarm(
new FtFarm(new S3Farm(bucket), mongo.client())
).find("@id='ABCZZFE03'").iterator().next();
final Claims claims = new Claims(project);
final AtomicLong cid = new AtomicLong(1L);
final int threads = 10;
MatcherAssert.assertThat(
inc -> {
final long num = cid.getAndIncrement();
new ClaimOut().cid(num).type("hello").postTo(project);
claims.remove(num);
return true;
},
new RunsInThreads<>(new AtomicInteger(), threads)
);
MatcherAssert.assertThat(
mongo.client().getDatabase("footprint")
.getCollection("claims")
.count(),
Matchers.equalTo((long) threads)
);
}
}
#location 10
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void reactsToMessage() throws Exception {
final Reaction reaction = Mockito.mock(Reaction.class);
final FkFarm farm = new FkFarm();
final VbBot bot = new VbBot();
final String callback = new TextOf(
TkViberTest.class.getResourceAsStream("message.json")
).asString();
new TkViber(farm, bot, reaction).act(
new RqWithBody(
new RqFake("POST", "/"),
callback
)
);
Mockito.verify(reaction)
.react(
Mockito.eq(bot), Mockito.eq(farm), Mockito.argThat(
event -> event.json()
.equals(
Json.createReader(new StringReader(callback))
.readObject()
)
)
);
} | #vulnerable code
@Test
public void reactsToMessage() throws Exception {
final Reaction reaction = Mockito.mock(Reaction.class);
new TkViber(new FkFarm(), reaction).act(
new RqWithBody(
new RqFake("POST", "/"),
new TextOf(
TkViberTest.class.getResourceAsStream("message.json")
).asString()
)
);
Mockito.verify(reaction)
.react(Mockito.any(), Mockito.any(), Mockito.any());
}
#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 rejectsIfAlreadyApplied() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final People people = new People(farm).bootstrap();
final String uid = "yegor256";
people.touch(uid);
people.apply(uid, Instant.now());
final RqWithUser req = new RqWithUser(
farm,
new RqFake("POST", "/join-post")
);
people.breakup(uid);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
req,
"personality=INTJ-A&stackoverflow=187241"
)
),
new HmRsHeader("Set-Cookie", Matchers.iterableWithSize(2))
);
} | #vulnerable code
@Test
public void rejectsIfAlreadyApplied() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final People people = new People(farm).bootstrap();
final String uid = "yegor256";
people.touch(uid);
people.apply(uid, new Date());
final RqWithUser req = new RqWithUser(
farm,
new RqFake("POST", "/join-post")
);
people.breakup(uid);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
req,
"personality=INTJ-A&stackoverflow=187241"
)
),
new HmRsHeader("Set-Cookie", Matchers.iterableWithSize(2))
);
}
#location 13
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@SuppressWarnings("unchecked")
public void exec() throws IOException {
final Props props = new Props();
if (props.has("//testing")) {
throw new IllegalStateException(
"Hey, we are in the testing mode!"
);
}
Sentry.init(props.get("//sentry/dsn", ""));
final Path temp = Paths.get("./s3farm").normalize();
if (!temp.toFile().mkdir()) {
throw new IllegalStateException(
String.format(
"Failed to mkdir \"%s\"", temp
)
);
}
try (
final Farm farm = new SmartFarm(
new S3Farm(new ExtBucket().value(), temp)
).value();
final SlackRadar radar = new SlackRadar(farm)
) {
new ExtMongobee(farm).apply();
new ExtTelegram(farm).value();
radar.refresh();
new GithubRoutine(farm).start();
new FtCli(
new TkApp(
farm,
new FkRegex("/slack", new TkSlack(farm, radar)),
new FkRegex("/alias", new TkAlias(farm)),
new FkRegex(
"/ghook",
new TkMethods(new TkGithub(farm), "POST")
)
),
this.arguments
).start(Exit.NEVER);
}
} | #vulnerable code
@SuppressWarnings("unchecked")
public void exec() throws IOException {
final Props props = new Props();
if (props.has("//testing")) {
throw new IllegalStateException(
"Hey, we are in the testing mode!"
);
}
Sentry.init(props.get("//sentry/dsn", ""));
try (
final Farm farm = new SmartFarm(
new S3Farm(new ExtBucket().value())
).value();
final SlackRadar radar = new SlackRadar(farm)
) {
new ExtMongobee(farm).apply();
new ExtTelegram(farm).value();
radar.refresh();
new GithubRoutine(farm).start();
new FtCli(
new TkApp(
farm,
new FkRegex("/slack", new TkSlack(farm, radar)),
new FkRegex("/alias", new TkAlias(farm)),
new FkRegex(
"/ghook",
new TkMethods(new TkGithub(farm), "POST")
)
),
this.arguments
).start(Exit.NEVER);
}
}
#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 rejectsIfAlreadyApplied() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final People people = new People(farm).bootstrap();
final String uid = "yegor256";
people.touch(uid);
people.apply(uid, Instant.now());
final Request req = new RqWithUser.WithInit(
farm,
new RqFake("POST", "/join-post")
);
people.breakup(uid);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
req,
"personality=INTJ-A&stackoverflow=187241"
)
),
new HmRsHeader("Set-Cookie", Matchers.iterableWithSize(2))
);
} | #vulnerable code
@Test
public void rejectsIfAlreadyApplied() throws Exception {
final Farm farm = FkFarm.props();
final People people = new People(farm).bootstrap();
final String uid = "yegor256";
people.touch(uid);
people.apply(uid, Instant.now());
final Request req = new RqWithUser.WithInit(
farm,
new RqFake("POST", "/join-post")
);
people.breakup(uid);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
req,
"personality=INTJ-A&stackoverflow=187241"
)
),
new HmRsHeader("Set-Cookie", Matchers.iterableWithSize(2))
);
}
#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 rendersListOfClaims() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
new TkApp(farm).act(
new RqWithUser(
farm,
new RqFake(
"GET",
"/footprint/C00000000"
)
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("//xhtml:article")
);
} | #vulnerable code
@Test
public void rendersListOfClaims() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final Catalog catalog = new Catalog(new Pmo(farm)).bootstrap();
final String pid = "A1B2C3D4F";
catalog.add(pid, String.format("2017/07/%s/", pid));
final Roles roles = new Roles(
farm.find(String.format("@id='%s'", pid)).iterator().next()
).bootstrap();
final String uid = "yegor256";
new People(new Pmo(farm)).bootstrap().invite(uid, "mentor");
roles.assign(uid, "PO");
final Take take = new TkApp(farm);
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
take.act(
new RqWithHeaders(
new RqFake(
"GET",
String.format("/footprint/%s", pid)
),
// @checkstyle LineLength (1 line)
"Cookie: PsCookie=0975A5A5-F6DB193E-AF18000A-75726E3A-74657374-3A310005-6C6F6769-6E000879-65676F72-323536AE"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("//xhtml:article")
);
}
#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 parsesJson() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final Take take = new TkGithub(
farm, (frm, github, event) -> "nothing"
);
MatcherAssert.assertThat(
take.act(
new RqWithBody(
new RqFake("POST", "/"),
String.format(
"payload=%s",
URLEncoder.encode(
"{\"foo\": \"bar\"}",
StandardCharsets.UTF_8.displayName()
)
)
)
),
new HmRsStatus(HttpURLConnection.HTTP_OK)
);
} | #vulnerable code
@Test
public void parsesJson() throws Exception {
MatcherAssert.assertThat(
new TkGithub(
new PropsFarm(),
new Rebound.Fake("nothing")
).act(
new RqWithBody(
new RqFake("POST", "/"),
String.format(
"payload=%s",
URLEncoder.encode(
"{\"foo\": \"bar\"}",
StandardCharsets.UTF_8.displayName()
)
)
)
),
new HmRsStatus(HttpURLConnection.HTTP_OK)
);
}
#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 rendersAgendaPage() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
new TkApp(farm).act(
new RqWithUser(
farm,
new RqFake("GET", "/u/Yegor256/agenda")
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("//xhtml:body")
);
} | #vulnerable code
@Test
public void rendersAgendaPage() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final String uid = "yegor256";
final People people = new People(farm).bootstrap();
people.touch(uid);
people.invite(uid, "mentor");
final Take take = new TkApp(farm);
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
take.act(
new RqWithHeaders(
new RqFake("GET", "/u/Yegor256/agenda"),
// @checkstyle LineLength (1 line)
"Cookie: PsCookie=0975A5A5-F6DB193E-AF18000A-75726E3A-74657374-3A310005-6C6F6769-6E000879-65676F72-323536AE"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("//xhtml:body")
);
}
#location 23
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void jobs(final String uid, final int jobs)
throws IOException {
this.checkExisting(uid);
try (final Item item = this.item()) {
new Xocument(item.path()).modify(
new Directives().xpath(
String.format(
"/people/person[@id='%s']",
uid
)
).addIf("jobs").set(jobs)
);
}
} | #vulnerable code
public void jobs(final String uid, final int jobs)
throws IOException {
if (!this.exists(uid)) {
throw new IllegalArgumentException(
new Par("Person @%s doesn't exist").say(uid)
);
}
try (final Item item = this.item()) {
new Xocument(item.path()).modify(
new Directives().xpath(
String.format(
"/people/person[@id='%s']",
uid
)
).addIf("jobs").set(jobs)
);
}
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public Response act(final RqRegex req) throws IOException {
final Project project = new RqProject(this.farm, req, "PO");
final RqFormSmart form = new RqFormSmart(new RqGreedy(req));
final String email = form.single("email");
final Cash amount = new Cash.S(
String.format(
"USD %.2f",
// @checkstyle MagicNumber (1 line)
Double.parseDouble(form.single("cents")) / 100.0d
)
);
final Stripe stripe = new Stripe(this.farm);
final String customer;
final String pid;
try {
customer = stripe.register(
form.single("token"), email
);
pid = stripe.charge(
customer, amount,
new Par(this.farm, "Project %s funded").say(project.pid())
);
} catch (final Stripe.PaymentException ex) {
throw new RsForward(
new RsParFlash(ex),
String.format("/p/%s", project.pid())
);
}
final String user = new RqUser(this.farm, req).value();
new ClaimOut()
.type("Funded by Stripe")
.param("amount", amount)
.param("stripe_customer", customer)
.param("payment_id", pid)
.param("email", email)
.author(user)
.postTo(project);
new ClaimOut().type("Notify PMO").param(
"message", new Par(
"Project %s was funded for %s by @%s;",
"customer `%s`, payment `%s`"
).say(project.pid(), amount, user, customer, pid)
).postTo(this.farm);
return new RsForward(
new RsParFlash(
new Par(
"The project %s was successfully funded for %s;",
"the ledger will be updated in a few minutes;",
"payment ID is `%s`"
).say(project.pid(), amount, pid),
Level.INFO
),
String.format("/p/%s", project.pid())
);
} | #vulnerable code
@Override
public Response act(final RqRegex req) throws IOException {
final Project project = new RqProject(this.farm, req, "PO");
final RqFormSmart form = new RqFormSmart(new RqGreedy(req));
final String email = form.single("email");
final String customer;
try {
customer = new Stripe(this.farm).pay(
form.single("token"),
email,
String.format(
"%s/%s",
project.pid(),
new Catalog(this.farm).title(project.pid())
)
);
} catch (final Stripe.PaymentException ex) {
throw new RsForward(
new RsParFlash(ex),
String.format("/p/%s", project.pid())
);
}
final Cash amount = new Cash.S(
String.format(
"USD %.2f",
// @checkstyle MagicNumber (1 line)
Double.parseDouble(form.single("cents")) / 100.0d
)
);
final String user = new RqUser(this.farm, req).value();
new ClaimOut()
.type("Funded by Stripe")
.param("amount", amount)
.param("stripe_customer", customer)
.param("email", email)
.author(user)
.postTo(project);
new ClaimOut().type("Notify PMO").param(
"message", new Par(
"Project %s was funded for %s by @%s"
).say(project.pid(), amount, user)
).postTo(this.farm);
return new RsForward(
new RsParFlash(
new Par(
"The project %s was successfully funded for %s.",
"The ledger will be updated in a few minutes."
).say(project.pid(), amount),
Level.INFO
),
String.format("/p/%s", project.pid())
);
}
#location 41
#vulnerability type RESOURCE_LEAK | 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 AdaptivePaymentsService service = new AdaptivePaymentsService(
new SolidMap<String, String>(
new MapEntry<>("mode", props.get("//paypal/mode")),
new MapEntry<>(
"acct1.UserName",
props.get("//paypal/username")
),
new MapEntry<>(
"acct1.Password",
props.get("//paypal/password")
),
new MapEntry<>(
"acct1.Signature",
props.get("//paypal/signature")
),
new MapEntry<>(
"acct1.AppId",
props.get("//paypal/appid")
)
)
);
try {
return Paypal.valid(
service.pay(
this.request(
target,
amount.decimal().doubleValue(),
details
)
)
).getPayKey();
} catch (final SSLConfigurationException
| InvalidCredentialException
| InvalidResponseDataException
| InterruptedException
| ClientActionRequiredException
| MissingCredentialException
| OAuthException
| HttpErrorException | IOException ex) {
throw new IOException(
String.format(
"Failed to pay %s to %s with memo \"%s\": %s %s",
amount, target, details,
ex.getClass().getName(), ex.getMessage()
),
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 PayPal commission"
).say(amount)
);
}
final Props props = new Props(this.farm);
final AdaptivePaymentsService service = new AdaptivePaymentsService(
new SolidMap<String, String>(
new MapEntry<>("mode", props.get("//paypal/mode")),
new MapEntry<>(
"acct1.UserName",
props.get("//paypal/username")
),
new MapEntry<>(
"acct1.Password",
props.get("//paypal/password")
),
new MapEntry<>(
"acct1.Signature",
props.get("//paypal/signature")
),
new MapEntry<>(
"acct1.AppId",
props.get("//paypal/appid")
)
)
);
try {
return Paypal.valid(
service.pay(
this.request(
target,
amount.decimal().doubleValue(),
details
)
)
).getPayKey();
} catch (final SSLConfigurationException
| InvalidCredentialException
| InvalidResponseDataException
| InterruptedException
| ClientActionRequiredException
| MissingCredentialException
| OAuthException
| HttpErrorException | IOException ex) {
throw new IOException(
String.format(
"Failed to pay %s to %s with memo \"%s\": %s %s",
amount, target, details,
ex.getClass().getName(), ex.getMessage()
),
ex
);
}
}
#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 removesOrder() throws Exception {
final Project project = new FkProject();
final Orders orders = new Orders(new PropsFarm(), project).bootstrap();
final String job = "gh:yegor256/0pdd#13";
new Wbs(project).bootstrap().add(job);
orders.assign(job, "yegor256", UUID.randomUUID().toString());
orders.remove(job);
MatcherAssert.assertThat(
"Order not removed",
orders.iterate(),
new IsEmptyCollection<>()
);
} | #vulnerable code
@Test
public void removesOrder() throws Exception {
final Project project = new FkProject();
final Orders orders = new Orders(new PropsFarm(), project).bootstrap();
final String job = "gh:yegor256/0pdd#13";
new Wbs(project).bootstrap().add(job);
orders.assign(job, "yegor256", "0");
orders.remove(job);
MatcherAssert.assertThat(
"Order not removed",
orders.iterate(),
new IsEmptyCollection<>()
);
}
#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 acceptRequestAndRedirectOnPost() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
new RqWithUser.WithInit(
farm,
new RqFake("POST", "/join-post")
),
"personality=INTJ-A&stackoverflow=187141"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/join")
)
);
} | #vulnerable code
@Test
public void acceptRequestAndRedirectOnPost() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
new RqWithUser(
farm,
new RqFake("POST", "/join-post")
),
"personality=INTJ-A&stackoverflow=187141"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/join")
)
);
}
#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 rendersReport() throws Exception {
final Farm farm = new FtFarm(new PropsFarm(new FkFarm()));
final String uid = "yegor256";
new ClaimOut()
.type("Order was given")
.param("login", uid)
.postTo(farm.find("@id='C00000000'").iterator().next());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new View(
farm,
"/report/C00000000?report=orders-given-by-week"
).xml()
),
XhtmlMatchers.hasXPaths("/page/rows/row[week]")
);
} | #vulnerable code
@Test
public void rendersReport() throws Exception {
final Farm farm = new FtFarm(new PropsFarm(new FkFarm()));
final String uid = "yegor256";
new ClaimOut()
.type("Order was given")
.param("login", uid)
.postTo(farm.find("@id='C00000000'").iterator().next());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
new TkApp(farm).act(
new RqWithHeaders(
new RqWithUser(
farm,
new RqFake(
"GET",
// @checkstyle LineLength (1 line)
"/report/C00000000?report=orders-given-by-week"
)
),
"Accept: application/vnd.zerocracy+xml"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("/page/rows/row[week]")
);
}
#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 rendersProfilePageWithRateInFirefox() throws Exception {
final Farm farm = FkFarm.props();
final double rate = 99.99;
final People people = new People(farm).bootstrap();
people.rate(
"yegor256", new Cash.S(String.format("USD %f", rate))
);
MatcherAssert.assertThat(
new View(farm, "/u/yegor256").html(),
Matchers.containsString(
String.format(
"rate</a> is <span style=\"color:darkgreen\">$%.2f</span>",
rate
)
)
);
} | #vulnerable code
@Test
public void rendersProfilePageWithRateInFirefox() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final double rate = 99.99;
final People people = new People(farm).bootstrap();
people.rate(
"yegor256", new Cash.S(String.format("USD %f", rate))
);
MatcherAssert.assertThat(
new View(farm, "/u/yegor256").html(),
Matchers.containsString(
String.format(
"rate</a> is <span style=\"color:darkgreen\">$%.2f</span>",
rate
)
)
);
}
#location 18
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public Response act(final Request req) throws IOException {
final JsonObject callback = TkViber.json(
new TextOf(req.body()).asString()
);
if (callback.isEmpty()) {
throw new HttpException(HttpURLConnection.HTTP_BAD_REQUEST);
}
if (Objects.equals(callback.getString("event"), "message")) {
this.reaction.react(
this.bot, this.farm, new VbEvent.Simple(callback)
);
}
return new RsWithStatus(
HttpURLConnection.HTTP_OK
);
} | #vulnerable code
@Override
public Response act(final Request req) throws IOException {
final JsonObject callback = TkViber.json(
new InputStreamReader(req.body(), StandardCharsets.UTF_8)
);
if (callback.isEmpty()) {
throw new HttpException(HttpURLConnection.HTTP_BAD_REQUEST);
}
if (Objects.equals(callback.getString("event"), "message")) {
this.reaction.react(
this.bot, this.farm, new VbEvent.Simple(callback)
);
}
return new RsWithStatus(
HttpURLConnection.HTTP_OK
);
}
#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 rendersHomePage() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
new TkApp(farm).act(
new RqWithUser(
farm,
new RqFake(
"GET",
"/a/C00000000?a=pm/staff/roles"
)
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("//xhtml:table")
);
} | #vulnerable code
@Test
public void rendersHomePage() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final Catalog catalog = new Catalog(new Pmo(farm)).bootstrap();
final String pid = "A1B2C3D4F";
catalog.add(pid, String.format("2017/07/%s/", pid));
final Roles roles = new Roles(
farm.find(String.format("@id='%s'", pid)).iterator().next()
).bootstrap();
final String uid = "yegor256";
new People(new Pmo(farm)).bootstrap().invite(uid, "mentor");
roles.assign(uid, "PO");
final Take take = new TkApp(farm);
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
take.act(
new RqWithHeaders(
new RqFake(
"GET",
String.format("/a/%s?a=pm/staff/roles", pid)
),
// @checkstyle LineLength (1 line)
"Cookie: PsCookie=0975A5A5-F6DB193E-AF18000A-75726E3A-74657374-3A310005-6C6F6769-6E000879-65676F72-323536AE"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("//xhtml:table")
);
}
#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 rendersXmlAwardsPage() throws Exception {
final Farm farm = FkFarm.props();
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
XhtmlMatchers.xhtml(
new View(farm, "/u/yegor256/awards").html()
)
),
XhtmlMatchers.hasXPaths("//xhtml:body")
);
} | #vulnerable code
@Test
public void rendersXmlAwardsPage() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
XhtmlMatchers.xhtml(
new View(farm, "/u/yegor256/awards").html()
)
),
XhtmlMatchers.hasXPaths("//xhtml:body")
);
}
#location 7
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public double vote(final String login, final StringBuilder log)
throws IOException {
final int mine = this.jobs.value().get(login);
final int smaller = new Filtered<>(
speed -> speed < mine,
this.jobs.value().values()
).size();
log.append(
Logger.format(
"Workload of %d jobs is no.%d",
mine, smaller + 1
)
);
return 1.0d - (double) smaller / (double) this.jobs.value().size();
} | #vulnerable code
@Override
public double vote(final String login, final StringBuilder log)
throws IOException {
final int jobs = new LengthOf(
new Agenda(this.pmo, login).jobs()
).intValue();
log.append(
new Par(
"%d out of %d job(s) in agenda"
).say(jobs, this.max)
);
return (double) (this.max - Math.min(jobs, this.max))
/ (double) this.max;
}
#location 10
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public Response act(final RqRegex req) throws IOException {
final Project project = new RqProject(this.farm, req);
return new RsWithHeaders(
new RsWithType(
new RsWithBody(
this.getClass().getResource("badge.svg")
),
"image/svg+xml"
),
"Cache-Control: no-cache",
String.format("X-Zerocracy-Project-ID: %s", project.pid())
);
} | #vulnerable code
@Override
public Response act(final RqRegex req) throws IOException {
final String pid = req.matcher().group(1);
final Project pmo = new Pmo(this.farm);
final Catalog catalog = new Catalog(pmo).bootstrap();
if (!catalog.exists(pid)) {
throw new RsForward(
new RsParFlash(
new Par("Project %s not found").say(pid),
Level.WARNING
)
);
}
return new RsWithHeaders(
new RsWithType(
new RsWithBody(
this.getClass().getResource("badge.svg")
),
"image/svg+xml"
),
"Cache-Control: no-cache",
String.format("X-Zerocracy-Project-ID: %s", pid)
);
}
#location 9
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
@SuppressWarnings("unchecked")
public void showsThatUserAlreadyHasMentor() throws IOException {
final Farm farm = new PropsFarm(new FkFarm());
final People people = new People(farm).bootstrap();
final String mentor = "yoda";
final String applicant = "luke";
people.touch(mentor);
people.touch(applicant);
people.invite(applicant, mentor, true);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
new RqWithUser(
farm,
new RqFake("GET", "/join-post"),
applicant
),
"personality=INTJ-A&stackoverflow=187242"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/join"),
new HmRsHeader(
"Set-Cookie",
Matchers.hasItems(
Matchers.containsString(
URLEncoder.encode(
new FormattedText(
"You already have a mentor (@%s)",
mentor
).asString(),
StandardCharsets.UTF_8.displayName()
)
)
)
)
)
);
} | #vulnerable code
@Test
@SuppressWarnings("unchecked")
public void showsThatUserAlreadyHasMentor() throws IOException {
final Farm farm = FkFarm.props();
final People people = new People(farm).bootstrap();
final String mentor = "yoda";
final String applicant = "luke";
people.touch(mentor);
people.touch(applicant);
people.invite(applicant, mentor, true);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
new RqWithUser(
farm,
new RqFake("GET", "/join-post"),
applicant
),
"personality=INTJ-A&stackoverflow=187242"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/join"),
new HmRsHeader(
"Set-Cookie",
Matchers.hasItems(
Matchers.containsString(
URLEncoder.encode(
new FormattedText(
"You already have a mentor (@%s)",
mentor
).asString(),
StandardCharsets.UTF_8.displayName()
)
)
)
)
)
);
}
#location 11
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public Collection<String> links(final String pid) throws IOException {
this.checkExist(pid);
try (final Item item = this.item()) {
return new SolidList<>(
new Mapped<>(
xml -> String.format(
"%s:%s",
xml.xpath("@rel").get(0),
xml.xpath("@href").get(0)
),
new Xocument(item).nodes(
String.format(
"/catalog/project[@id='%s']/links/link",
pid
)
)
)
);
}
} | #vulnerable code
public Collection<String> links(final String pid) throws IOException {
if (!this.exists(pid)) {
throw new IllegalArgumentException(
new Par(
"Project %s doesn't exist, can't get links"
).say(pid)
);
}
try (final Item item = this.item()) {
return new SolidList<>(
new Mapped<>(
xml -> String.format(
"%s:%s",
xml.xpath("@rel").get(0),
xml.xpath("@href").get(0)
),
new Xocument(item).nodes(
String.format(
"/catalog/project[@id='%s']/links/link",
pid
)
)
)
);
}
}
#location 6
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void pause(final String pid,
final boolean pause) throws IOException {
this.checkExist(pid);
try (final Item item = this.item()) {
new Xocument(item.path()).modify(
new Directives().xpath(
String.format("/catalog/project[@id='%s']/alive", pid)
).strict(1).set(!pause)
);
}
} | #vulnerable code
public void pause(final String pid,
final boolean pause) throws IOException {
if (!this.exists(pid)) {
throw new IllegalArgumentException(
new Par("Project %s doesn't exist, can't pause").say(pid)
);
}
try (final Item item = this.item()) {
new Xocument(item.path()).modify(
new Directives().xpath(
String.format("/catalog/project[@id='%s']/alive", pid)
).strict(1).set(!pause)
);
}
}
#location 5
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public String adviser(final String pid) throws IOException {
this.checkExist(pid);
try (final Item item = this.item()) {
return new Xocument(item.path()).xpath(
String.format(
"/catalog/project[@id = '%s']/adviser/text()",
pid
)
).get(0);
}
} | #vulnerable code
public String adviser(final String pid) throws IOException {
if (!this.exists(pid)) {
throw new IllegalArgumentException(
new Par(
"Project %s doesn't exist, can't get adviser"
).say(pid)
);
}
try (final Item item = this.item()) {
return new Xocument(item.path()).xpath(
String.format(
"/catalog/project[@id = '%s']/adviser/text()",
pid
)
).get(0);
}
}
#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 rendersHomePage() throws Exception {
final Farm farm = FkFarm.props();
final String uid = "yegor";
new Awards(farm, uid).bootstrap().add(
new FkProject(), 1, "gh:test/test#1", "reason"
);
new Agenda(farm, uid).bootstrap().add(
new FkProject(), "gh:test/test#2", "QA"
);
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(new View(farm, "/u/Yegor256").html()),
XhtmlMatchers.hasXPaths("//xhtml:body")
);
} | #vulnerable code
@Test
public void rendersHomePage() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final String uid = "yegor";
new Awards(farm, uid).bootstrap().add(
new FkProject(), 1, "gh:test/test#1", "reason"
);
new Agenda(farm, uid).bootstrap().add(
new FkProject(), "gh:test/test#2", "QA"
);
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(new View(farm, "/u/Yegor256").html()),
XhtmlMatchers.hasXPaths("//xhtml:body")
);
}
#location 15
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public double take(final String login, final StringBuilder log)
throws IOException {
final int total = new Agenda(this.pmo, login).bootstrap().jobs().size();
final double rate;
final int max = new Options(this.pmo, login).bootstrap()
.maxJobsInAgenda();
if (total >= max) {
rate = 1.0d;
log.append(
String.format(
"%d job(s) already, maxJobsInAgenda option is %d",
total, max
)
);
} else {
rate = 0.0d;
log.append(
String.format(
"%d job(s) out of %d from maxJobsInAgenda option",
total, max
)
);
}
return rate;
} | #vulnerable code
@Override
public double take(final String login, final StringBuilder log)
throws IOException {
final int total = new Agenda(this.pmo, login).bootstrap().jobs().size();
final double rate;
final int max = new Options(this.pmo, login).bootstrap()
.maxJobsInAgenda();
if (total >= max) {
rate = 1.0d;
log.append(
new Par(
"%d job(s) already, maxJobsInAgenda option is %d"
).say(total, max)
);
} else {
rate = 0.0d;
log.append(
new Par(
"%d job(s) out of %d from maxJobsInAgenda option"
).say(total, max)
);
}
return rate;
}
#location 13
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public double speed(final String uid) throws IOException {
this.checkExisting(uid);
try (final Item item = this.item()) {
return new NumberOf(
new Xocument(item.path()).xpath(
String.format(
"/people/person[@id='%s']/speed/text()",
uid
),
"0.0"
)
).doubleValue();
}
} | #vulnerable code
public double speed(final String uid) throws IOException {
if (!this.exists(uid)) {
throw new IllegalArgumentException(
new Par("Person @%s doesn't exist").say(uid)
);
}
try (final Item item = this.item()) {
return new NumberOf(
new Xocument(item.path()).xpath(
String.format(
"/people/person[@id='%s']/speed/text()",
uid
),
"0.0"
)
).doubleValue();
}
}
#location 4
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public Collection<String> links(final String pid, final String rel)
throws IOException {
this.checkExist(pid);
try (final Item item = this.item()) {
return new Xocument(item).xpath(
String.format(
"/catalog/project[@id='%s']/links/link[@rel='%s']/@href",
pid, rel
)
);
}
} | #vulnerable code
public Collection<String> links(final String pid, final String rel)
throws IOException {
if (!this.exists(pid)) {
throw new IllegalArgumentException(
new Par(
"Project %s doesn't exist, can't get links"
).say(pid)
);
}
try (final Item item = this.item()) {
return new Xocument(item).xpath(
String.format(
"/catalog/project[@id='%s']/links/link[@rel='%s']/@href",
pid, rel
)
);
}
}
#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 rendersProfilePageWithRateInFirefox() throws Exception {
final Farm farm = FkFarm.props();
final double rate = 99.99;
final People people = new People(farm).bootstrap();
people.rate(
"yegor256", new Cash.S(String.format("USD %f", rate))
);
MatcherAssert.assertThat(
new View(farm, "/u/yegor256").html(),
Matchers.containsString(
String.format(
"rate</a> is <span style=\"color:darkgreen\">$%.2f</span>",
rate
)
)
);
} | #vulnerable code
@Test
public void rendersProfilePageWithRateInFirefox() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final double rate = 99.99;
final People people = new People(farm).bootstrap();
people.rate(
"yegor256", new Cash.S(String.format("USD %f", rate))
);
MatcherAssert.assertThat(
new View(farm, "/u/yegor256").html(),
Matchers.containsString(
String.format(
"rate</a> is <span style=\"color:darkgreen\">$%.2f</span>",
rate
)
)
);
}
#location 10
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void rendersSingleArtifact() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
new TkApp(farm).act(
new RqWithUser(
farm,
new RqFake(
"GET",
"/xml/C00000000?file=roles.xml"
)
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("/roles")
);
} | #vulnerable code
@Test
public void rendersSingleArtifact() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final Catalog catalog = new Catalog(new Pmo(farm)).bootstrap();
final String pid = "A1B2C3D4F";
catalog.add(pid, String.format("2017/07/%s/", pid));
final Roles roles = new Roles(
farm.find(String.format("@id='%s'", pid)).iterator().next()
).bootstrap();
final String uid = "yegor256";
roles.assign(uid, "PO");
new People(new Pmo(farm)).bootstrap().invite(uid, "mentor");
final Take take = new TkApp(farm);
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
take.act(
new RqWithHeaders(
new RqFake(
"GET",
String.format(
"/xml/%s?file=roles.xml", pid
)
),
// @checkstyle LineLength (1 line)
"Cookie: PsCookie=0975A5A5-F6DB193E-AF18000A-75726E3A-74657374-3A310005-6C6F6769-6E000879-65676F72-323536AE"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("/roles")
);
}
#location 13
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public Response act(final Request request) throws IOException {
return new RsWithType(
new RsWithBody(
new BufferedInputStream(
new HeapDump(this.bucket.value(), "").load()
)
),
"application/octet-stream"
);
} | #vulnerable code
@Override
public Response act(final Request request) throws IOException {
return new RsWithType(
new RsWithBody(
new BufferedInputStream(
new HeapDump(new ExtBucket().value(), "").load()
)
),
"application/octet-stream"
);
}
#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 registerImpediment() throws Exception {
final Project project = new FkProject();
final Impediments imp = new Impediments(new PropsFarm(), project)
.bootstrap();
final String job = "gh:test/test#1";
new Wbs(project).bootstrap().add(job);
new Orders(new PropsFarm(), project).bootstrap()
.assign(job, "yegor256", UUID.randomUUID().toString());
imp.register(job, "test");
MatcherAssert.assertThat(
imp.jobs(),
Matchers.contains(job)
);
MatcherAssert.assertThat(
imp.exists(job),
Matchers.is(true)
);
} | #vulnerable code
@Test
public void registerImpediment() throws Exception {
final Project project = new FkProject();
final Impediments imp = new Impediments(new PropsFarm(), project)
.bootstrap();
final String job = "gh:test/test#1";
new Wbs(project).bootstrap().add(job);
new Orders(new PropsFarm(), project).bootstrap()
.assign(job, "yegor256", "0");
imp.register(job, "test");
MatcherAssert.assertThat(
imp.jobs(),
Matchers.contains(job)
);
MatcherAssert.assertThat(
imp.exists(job),
Matchers.is(true)
);
}
#location 16
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public void exec(final Message input) throws Exception {
try (
final Footprint footprint = new Footprint(
this.farm, new SqsProject(this.farm, input)
)
) {
final XML xml = new XMLDocument(input.getBody())
.nodes("/claim").get(0);
Logger.info(
this, "Processing message %s",
input.getMessageId()
);
footprint.open(
xml,
input.getMessageAttributes().get("signature").getStringValue()
);
Logger.info(
this, "Claim was opened for message %s",
input.getMessageId()
);
this.origin.exec(input);
footprint.close(xml);
Logger.info(
this, "Claim was closed for message %s",
input.getMessageId()
);
}
} | #vulnerable code
@Override
public void exec(final Message input) throws Exception {
final Footprint footprint = new Footprint(
this.farm, new SqsProject(this.farm, input)
);
final XML xml = new XMLDocument(input.getBody())
.nodes("/claim").get(0);
Logger.info(
this, "Processing message %s", input.getMessageId()
);
footprint.open(
xml, input.getMessageAttributes().get("signature").getStringValue()
);
Logger.info(
this, "Claim was opened for message %s",
input.getMessageId()
);
this.origin.exec(input);
footprint.close(xml);
Logger.info(
this, "Claim was closed for message %s",
input.getMessageId()
);
}
#location 19
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Loggable
@SuppressWarnings("PMD.AvoidCatchingThrowable")
public static void main(final String... args) throws IOException {
final Props props = new Props();
if (props.has("//testing")) {
throw new IllegalStateException(
"Hey, we are in the testing mode!"
);
}
final long start = System.currentTimeMillis();
try {
Runtime.getRuntime()
.exec("ping -c1 data.0crat.com.s3.amazonaws.com")
.waitFor();
new Main(args).exec();
} catch (final Throwable ex) {
new SafeSentry(new PropsFarm()).capture(ex);
Logger.error(Main.class, "The main app crashed: %[exception]s", ex);
throw new IOException(ex);
} finally {
Logger.info(
Main.class, "Finished after %[ms]s of activity",
System.currentTimeMillis() - start
);
}
} | #vulnerable code
@Loggable
@SuppressWarnings("PMD.AvoidCatchingThrowable")
public static void main(final String... args) throws IOException {
final Props props = new Props();
if (props.has("//testing")) {
throw new IllegalStateException(
"Hey, we are in the testing mode!"
);
}
final long start = System.currentTimeMillis();
try {
new Main(args).exec();
} catch (final Throwable ex) {
new SafeSentry(new PropsFarm()).capture(ex);
Logger.error(Main.class, "The main app crashed: %[exception]s", ex);
throw new IOException(ex);
} finally {
Logger.info(
Main.class, "Finished after %[ms]s of activity",
System.currentTimeMillis() - start
);
}
}
#location 14
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public Response act(final RqRegex req) throws IOException {
final Project project = new RqAnonProject(this.farm, req);
final Cash left = new Ledger(project).bootstrap().cash().add(
new Estimates(project).bootstrap().total().mul(-1L)
);
final String amount;
if (left.equals(Cash.ZERO)) {
amount = "no money";
} else {
amount = String.format("$%s left", left.decimal().intValue());
}
return new RsWithHeaders(
new RsWithType(
new RsWithBody(
new TextOf(
this.getClass().getResource("contrib-badge.svg")
).asString().replace("AMOUNT", amount)
),
"image/svg+xml"
),
"Cache-Control: no-cache",
String.format("X-Zerocracy-Project-ID: %s", project.pid())
);
} | #vulnerable code
@Override
public Response act(final RqRegex req) throws IOException {
final String pid = req.matcher().group(1);
final Catalog catalog = new Catalog(this.farm).bootstrap();
if (!catalog.exists(pid)) {
throw new RsForward(
new RsParFlash(
new Par("Project %s not found").say(pid),
Level.WARNING
)
);
}
final Project project = this.farm.find(
String.format("@id='%s'", pid)
).iterator().next();
final Cash left = new Ledger(project).bootstrap().cash().add(
new Estimates(project).bootstrap().total().mul(-1L)
);
final String amount;
if (left.equals(Cash.ZERO)) {
amount = "no money";
} else {
amount = String.format("$%s left", left.decimal().intValue());
}
return new RsWithHeaders(
new RsWithType(
new RsWithBody(
new TextOf(
this.getClass().getResource("contrib-badge.svg")
).asString().replace("AMOUNT", amount)
),
"image/svg+xml"
),
"Cache-Control: no-cache",
String.format("X-Zerocracy-Project-ID: %s", project.pid())
);
}
#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 acceptIfNeverApplied() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final People people = new People(farm).bootstrap();
final String uid = "yegor256";
people.touch(uid);
final Request req = new RqWithUser(
farm,
new RqFake("POST", "/join-post"),
uid
);
people.breakup(uid);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
req,
// @checkstyle LineLength (1 line)
"personality=INTJ-A&stackoverflow=187241&telegram=123&about=txt"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/")
)
);
} | #vulnerable code
@Test
public void acceptIfNeverApplied() throws Exception {
final Farm farm = FkFarm.props();
final People people = new People(farm).bootstrap();
final String uid = "yegor256";
people.touch(uid);
final Request req = new RqWithUser(
farm,
new RqFake("POST", "/join-post"),
uid
);
people.breakup(uid);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
req,
// @checkstyle LineLength (1 line)
"personality=INTJ-A&stackoverflow=187241&telegram=123&about=txt"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/")
)
);
}
#location 13
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public int jobs(final String uid) throws IOException {
this.checkExisting(uid);
try (final Item item = this.item()) {
return new NumberOf(
new Xocument(item.path()).xpath(
String.format(
"/people/person[@id='%s']/jobs/text()",
uid
),
"0"
)
).intValue();
}
} | #vulnerable code
public int jobs(final String uid) throws IOException {
if (!this.exists(uid)) {
throw new IllegalArgumentException(
new Par("Person @%s doesn't exist").say(uid)
);
}
try (final Item item = this.item()) {
return new NumberOf(
new Xocument(item.path()).xpath(
String.format(
"/people/person[@id='%s']/jobs/text()",
uid
),
"0"
)
).intValue();
}
}
#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 redirectsWhenAccessingNonexistentUsersAgenda()
throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
new People(farm).bootstrap().touch("yegor256");
MatcherAssert.assertThat(
new RsPrint(
new TkApp(farm).act(
new RqWithUser.WithInit(
farm,
new RqFake("GET", "/u/foo-user/agenda")
)
)
),
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER)
);
} | #vulnerable code
@Test
public void redirectsWhenAccessingNonexistentUsersAgenda()
throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
new People(farm).bootstrap().touch("yegor256");
MatcherAssert.assertThat(
new RsPrint(
new TkApp(farm).act(
new RqWithUser(
farm,
new RqFake("GET", "/u/foo-user/agenda")
)
)
),
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER)
);
}
#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 renderJoinPage() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
new TkApp(farm).act(
new RqWithUser.WithInit(
farm, new RqFake("GET", "/join")
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("//xhtml:body")
);
} | #vulnerable code
@Test
public void renderJoinPage() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
new TkApp(farm).act(
new RqWithUser(farm, new RqFake("GET", "/join"))
)
).printBody()
),
XhtmlMatchers.hasXPaths("//xhtml:body")
);
}
#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 findsBasicNumbers() throws Exception {
MatcherAssert.assertThat(
new Policy(FkFarm.props()).get("1.min-rep", "???"),
Matchers.startsWith("??")
);
} | #vulnerable code
@Test
public void findsBasicNumbers() throws Exception {
MatcherAssert.assertThat(
new Policy(new PropsFarm(new FkFarm())).get("1.min-rep", "???"),
Matchers.startsWith("??")
);
}
#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 rendersSingleArtifact() throws Exception {
final Farm farm = FkFarm.props();
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
new TkApp(farm).act(
new RqWithUser.WithInit(
farm,
new RqFake(
"GET",
"/xml/C00000000?file=roles.xml"
)
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("/roles")
);
} | #vulnerable code
@Test
public void rendersSingleArtifact() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
new TkApp(farm).act(
new RqWithUser.WithInit(
farm,
new RqFake(
"GET",
"/xml/C00000000?file=roles.xml"
)
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("/roles")
);
}
#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 rendersListOfClaims() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
new TkApp(farm).act(
new RqWithUser.WithInit(
farm,
new RqFake(
"GET",
"/footprint/C00000000"
)
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("//xhtml:article")
);
} | #vulnerable code
@Test
public void rendersListOfClaims() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
new TkApp(farm).act(
new RqWithUser(
farm,
new RqFake(
"GET",
"/footprint/C00000000"
)
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("//xhtml:article")
);
}
#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 dontRepostNotifyFailures() throws Exception {
final Project project = new FkProject();
new ClaimOut()
.type("Notify GitHub")
.token("github;test/test#1")
.postTo(project);
final XML claim = new Claims(project).iterate().iterator().next();
new StkSafe(
"hello1",
new StkSafeTest.NonTestingFarm(),
new StkSafeTest.StkError()
).process(project, claim);
MatcherAssert.assertThat(
new Claims(project).iterate(),
Matchers.iterableWithSize(2)
);
} | #vulnerable code
@Test
public void dontRepostNotifyFailures() throws Exception {
final Stakeholder stk = Mockito.mock(Stakeholder.class);
final Project project = new FkProject();
new ClaimOut()
.type("Notify GitHub")
.token("github;test/test#1")
.postTo(project);
final XML claim = new Claims(project).iterate().iterator().next();
Mockito.doThrow(new IllegalStateException("")).when(stk).process(
project, claim
);
new StkSafe(
"hello1",
new PropsFarm(new Directives().xpath("/props/testing").remove()),
stk
).process(project, claim);
MatcherAssert.assertThat(
new Claims(project).iterate(),
Matchers.iterableWithSize(2)
);
}
#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 respondsToMilestonedEvent() throws IOException {
final MkGithub github = new MkGithub();
final Repo repo = github.repos()
.create(new Repos.RepoCreate("test", false));
final Issue bug = repo
.issues().create("bug", "");
final Milestone milestone =
repo.milestones().create("my milestone");
new Issue.Smart(bug).milestone(milestone);
final FkFarm farm = new FkFarm();
MatcherAssert.assertThat(
new RbAddToMilestone().react(
farm,
github,
Json.createObjectBuilder()
.add(
"repository",
Json.createObjectBuilder()
.add("full_name", repo.coordinates().toString())
.build()
)
.add(
"issue",
Json.createObjectBuilder()
.add("number", 1)
.add(
"milestone",
Json.createObjectBuilder()
.add("title", "milestone-title")
.add("number", 1)
.build()
).build()
).build()
),
Matchers.is(
String.format(
"Issue #%d has been added to milestone #%d",
bug.number(), milestone.number()
)
)
);
final Collection<XML> claims =
new Claims(new GhProject(farm, bug.repo())).bootstrap().iterate();
final ClaimIn claim = new ClaimIn(claims.iterator().next());
MatcherAssert.assertThat(
claim.type(),
Matchers.is("Job milestoned")
);
MatcherAssert.assertThat(
claim.param("milestone"),
Matchers.is(String.valueOf(milestone.number()))
);
MatcherAssert.assertThat(
claim.param("job"),
Matchers.is(new Job(bug).toString())
);
} | #vulnerable code
@Test
public void respondsToMilestonedEvent() throws IOException {
final MkGithub github = new MkGithub();
final Repo repo = github.repos()
.create(new Repos.RepoCreate("test", false));
final Issue bug = repo
.issues().create("bug", "");
final Milestone milestone =
repo.milestones().create("my milestone");
new Issue.Smart(bug).milestone(milestone);
MatcherAssert.assertThat(
new RbAddToMilestone().react(
new FkFarm(),
github,
Json.createObjectBuilder()
.add(
"repository",
Json.createObjectBuilder()
.add("full_name", repo.coordinates().toString())
.build()
)
.add(
"issue",
Json.createObjectBuilder()
.add("number", 1)
.add(
"milestone",
Json.createObjectBuilder()
.add("title", "milestone-title")
.add("number", 1)
.build()
).build()
).build()
),
Matchers.is(
String.format(
"Issue #%d has been added to milestone #%d",
bug.number(), milestone.number()
)
)
);
}
#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 renderClaimXml() throws Exception {
final Farm farm = new FtFarm(new PropsFarm(new FkFarm()));
final long cid = 42L;
final ClaimOut claim = new ClaimOut().type("test").cid(cid);
claim.postTo(farm.find("@id='C00000000'").iterator().next());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
new TkApp(farm).act(
new RqWithHeaders(
new RqWithUser(
farm,
new RqFake(
"GET",
String.format(
"/footprint/C00000000/%d", cid
)
)
),
"Accept: application/xml"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths(
String.format("/page/claim/cid[text() = %d]", cid)
)
);
} | #vulnerable code
@Test
public void renderClaimXml() throws Exception {
final Farm farm = new FtFarm(new PropsFarm(new FkFarm()));
final Catalog catalog = new Catalog(new Pmo(farm)).bootstrap();
final String pid = "A1B2C3D4F";
catalog.add(pid, String.format("2017/07/%s/", pid));
final Project pkt = farm.find(String.format("@id='%s'", pid))
.iterator().next();
final Roles roles = new Roles(
pkt
).bootstrap();
final String uid = "yegor256";
new People(new Pmo(farm)).bootstrap().invite(uid, "mentor");
roles.assign(uid, "PO");
final Take take = new TkApp(farm);
final long cid = 42L;
final ClaimOut claim = new ClaimOut().type("test").cid(cid);
claim.postTo(pkt);
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
take.act(
new RqWithHeaders(
new RqFake(
"GET",
String.format("/footprint/%s/%d", pid, cid)
),
// @checkstyle LineLength (1 line)
"Cookie: PsCookie=0975A5A5-F6DB193E-AF18000A-75726E3A-74657374-3A310005-6C6F6769-6E000879-65676F72-323536AE",
"Accept: application/xml"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths(
String.format("/page/claim/cid[text() = %d]", cid)
)
);
}
#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 acceptIfNeverApplied() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final People people = new People(farm).bootstrap();
final String uid = "yegor256";
people.touch(uid);
final Request req = new RqWithUser(
farm,
new RqFake("POST", "/join-post"),
uid
);
people.breakup(uid);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
req,
// @checkstyle LineLength (1 line)
"personality=INTJ-A&stackoverflow=187241&telegram=123&about=txt"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/")
)
);
} | #vulnerable code
@Test
public void acceptIfNeverApplied() throws Exception {
final Farm farm = FkFarm.props();
final People people = new People(farm).bootstrap();
final String uid = "yegor256";
people.touch(uid);
final Request req = new RqWithUser(
farm,
new RqFake("POST", "/join-post"),
uid
);
people.breakup(uid);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
req,
// @checkstyle LineLength (1 line)
"personality=INTJ-A&stackoverflow=187241&telegram=123&about=txt"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/")
)
);
}
#location 26
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@SuppressWarnings("unchecked")
public void exec() throws IOException {
final Props props = new Props();
if (props.has("//testing")) {
throw new IllegalStateException(
"Hey, we are in the testing mode!"
);
}
Sentry.init(props.get("//sentry/dsn", ""));
final Path temp = Paths.get("./s3farm").normalize();
if (!temp.toFile().mkdir()) {
throw new IllegalStateException(
String.format(
"Failed to mkdir \"%s\"", temp
)
);
}
try (
final Farm farm = new SmartFarm(
new S3Farm(new ExtBucket().value(), temp)
).value();
final SlackRadar radar = new SlackRadar(farm)
) {
new ExtMongobee(farm).apply();
new ExtTelegram(farm).value();
radar.refresh();
new GithubRoutine(farm).start();
new FtCli(
new TkApp(
farm,
new FkRegex("/slack", new TkSlack(farm, radar)),
new FkRegex("/alias", new TkAlias(farm)),
new FkRegex(
"/ghook",
new TkMethods(new TkGithub(farm), "POST")
)
),
this.arguments
).start(Exit.NEVER);
}
} | #vulnerable code
@SuppressWarnings("unchecked")
public void exec() throws IOException {
final Props props = new Props();
if (props.has("//testing")) {
throw new IllegalStateException(
"Hey, we are in the testing mode!"
);
}
Sentry.init(props.get("//sentry/dsn", ""));
try (
final Farm farm = new SmartFarm(
new S3Farm(new ExtBucket().value())
).value();
final SlackRadar radar = new SlackRadar(farm)
) {
new ExtMongobee(farm).apply();
new ExtTelegram(farm).value();
radar.refresh();
new GithubRoutine(farm).start();
new FtCli(
new TkApp(
farm,
new FkRegex("/slack", new TkSlack(farm, radar)),
new FkRegex("/alias", new TkAlias(farm)),
new FkRegex(
"/ghook",
new TkMethods(new TkGithub(farm), "POST")
)
),
this.arguments
).start(Exit.NEVER);
}
}
#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 rendersAllPossibleUrls() throws Exception {
final Take take = new TkApp(new PropsFarm(new FkFarm()));
MatcherAssert.assertThat(
this.url,
take.act(new RqFake("GET", this.url)),
Matchers.not(
new HmRsStatus(
HttpURLConnection.HTTP_NOT_FOUND
)
)
);
} | #vulnerable code
@Test
public void rendersAllPossibleUrls() throws Exception {
final Take take = new TkApp(FkFarm.props());
MatcherAssert.assertThat(
this.url,
take.act(new RqFake("GET", this.url)),
Matchers.not(
new HmRsStatus(
HttpURLConnection.HTTP_NOT_FOUND
)
)
);
}
#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 estimatesJobsWithDifferentCurrencies() throws Exception {
final Project project = new FkProject();
final Farm farm = new PropsFarm();
new Ledger(farm, project).bootstrap().add(
new Ledger.Transaction(
new Cash.S("$500"),
"assets", "cash",
"income", "sponsor",
"Funded by some guy"
)
);
final Estimates estimates = new Estimates(farm, project).bootstrap();
final String first = "gh:yegor256/pdd#4";
final Wbs wbs = new Wbs(project).bootstrap();
wbs.add(first);
new Orders(farm, project).bootstrap()
.assign(first, "yegor256", UUID.randomUUID().toString());
estimates.update(first, new Cash.S("$45"));
MatcherAssert.assertThat(
estimates.get(first),
Matchers.equalTo(new Cash.S("$45.00"))
);
final String second = "gh:yegor256/pdd#1";
wbs.add(second);
new Orders(farm, project).bootstrap()
.assign(second, "yegor", UUID.randomUUID().toString());
estimates.update(second, new Cash.S("€100"));
MatcherAssert.assertThat(
estimates.total(),
Matchers.equalTo(new Cash.S("$177.00"))
);
} | #vulnerable code
@Test
public void estimatesJobsWithDifferentCurrencies() throws Exception {
final Project project = new FkProject();
final Farm farm = new PropsFarm();
new Ledger(farm, project).bootstrap().add(
new Ledger.Transaction(
new Cash.S("$500"),
"assets", "cash",
"income", "sponsor",
"Funded by some guy"
)
);
final Estimates estimates = new Estimates(farm, project).bootstrap();
final String first = "gh:yegor256/pdd#4";
final Wbs wbs = new Wbs(project).bootstrap();
wbs.add(first);
new Orders(farm, project).bootstrap().assign(first, "yegor256", "0");
estimates.update(first, new Cash.S("$45"));
MatcherAssert.assertThat(
estimates.get(first),
Matchers.equalTo(new Cash.S("$45.00"))
);
final String second = "gh:yegor256/pdd#1";
wbs.add(second);
new Orders(farm, project).bootstrap().assign(second, "yegor", "0");
estimates.update(second, new Cash.S("€100"));
MatcherAssert.assertThat(
estimates.total(),
Matchers.equalTo(new Cash.S("$177.00"))
);
}
#location 28
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
@Ignore
public void showsResumeIfAlreadyApplied() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final People people = new People(farm).bootstrap();
final String uid = "yegor256";
people.touch(uid);
people.apply(uid, Instant.now());
MatcherAssert.assertThat(
new RsPrint(
new TkApp(farm).act(
new RqWithUser(farm, new RqFake("GET", "/join"))
)
).printBody(),
new StringContainsInOrder(
new IterableOf<String>(
"User",
"here is your resume."
)
)
);
} | #vulnerable code
@Test
@Ignore
public void showsResumeIfAlreadyApplied() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final People people = new People(farm).bootstrap();
final String uid = "yegor256";
people.touch(uid);
people.apply(uid, new Date());
MatcherAssert.assertThat(
new RsPrint(
new TkApp(farm).act(
new RqWithUser(farm, new RqFake("GET", "/join"))
)
).printBody(),
new StringContainsInOrder(
new IterableOf<String>(
"User",
"here is your resume."
)
)
);
}
#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 acceptIfNeverApplied() throws Exception {
final Farm farm = FkFarm.props();
final People people = new People(farm).bootstrap();
final String uid = "yegor256";
people.touch(uid);
final Request req = new RqWithUser(
farm,
new RqFake("POST", "/join-post"),
uid
);
people.breakup(uid);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
req,
// @checkstyle LineLength (1 line)
"personality=INTJ-A&stackoverflow=187241&telegram=123&about=txt"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/")
)
);
} | #vulnerable code
@Test
public void acceptIfNeverApplied() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final People people = new People(farm).bootstrap();
final String uid = "yegor256";
people.touch(uid);
final Request req = new RqWithUser(
farm,
new RqFake("POST", "/join-post"),
uid
);
people.breakup(uid);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
req,
// @checkstyle LineLength (1 line)
"personality=INTJ-A&stackoverflow=187241&telegram=123&about=txt"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/")
)
);
}
#location 13
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void adviser(final String pid, final String adviser)
throws IOException {
this.checkExist(pid);
try (final Item item = this.item()) {
new Xocument(item.path()).modify(
new Directives().xpath(
String.format(
"/catalog/project[@id = '%s']",
pid
)
).addIf("adviser").set(adviser)
);
}
} | #vulnerable code
public void adviser(final String pid, final String adviser)
throws IOException {
if (!this.exists(pid)) {
throw new IllegalArgumentException(
new Par(
"Project %s doesn't exist, can't get adviser"
).say(pid)
);
}
try (final Item item = this.item()) {
new Xocument(item.path()).modify(
new Directives().xpath(
String.format(
"/catalog/project[@id = '%s']",
pid
)
).addIf("adviser").set(adviser)
);
}
}
#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 acceptRequestAndRedirectOnPost() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
new RqWithUser.WithInit(
farm,
new RqFake("POST", "/join-post")
),
"personality=INTJ-A&stackoverflow=187141"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/join")
)
);
} | #vulnerable code
@Test
public void acceptRequestAndRedirectOnPost() throws Exception {
final Farm farm = FkFarm.props();
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
new RqWithUser.WithInit(
farm,
new RqFake("POST", "/join-post")
),
"personality=INTJ-A&stackoverflow=187141"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/join")
)
);
}
#location 4
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@SuppressWarnings("unchecked")
public void exec() throws IOException {
Logger.info(this, "Farm is ready to start");
final ShutdownFarm.Hook shutdown = new ShutdownFarm.Hook();
final ClaimGuts cgts = new ClaimGuts();
final TestLocks locks = new TestLocks();
try (
final MessageSink farm = new MessageSink(
new ShutdownFarm(
new ClaimsFarm(
new TempFiles.Farm(
new SmartFarm(
new S3Farm(new ExtBucket().value(), locks),
locks
)
),
cgts
),
shutdown
),
shutdown
);
final SlackRadar radar = new SlackRadar(farm);
final ClaimsRoutine claims = new ClaimsRoutine(farm)
) {
new ExtMongobee(farm).apply();
farm.start(claims.messages());
cgts.add(claims.messages());
claims.start(shutdown);
new AsyncFunc<>(
input -> {
new ExtTelegram(farm).value();
}
).exec(null);
new AsyncFunc<>(
input -> {
radar.refresh();
}
).exec(null);
new GithubRoutine(farm).start();
new Pings(farm).start();
new FtCli(
new TkApp(
farm,
new FkRegex("/alias", new TkAlias(farm)),
new FkRegex("/slack", new TkSlack(farm, radar)),
new FkRegex("/viber", new TkViber(farm)),
new FkRegex(
"/ghook",
new TkMethods(
new TkSentry(farm, new TkGithub(farm)),
HttpMethod.POST
)
),
new FkRegex(
"/glhook",
new TkMethods(
new TkSentry(farm, new TkGitlab()),
HttpMethod.POST
)
),
new FkRegex(
"/zcallback",
new TkZoldCallback(farm)
)
),
this.arguments
).start(Exit.NEVER);
}
} | #vulnerable code
@SuppressWarnings("unchecked")
public void exec() throws IOException {
final Path temp = Paths.get("./s3farm").normalize();
if (!temp.toFile().mkdir()) {
throw new IllegalStateException(
String.format(
"Failed to mkdir \"%s\"", temp
)
);
}
Logger.info(this, "Farm is ready to start");
final ShutdownFarm.Hook shutdown = new ShutdownFarm.Hook();
final ClaimGuts cgts = new ClaimGuts();
final TestLocks locks = new TestLocks();
try (
final MessageSink farm = new MessageSink(
new ShutdownFarm(
new ClaimsFarm(
new TempFiles.Farm(
new SmartFarm(
new S3Farm(new ExtBucket().value(), locks),
locks
)
),
cgts
),
shutdown
),
shutdown
);
final SlackRadar radar = new SlackRadar(farm);
final ClaimsRoutine claims = new ClaimsRoutine(farm)
) {
new ExtMongobee(farm).apply();
farm.start(claims.messages());
cgts.add(claims.messages());
claims.start(shutdown);
new AsyncFunc<>(
input -> {
new ExtTelegram(farm).value();
}
).exec(null);
new AsyncFunc<>(
input -> {
radar.refresh();
}
).exec(null);
new GithubRoutine(farm).start();
new Pings(farm).start();
new FtCli(
new TkApp(
farm,
new FkRegex("/alias", new TkAlias(farm)),
new FkRegex("/slack", new TkSlack(farm, radar)),
new FkRegex("/viber", new TkViber(farm)),
new FkRegex(
"/ghook",
new TkMethods(
new TkSentry(farm, new TkGithub(farm)),
HttpMethod.POST
)
),
new FkRegex(
"/glhook",
new TkMethods(
new TkSentry(farm, new TkGitlab()),
HttpMethod.POST
)
),
new FkRegex(
"/zcallback",
new TkZoldCallback(farm)
)
),
this.arguments
).start(Exit.NEVER);
}
}
#location 10
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void delete(final String pid) throws IOException {
this.checkExist(pid);
try (final Item item = this.item()) {
new Xocument(item.path()).modify(
new Directives().xpath(
String.format("/catalog/project[@id='%s'] ", pid)
).strict(1).remove()
);
}
} | #vulnerable code
public void delete(final String pid) throws IOException {
if (!this.exists(pid)) {
throw new IllegalArgumentException(
new Par("Project %s doesn't exist, can't delete").say(pid)
);
}
try (final Item item = this.item()) {
new Xocument(item.path()).modify(
new Directives().xpath(
String.format("/catalog/project[@id='%s'] ", pid)
).strict(1).remove()
);
}
}
#location 4
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Loggable
@SuppressWarnings("PMD.AvoidCatchingThrowable")
public static void main(final String... args) throws IOException {
final Props props = new Props();
if (props.has("//testing")) {
throw new IllegalStateException(
"Hey, we are in the testing mode!"
);
}
final long start = System.currentTimeMillis();
try {
new Main(args).exec();
} catch (final Throwable ex) {
new SafeSentry(new PropsFarm()).capture(ex);
Logger.error(Main.class, "The main app crashed: %[exception]s", ex);
throw new IOException(ex);
} finally {
Logger.info(
Main.class, "Finished after %[ms]s of activity",
System.currentTimeMillis() - start
);
}
} | #vulnerable code
@Loggable
@SuppressWarnings("PMD.AvoidCatchingThrowable")
public static void main(final String... args) throws IOException {
final Props props = new Props();
if (props.has("//testing")) {
throw new IllegalStateException(
"Hey, we are in the testing mode!"
);
}
final long start = System.currentTimeMillis();
try {
Runtime.getRuntime()
.exec("ping -c1 data.0crat.com.s3.amazonaws.com")
.waitFor();
new Main(args).exec();
} catch (final Throwable ex) {
new SafeSentry(new PropsFarm()).capture(ex);
Logger.error(Main.class, "The main app crashed: %[exception]s", ex);
throw new IOException(ex);
} finally {
Logger.info(
Main.class, "Finished after %[ms]s of activity",
System.currentTimeMillis() - start
);
}
}
#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 acceptIfNeverApplied() throws Exception {
final Farm farm = FkFarm.props();
final People people = new People(farm).bootstrap();
final String uid = "yegor256";
people.touch(uid);
final Request req = new RqWithUser(
farm,
new RqFake("POST", "/join-post"),
uid
);
people.breakup(uid);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
req,
// @checkstyle LineLength (1 line)
"personality=INTJ-A&stackoverflow=187241&telegram=123&about=txt"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/")
)
);
} | #vulnerable code
@Test
public void acceptIfNeverApplied() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final People people = new People(farm).bootstrap();
final String uid = "yegor256";
people.touch(uid);
final Request req = new RqWithUser(
farm,
new RqFake("POST", "/join-post"),
uid
);
people.breakup(uid);
MatcherAssert.assertThat(
new TkApp(farm).act(
new RqWithBody(
req,
// @checkstyle LineLength (1 line)
"personality=INTJ-A&stackoverflow=187241&telegram=123&about=txt"
)
),
Matchers.allOf(
new HmRsStatus(HttpURLConnection.HTTP_SEE_OTHER),
new HmRsHeader("Location", "/")
)
);
}
#location 26
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void rendersProfilePageWithoutRateInFirefox() throws Exception {
final Farm farm = FkFarm.props();
final String uid = "yegor256";
MatcherAssert.assertThat(
new View(farm, String.format("/u/%s", uid)).html(),
Matchers.containsString("rate</a> is not defined")
);
} | #vulnerable code
@Test
public void rendersProfilePageWithoutRateInFirefox() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final String uid = "yegor256";
MatcherAssert.assertThat(
new View(farm, String.format("/u/%s", uid)).html(),
Matchers.containsString("rate</a> is not defined")
);
}
#location 6
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void title(final String pid, final String title)
throws IOException {
this.checkExist(pid);
try (final Item item = this.item()) {
new Xocument(item.path()).modify(
new Directives()
.xpath(String.format("/catalog/project[@id = '%s']", pid))
.strict(1)
.addIf(Catalog.PRJ_TITLE)
.set(title)
);
}
} | #vulnerable code
public void title(final String pid, final String title)
throws IOException {
if (!this.exists(pid)) {
throw new IllegalArgumentException(
new Par(
"Project %s doesn't exist, can't change title"
).say(pid)
);
}
try (final Item item = this.item()) {
new Xocument(item.path()).modify(
new Directives()
.xpath(String.format("/catalog/project[@id = '%s']", pid))
.strict(1)
.addIf(Catalog.PRJ_TITLE)
.set(title)
);
}
}
#location 7
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Override
public Response act(final RqRegex req) throws IOException {
final Project project = new RqProject(this.farm, req, "PO");
final RqFormSmart form = new RqFormSmart(new RqGreedy(req));
final String email = form.single("email");
final Cash amount = new Cash.S(
String.format(
"USD %.2f",
// @checkstyle MagicNumber (1 line)
Double.parseDouble(form.single("cents")) / 100.0d
)
);
final Stripe stripe = new Stripe(this.farm);
final String customer;
final String pid;
try {
customer = stripe.register(
form.single("token"), email
);
pid = stripe.charge(
customer, amount,
new Par(this.farm, "Project %s funded").say(project.pid())
);
} catch (final Stripe.PaymentException ex) {
throw new RsForward(
new RsParFlash(ex),
String.format("/p/%s", project.pid())
);
}
final String user = new RqUser(this.farm, req).value();
new ClaimOut()
.type("Funded by Stripe")
.param("amount", amount)
.param("stripe_customer", customer)
.param("payment_id", pid)
.param("email", email)
.author(user)
.postTo(project);
new ClaimOut().type("Notify PMO").param(
"message", new Par(
"Project %s was funded for %s by @%s;",
"customer `%s`, payment `%s`"
).say(project.pid(), amount, user, customer, pid)
).postTo(this.farm);
return new RsForward(
new RsParFlash(
new Par(
"The project %s was successfully funded for %s;",
"the ledger will be updated in a few minutes;",
"payment ID is `%s`"
).say(project.pid(), amount, pid),
Level.INFO
),
String.format("/p/%s", project.pid())
);
} | #vulnerable code
@Override
public Response act(final RqRegex req) throws IOException {
final Project project = new RqProject(this.farm, req, "PO");
final RqFormSmart form = new RqFormSmart(new RqGreedy(req));
final String email = form.single("email");
final String customer;
try {
customer = new Stripe(this.farm).pay(
form.single("token"),
email,
String.format(
"%s/%s",
project.pid(),
new Catalog(this.farm).title(project.pid())
)
);
} catch (final Stripe.PaymentException ex) {
throw new RsForward(
new RsParFlash(ex),
String.format("/p/%s", project.pid())
);
}
final Cash amount = new Cash.S(
String.format(
"USD %.2f",
// @checkstyle MagicNumber (1 line)
Double.parseDouble(form.single("cents")) / 100.0d
)
);
final String user = new RqUser(this.farm, req).value();
new ClaimOut()
.type("Funded by Stripe")
.param("amount", amount)
.param("stripe_customer", customer)
.param("email", email)
.author(user)
.postTo(project);
new ClaimOut().type("Notify PMO").param(
"message", new Par(
"Project %s was funded for %s by @%s"
).say(project.pid(), amount, user)
).postTo(this.farm);
return new RsForward(
new RsParFlash(
new Par(
"The project %s was successfully funded for %s.",
"The ledger will be updated in a few minutes."
).say(project.pid(), amount),
Level.INFO
),
String.format("/p/%s", project.pid())
);
}
#location 48
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
public void reputation(final String uid, final int rep)
throws IOException {
this.checkExisting(uid);
try (final Item item = this.item()) {
new Xocument(item.path()).modify(
new Directives().xpath(
String.format(
"/people/person[@id='%s']",
uid
)
).addIf("reputation").set(rep)
);
}
} | #vulnerable code
public void reputation(final String uid, final int rep)
throws IOException {
if (!this.exists(uid)) {
throw new IllegalArgumentException(
new Par("Person @%s doesn't exist").say(uid)
);
}
try (final Item item = this.item()) {
new Xocument(item.path()).modify(
new Directives().xpath(
String.format(
"/people/person[@id='%s']",
uid
)
).addIf("reputation").set(rep)
);
}
}
#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 addsClaims() throws Exception {
final Farm farm = new PropsFarm();
final Project project = farm.find("@id='FOOTPRNTX'").iterator().next();
new ClaimOut().type("hello").postTo(project);
final XML xml = new Claims(project).iterate().iterator().next();
try (final Footprint footprint = new Footprint(farm, project)) {
footprint.open(xml);
footprint.close(xml);
MatcherAssert.assertThat(
footprint.collection().find(
Filters.eq("project", project.pid())
),
Matchers.iterableWithSize(1)
);
}
} | #vulnerable code
@Test
public void addsClaims() throws Exception {
final Farm farm = new PropsFarm();
final Project project = new Pmo(farm);
new ClaimOut().type("hello").postTo(project);
final XML xml = new Claims(project).iterate().iterator().next();
try (final Footprint footprint = new Footprint(farm, project)) {
footprint.open(xml);
footprint.close(xml);
MatcherAssert.assertThat(
footprint.collection().find(
Filters.eq("project", project.pid())
),
Matchers.iterableWithSize(1)
);
}
}
#location 7
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@SuppressWarnings("unchecked")
public void exec() throws IOException {
final Path temp = Paths.get("./s3farm").normalize();
if (!temp.toFile().mkdir()) {
throw new IllegalStateException(
String.format(
"Failed to mkdir \"%s\"", temp
)
);
}
Logger.info(this, "Farm is ready to start");
final ShutdownFarm.Hook shutdown = new ShutdownFarm.Hook();
final AtomicInteger count = new AtomicInteger();
final int threads = Runtime.getRuntime().availableProcessors();
final ClaimGuts cgts = new ClaimGuts();
try (
final S3Farm origin = new S3Farm(new ExtBucket().value(), temp);
final Farm farm = new ShutdownFarm(
new ClaimsFarm(
new SmartFarm(
origin, new TestLocks()
),
cgts
),
shutdown
);
final SlackRadar radar = new SlackRadar(farm);
final ClaimsRoutine claims = new ClaimsRoutine(
farm,
new AsyncProc(
threads,
new MessageMonitorProc(
farm,
new ExpiryProc(
new SentryProc(
farm,
new FootprintProc(
farm,
new CountingProc(
new BrigadeProc(farm),
count
)
)
)
),
shutdown
),
cgts,
shutdown
),
() -> count.intValue() < threads
)
) {
new ExtMongobee(farm).apply();
claims.start(shutdown);
new AsyncFunc<>(
input -> {
new ExtTelegram(farm).value();
}
).exec(null);
new AsyncFunc<>(
input -> {
radar.refresh();
}
).exec(null);
new GithubRoutine(farm).start();
new Pings(farm).start();
new FtCli(
new TkApp(
farm,
new FkRegex("/alias", new TkAlias(farm)),
new FkRegex("/slack", new TkSlack(farm, radar)),
new FkRegex("/viber", new TkViber(farm)),
new FkRegex(
"/ghook",
new TkMethods(
new TkSentry(farm, new TkGithub(farm)),
HttpMethod.POST
)
),
new FkRegex(
"/glhook",
new TkMethods(
new TkSentry(farm, new TkGitlab()),
HttpMethod.POST
)
)
),
this.arguments
).start(Exit.NEVER);
}
} | #vulnerable code
@SuppressWarnings("unchecked")
public void exec() throws IOException {
final Path temp = Paths.get("./s3farm").normalize();
if (!temp.toFile().mkdir()) {
throw new IllegalStateException(
String.format(
"Failed to mkdir \"%s\"", temp
)
);
}
Logger.info(this, "Farm is ready to start");
final ShutdownFarm.Hook shutdown = new ShutdownFarm.Hook();
final AtomicInteger count = new AtomicInteger();
final int threads = Runtime.getRuntime().availableProcessors();
final ClaimGuts cgts = new ClaimGuts();
try (
final S3Farm origin = new S3Farm(new ExtBucket().value(), temp);
final Farm farm = new ShutdownFarm(
new ClaimsFarm(
new SmartFarm(
origin,
new PgLocks(
new ExtDataSource(new PropsFarm(origin)).value()
)
),
cgts
),
shutdown
);
final SlackRadar radar = new SlackRadar(farm);
final ClaimsRoutine claims = new ClaimsRoutine(
farm,
new AsyncProc(
threads,
new MessageMonitorProc(
farm,
new ExpiryProc(
new SentryProc(
farm,
new FootprintProc(
farm,
new CountingProc(
new BrigadeProc(farm),
count
)
)
)
),
shutdown
),
cgts,
shutdown
),
() -> count.intValue() < threads
)
) {
new ExtMongobee(farm).apply();
claims.start(shutdown);
new AsyncFunc<>(
input -> {
new ExtTelegram(farm).value();
}
).exec(null);
new AsyncFunc<>(
input -> {
radar.refresh();
}
).exec(null);
new GithubRoutine(farm).start();
new Pings(farm).start();
new FtCli(
new TkApp(
farm,
new FkRegex("/alias", new TkAlias(farm)),
new FkRegex("/slack", new TkSlack(farm, radar)),
new FkRegex("/viber", new TkViber(farm)),
new FkRegex(
"/ghook",
new TkMethods(
new TkSentry(farm, new TkGithub(farm)),
HttpMethod.POST
)
),
new FkRegex(
"/glhook",
new TkMethods(
new TkSentry(farm, new TkGitlab()),
HttpMethod.POST
)
)
),
this.arguments
).start(Exit.NEVER);
}
}
#location 23
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void rendersReport() throws Exception {
final Farm farm = new FtFarm(new PropsFarm(new FkFarm()));
final String uid = "yegor256";
new ClaimOut()
.type("Order was given")
.param("login", uid)
.postTo(farm.find("@id='C00000000'").iterator().next());
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
new TkApp(farm).act(
new RqWithHeaders(
new RqWithUser(
farm,
new RqFake(
"GET",
// @checkstyle LineLength (1 line)
"/report/C00000000?report=orders-given-by-week"
)
),
"Accept: application/xml"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("/page/rows/row[week]")
);
} | #vulnerable code
@Test
public void rendersReport() throws Exception {
final Farm farm = new FtFarm(new PropsFarm(new FkFarm()));
final Catalog catalog = new Catalog(new Pmo(farm)).bootstrap();
final String pid = "A1B2C3DXF";
catalog.add(pid, String.format("2017/10/%s/", pid));
final Project project = farm.find(
String.format("@id='%s'", pid)
).iterator().next();
final Roles roles = new Roles(project).bootstrap();
final String uid = "yegor256";
roles.assign(uid, "PO");
new People(new Pmo(farm)).bootstrap().invite(uid, "mentor");
new ClaimOut()
.type("Order was given")
.param("login", uid)
.postTo(project);
final Take take = new TkApp(farm);
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
take.act(
new RqWithHeaders(
new RqFake(
"GET",
String.format(
"/report/%s?report=orders-given-by-week",
pid
)
),
// @checkstyle LineLength (1 line)
"Cookie: PsCookie=0975A5A5-F6DB193E-AF18000A-75726E3A-74657374-3A310005-6C6F6769-6E000879-65676F72-323536AE",
"Accept: application/xml"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("/page/rows/row[week]")
);
}
#location 40
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void showsLinkToPolicyForUnknownUser() throws Exception {
final String flash =
// @checkstyle LineLength (1 line)
"@nvseenu is not invited to us yet, see <a href=\"www.zerocracy.com/policy.html#1\">§1</a>";
MatcherAssert.assertThat(
new View(FkFarm.props(), "/").html(
new FormattedText(
"Cookie: RsFlash=%s/WARNING",
URLEncoder.encode(flash, StandardCharsets.UTF_8.toString())
).asString()
),
new StringContains(flash)
);
} | #vulnerable code
@Test
public void showsLinkToPolicyForUnknownUser() throws Exception {
final String flash =
// @checkstyle LineLength (1 line)
"@nvseenu is not invited to us yet, see <a href=\"www.zerocracy.com/policy.html#1\">§1</a>";
MatcherAssert.assertThat(
new View(new PropsFarm(new FkFarm()), "/").html(
new FormattedText(
"Cookie: RsFlash=%s/WARNING",
URLEncoder.encode(flash, StandardCharsets.UTF_8.toString())
).asString()
),
new StringContains(flash)
);
}
#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 rendersHomePage() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final String uid = "yegor256";
new Awards(farm, uid).bootstrap().add(1, "gh:test/test#1", "reason");
new Agenda(farm, uid).bootstrap().add("gh:test/test#2", "QA");
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
new TkApp(farm).act(
new RqWithUser(
farm,
new RqFake("GET", "/u/Yegor256")
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("//xhtml:body")
);
} | #vulnerable code
@Test
public void rendersHomePage() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final String uid = "yegor256";
final People people = new People(farm).bootstrap();
people.touch(uid);
people.invite(uid, "mentor");
new Awards(farm, uid).bootstrap().add(1, "gh:test/test#1", "reason");
new Agenda(farm, uid).bootstrap().add("gh:test/test#2", "QA");
final String pid = "9A0007788";
new Projects(farm, uid).bootstrap().add(pid);
new Catalog(farm).bootstrap().add(pid, "2018/01/9A0007788/");
final Take take = new TkApp(farm);
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
take.act(
new RqWithHeaders(
new RqFake("GET", "/u/Yegor256"),
// @checkstyle LineLength (1 line)
"Cookie: PsCookie=0975A5A5-F6DB193E-AF18000A-75726E3A-74657374-3A310005-6C6F6769-6E000879-65676F72-323536AE"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths("//xhtml:body")
);
}
#location 28
#vulnerability type RESOURCE_LEAK | Below is the vulnerable code, please generate the patch based on the following information. |
#fixed code
@Test
public void rendersDebts() throws Exception {
final Farm farm = FkFarm.props();
final Debts debts = new Debts(farm).bootstrap();
final String uid = "yegor256";
final String first = "details 1";
final String second = "details 2";
final String price = "$9.99";
final String amount = "$3.33";
final String reason = "reason";
debts.add(uid, new Cash.S(price), first, reason);
debts.add(uid, new Cash.S(amount), second, reason);
final String html = new View(farm, String.format("/u/%s", uid)).html();
MatcherAssert.assertThat(
html,
Matchers.allOf(
XhtmlMatchers.hasXPaths(
new FormattedText(
"//xhtml:td[.='%s (%s)']", first, reason
).asString()
),
XhtmlMatchers.hasXPaths(
new FormattedText(
"//xhtml:td[.='%s (%s)']", second, reason
).asString()
),
XhtmlMatchers.hasXPaths(
new FormattedText("//xhtml:td[.='%s']", price).asString()
),
XhtmlMatchers.hasXPaths(
new FormattedText("//xhtml:td[.='%s']", amount).asString()
)
)
);
} | #vulnerable code
@Test
public void rendersDebts() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final Debts debts = new Debts(farm).bootstrap();
final String uid = "yegor256";
final String first = "details 1";
final String second = "details 2";
final String price = "$9.99";
final String amount = "$3.33";
final String reason = "reason";
debts.add(uid, new Cash.S(price), first, reason);
debts.add(uid, new Cash.S(amount), second, reason);
final String html = new View(farm, String.format("/u/%s", uid)).html();
MatcherAssert.assertThat(
html,
Matchers.allOf(
XhtmlMatchers.hasXPaths(
new FormattedText(
"//xhtml:td[.='%s (%s)']", first, reason
).asString()
),
XhtmlMatchers.hasXPaths(
new FormattedText(
"//xhtml:td[.='%s (%s)']", second, reason
).asString()
),
XhtmlMatchers.hasXPaths(
new FormattedText("//xhtml:td[.='%s']", price).asString()
),
XhtmlMatchers.hasXPaths(
new FormattedText("//xhtml:td[.='%s']", amount).asString()
)
)
);
}
#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 rendersWithoutChromeNotice() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final String get = new RsPrint(
new TkApp(farm).act(
new RqWithUser.WithInit(
farm,
new RqFake(
"GET",
"/a/C00000000?a=pm/staff/roles"
)
)
)
).printBody();
MatcherAssert.assertThat(
get,
Matchers.not(Matchers.containsString("Chrome"))
);
} | #vulnerable code
@Test
public void rendersWithoutChromeNotice() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final String get = new RsPrint(
new TkApp(farm).act(
new RqWithUser(
farm,
new RqFake(
"GET",
"/a/C00000000?a=pm/staff/roles"
)
)
)
).printBody();
MatcherAssert.assertThat(
get,
Matchers.not(Matchers.containsString("Chrome"))
);
}
#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 rendersAllPossibleUrls() throws Exception {
final Take take = new TkApp(FkFarm.props());
MatcherAssert.assertThat(
this.url,
take.act(new RqFake("GET", this.url)),
Matchers.not(
new HmRsStatus(
HttpURLConnection.HTTP_NOT_FOUND
)
)
);
} | #vulnerable code
@Test
public void rendersAllPossibleUrls() throws Exception {
final Take take = new TkApp(new PropsFarm(new FkFarm()));
MatcherAssert.assertThat(
this.url,
take.act(new RqFake("GET", this.url)),
Matchers.not(
new HmRsStatus(
HttpURLConnection.HTTP_NOT_FOUND
)
)
);
}
#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 rendersProjectPage() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final Catalog catalog = new Catalog(new Pmo(farm)).bootstrap();
final String pid = "A1B2C3D4F";
catalog.add(pid, String.format("2017/07/%s/", pid));
catalog.link(pid, "github", "test/test");
final Roles roles = new Roles(
farm.find(String.format("@id='%s'", pid)).iterator().next()
).bootstrap();
final String uid = "yegor256";
roles.assign(uid, "PO");
new People(new Pmo(farm)).bootstrap().invite(uid, "mentor");
final Take take = new TkApp(farm);
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
take.act(
new RqWithHeaders(
new RqFake(
"GET",
String.format("/p/%s", pid)
),
// @checkstyle LineLength (1 line)
"Cookie: PsCookie=0975A5A5-F6DB193E-AF18000A-75726E3A-74657374-3A310005-6C6F6769-6E000879-65676F72-323536AE",
"Accept: application/xml"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths(
String.format("/page[project='%s']", pid),
"/page/project_links[link='github:test/test']"
)
);
} | #vulnerable code
@Test
public void rendersProjectPage() throws Exception {
final Farm farm = new PropsFarm(new FkFarm());
final Catalog catalog = new Catalog(new Pmo(farm)).bootstrap();
final String pid = "A1B2C3D4F";
catalog.add(pid, String.format("2017/07/%s/", pid));
catalog.link(pid, "github", "test/test");
final Roles roles = new Roles(
farm.find(String.format("@id='%s'", pid)).iterator().next()
).bootstrap();
final String uid = "yegor256";
roles.assign(uid, "PO");
new People(new Pmo(farm)).bootstrap().invite(uid, "mentor");
final Take take = new TkApp(farm);
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new RsPrint(
take.act(
new RqWithHeaders(
new RqFake(
"GET",
String.format("/p/%s", pid)
),
// @checkstyle LineLength (1 line)
"Cookie: PsCookie=0975A5A5-F6DB193E-AF18000A-75726E3A-74657374-3A310005-6C6F6769-6E000879-65676F72-323536AE",
"Accept: application/xml"
)
)
).printBody()
),
XhtmlMatchers.hasXPaths(
"/page/project_links[link='github:test/test']"
)
);
}
#location 35
#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.