input
stringlengths 205
73.3k
| output
stringlengths 64
73.2k
| instruction
stringclasses 1
value |
---|---|---|
#vulnerable code
@Test
public void TestEscCloseLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140)));
}
#location 6
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscCloseLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestArbitrarySplitLocations() throws IOException {
//int totalSize = 415;
//int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415)));
}
#location 10
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestArbitrarySplitLocations() throws Exception {
//int totalSize = 415;
//int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEachOnce() throws IOException {
//Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121)));
Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187)));
Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264)));
Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412)));
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41)));
// Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
}
#location 6
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEachOnce() throws Exception {
//Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121)));
Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187)));
Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264)));
Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412)));
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41)));
// Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Ignore // May not be guaranteed behavior
public void TestComma() throws IOException {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
#location 10
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Ignore // May not be guaranteed behavior
public void TestComma() throws Exception {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestArbitrarySplitLocations() throws IOException {
//int totalSize = 415;
//int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415)));
}
#location 14
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestArbitrarySplitLocations() throws Exception {
//int totalSize = 415;
//int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscape() throws IOException { // Issue #68
//int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140)));
Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140)));
Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289)));
Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}"
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69)));
}
#location 5
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscape() throws Exception { // Issue #68
//int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140)));
Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140)));
Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289)));
Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}"
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestWhitespace() throws IOException {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
#location 8
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestWhitespace() throws Exception {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestWhitespace() throws IOException {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
#location 4
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestWhitespace() throws Exception {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestNullAttr() throws Exception {
Configuration config = new Configuration();
Text value = new Text();
SerDe jserde = new GeoJsonSerDe();
Properties proptab = new Properties();
proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "num");
proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "int");
jserde.initialize(config, proptab);
StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector();
value.set("{\"properties\":{\"num\":7}}");
Object row = jserde.deserialize(value);
StructField f0 = rowOI.getStructFieldRef("num");
Object fieldData = rowOI.getStructFieldData(row, f0);
Assert.assertEquals(7, ((IntWritable)fieldData).get());
value.set("{\"properties\":{}}");
row = jserde.deserialize(value);
f0 = rowOI.getStructFieldRef("num");
fieldData = rowOI.getStructFieldData(row, f0);
Assert.assertEquals(null, fieldData);
}
#location 15
#vulnerability type NULL_DEREFERENCE
|
#fixed code
@Test
public void TestNullAttr() throws Exception {
ArrayList<Object> stuff = new ArrayList<Object>();
Properties proptab = new Properties();
proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "num");
proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "int");
SerDe jserde = mkSerDe(proptab);
StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector();
//value.set("{\"properties\":{\"num\":7}}");
addWritable(stuff, 7);
Object row = runSerDe(stuff, jserde, rowOI);
Object fieldData = getField("num", row, rowOI);
Assert.assertEquals(7, ((IntWritable)fieldData).get());
//value.set("{\"properties\":{}}");
stuff.set(0, null);
row = runSerDe(stuff, jserde, rowOI);
fieldData = getField("num", row, rowOI);
Assert.assertNull(fieldData);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscCloseLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140)));
}
#location 9
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscCloseLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscAposLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140)));
}
#location 9
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscAposLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscQuoteLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140)));
}
#location 8
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscQuoteLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEachOnce() throws IOException {
//Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121)));
Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187)));
Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264)));
Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412)));
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41)));
// Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
}
#location 4
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEachOnce() throws Exception {
//Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121)));
Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187)));
Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264)));
Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412)));
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41)));
// Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestArbitrarySplitLocations() throws Exception {
//int totalSize = 415;
//int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415)));
}
#location 16
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestArbitrarySplitLocations() throws Exception {
//int totalSize = 415;
//int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestWhitespace() throws IOException {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
#location 11
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestWhitespace() throws Exception {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscSlashLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140)));
}
#location 6
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscSlashLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscape() throws IOException { // Issue #68
//int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140)));
Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140)));
Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289)));
Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}"
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69)));
}
#location 8
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscape() throws Exception { // Issue #68
//int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140)));
Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140)));
Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289)));
Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}"
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEachOnce() throws IOException {
//Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121)));
Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187)));
Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264)));
Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412)));
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41)));
// Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
}
#location 9
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEachOnce() throws Exception {
//Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121)));
Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187)));
Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264)));
Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412)));
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41)));
// Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscAposLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140)));
}
#location 4
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscAposLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestGeomFirst() throws IOException {
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 32, 54)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 48, 54)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 49, 54)));
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 0, 52), true));
}
#location 5
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestGeomFirst() throws Exception {
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 32, 54)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 48, 54)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 49, 54)));
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 0, 52), true));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscSlashLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140)));
}
#location 9
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscSlashLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestArbitrarySplitLocations() throws IOException {
//int totalSize = 415;
//int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415)));
}
#location 15
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestArbitrarySplitLocations() throws Exception {
//int totalSize = 415;
//int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestWhitespace() throws IOException {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
#location 14
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestWhitespace() throws Exception {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscape() throws IOException { // Issue #68
//int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140)));
Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140)));
Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289)));
Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}"
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69)));
}
#location 6
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscape() throws Exception { // Issue #68
//int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140)));
Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140)));
Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289)));
Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}"
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscOpenLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140)));
Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280)));
}
#location 7
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscOpenLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140)));
Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscOpenLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140)));
Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280)));
}
#location 5
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscOpenLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140)));
Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscPoints() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 74), true));
Assert.assertArrayEquals(new int[] {0, 75}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 76), true));
Assert.assertArrayEquals(new int[] {75, 146}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 70, 148), true));
}
#location 4
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscPoints() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 74), true));
Assert.assertArrayEquals(new int[] {0, 75}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 76), true));
Assert.assertArrayEquals(new int[] {75, 146}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 70, 148), true));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscAposLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140)));
}
#location 5
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscAposLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscSlashLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140)));
}
#location 5
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscSlashLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscOpenLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140)));
Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280)));
}
#location 4
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscOpenLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140)));
Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEachOnce() throws IOException {
//Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121)));
Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187)));
Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264)));
Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412)));
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41)));
// Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
}
#location 5
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEachOnce() throws Exception {
//Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121)));
Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187)));
Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264)));
Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412)));
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41)));
// Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestArbitrarySplitLocations() throws IOException {
//int totalSize = 415;
//int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415)));
}
#location 9
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestArbitrarySplitLocations() throws Exception {
//int totalSize = 415;
//int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestGeomFirst() throws IOException {
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 32, 54)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 48, 54)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 49, 54)));
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 0, 52), true));
}
#location 3
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestGeomFirst() throws Exception {
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 32, 54)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 48, 54)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 49, 54)));
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-geom-first.json", 0, 52), true));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscCloseLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140)));
}
#location 8
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscCloseLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Ignore // May not be guaranteed behavior
public void TestComma() throws IOException {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
#location 4
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Ignore // May not be guaranteed behavior
public void TestComma() throws Exception {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscQuoteLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140)));
}
#location 9
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscQuoteLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestWhitespace() throws IOException {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
#location 10
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestWhitespace() throws Exception {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Ignore // May not be guaranteed behavior
public void TestComma() throws IOException {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
#location 14
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Ignore // May not be guaranteed behavior
public void TestComma() throws Exception {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestArbitrarySplitLocations() throws Exception {
//int totalSize = 415;
//int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415)));
}
#location 15
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestArbitrarySplitLocations() throws Exception {
//int totalSize = 415;
//int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
private static void validatePoint(Point point, BytesWritable geometryAsWritable) {
ST_X getX = new ST_X();
DoubleWritable xAsWritable = getX.evaluate(geometryAsWritable);
assertNotNull("The x writable must not be null!", xAsWritable);
ST_Y getY = new ST_Y();
DoubleWritable yAsWritable = getY.evaluate(geometryAsWritable);
assertNotNull("The y writable must not be null!", yAsWritable);
assertEquals("Longitude is different!", point.getX(), xAsWritable.get(), Epsilon);
assertEquals("Latitude is different!", point.getY(), yAsWritable.get(), Epsilon);
}
#location 10
#vulnerability type NULL_DEREFERENCE
|
#fixed code
private static void validatePoint(Point point, BytesWritable geometryAsWritable) {
ST_X getX = new ST_X();
ST_Y getY = new ST_Y();
DoubleWritable xAsWritable = getX.evaluate(geometryAsWritable);
DoubleWritable yAsWritable = getY.evaluate(geometryAsWritable);
if (null == xAsWritable || null == yAsWritable ||
Math.abs(point.getX() - xAsWritable.get()) > Epsilon ||
Math.abs(point.getY() - yAsWritable.get()) > Epsilon)
System.err.println("validateCentroid: " + (new ST_AsText()).evaluate(geometryAsWritable)
+ " ~ " + point);
assertNotNull("The x writable must not be null!", xAsWritable);
assertNotNull("The y writable must not be null!", yAsWritable);
assertEquals("Longitude is different!", point.getX(), xAsWritable.get(), Epsilon);
assertEquals("Latitude is different!", point.getY(), yAsWritable.get(), Epsilon);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEachOnce() throws IOException {
//Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121)));
Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187)));
Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264)));
Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412)));
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41)));
// Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
}
#location 8
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEachOnce() throws Exception {
//Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121)));
Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187)));
Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264)));
Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412)));
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41)));
// Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestArbitrarySplitLocations() throws IOException {
//int totalSize = 415;
//int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415)));
}
#location 16
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestArbitrarySplitLocations() throws Exception {
//int totalSize = 415;
//int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscOpenLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140)));
Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280)));
}
#location 10
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscOpenLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140)));
Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
private UnenclosedJsonRecordReader getReaderFor(String resource, int start, int end) throws IOException {
Path path = new Path(this.getClass().getResource(resource).getFile());
JobConf conf = new JobConf();
FileSplit split = new FileSplit(path, start, end - start, new String[0]);
return new UnenclosedJsonRecordReader(split, conf);
}
#location 8
#vulnerability type RESOURCE_LEAK
|
#fixed code
private UnenclosedJsonRecordReader getReaderFor(String resource, int start, int end) throws Exception {
Path path = new Path(this.getClass().getResource(resource).getFile());
FileSplit split = new FileSplit(path, start, end - start, new String[0]);
UnenclosedJsonRecordReader rr = new UnenclosedJsonRecordReader();
try {
TaskAttemptContext tac =
createTaskAttemptContext(new Configuration(), new TaskAttemptID());
rr.initialize(split, tac);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
}
return rr;
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscape() throws IOException { // Issue #68
//int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140)));
Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140)));
Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289)));
Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}"
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69)));
}
#location 9
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscape() throws Exception { // Issue #68
//int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140)));
Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140)));
Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289)));
Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}"
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscAposLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140)));
}
#location 8
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscAposLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscape() throws IOException { // Issue #68
//int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140)));
Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140)));
Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289)));
Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}"
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69)));
}
#location 10
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscape() throws Exception { // Issue #68
//int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140)));
Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140)));
Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289)));
Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}"
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscOpenLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140)));
Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280)));
}
#location 6
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscOpenLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140)));
Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscCloseLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140)));
}
#location 4
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscCloseLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 25, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc4.json", 44, 140)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscAposLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140)));
}
#location 6
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscAposLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc2.json", 43, 140)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscPoints() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 74), true));
Assert.assertArrayEquals(new int[] {0, 75}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 76), true));
Assert.assertArrayEquals(new int[] {75, 146}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 70, 148), true));
}
#location 5
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscPoints() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 74), true));
Assert.assertArrayEquals(new int[] {0, 75}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 0, 76), true));
Assert.assertArrayEquals(new int[] {75, 146}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc-points.json", 70, 148), true));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscQuoteLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140)));
}
#location 4
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscQuoteLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 25, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc1.json", 44, 140)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Ignore // May not be guaranteed behavior
public void TestComma() throws IOException {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
#location 11
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Ignore // May not be guaranteed behavior
public void TestComma() throws Exception {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscOpenLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140)));
Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280)));
}
#location 9
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscOpenLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140)));
Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscape() throws IOException { // Issue #68
//int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140)));
Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140)));
Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289)));
Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}"
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69)));
}
#location 7
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscape() throws Exception { // Issue #68
//int [] recordBreaks = new int[] { 0, 44, 88, 137, 181, 229, 270, 311, 354 }; //length 395
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 43, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 140)));
Assert.assertArrayEquals(new int[] {2, 3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 45, 140)));
Assert.assertArrayEquals(new int[] {4,5,6}, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 181, 289)));
Assert.assertArrayEquals(new int[] { 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 336, 400))); // 7|{}"
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 14, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 22, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 23, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 24, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 25, 45)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 68)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-escape.json", 44, 69)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestIntPoint() throws Exception {
Configuration config = new Configuration();
Text value = new Text();
SerDe jserde = new GeoJsonSerDe();
Properties proptab = new Properties();
proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "num,shape");
proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "bigint,binary");
jserde.initialize(config, proptab);
StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector();
value.set("{\"properties\":{\"num\":7},\"geometry\":{\"type\":\"Point\",\"coordinates\":[15.0,5.0]}}");
Object row = jserde.deserialize(value);
StructField fref = rowOI.getStructFieldRef("num");
Object fieldData = rowOI.getStructFieldData(row, fref);
Assert.assertEquals(7, ((LongWritable)fieldData).get());
value.set("{\"properties\":{\"num\":4},\"geometry\":{\"type\":\"Point\",\"coordinates\":[7.0,2.0]}}");
row = jserde.deserialize(value);
fref = rowOI.getStructFieldRef("num");
fieldData = rowOI.getStructFieldData(row, fref);
Assert.assertEquals(4, ((LongWritable)fieldData).get());
fref = rowOI.getStructFieldRef("shape");
fieldData = rowOI.getStructFieldData(row, fref);
ckPoint(new Point(7.0, 2.0), (BytesWritable)fieldData);
}
#location 15
#vulnerability type NULL_DEREFERENCE
|
#fixed code
@Test
public void TestIntPoint() throws Exception {
ArrayList<Object> stuff = new ArrayList<Object>();
Properties proptab = new Properties();
proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "num,shape");
proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "bigint,binary");
SerDe jserde = mkSerDe(proptab);
StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector();
// value.set("{\"properties\":{\"num\":7},\"geometry\":{\"type\":\"Point\",\"coordinates\":[15.0,5.0]}}");
addWritable(stuff, 7L);
addWritable(stuff, new Point(15.0, 5.0));
Object row = runSerDe(stuff, jserde, rowOI);
Object fieldData = getField("num", row, rowOI);
Assert.assertEquals(7, ((LongWritable)fieldData).get());
//value.set("{\"properties\":{\"num\":4},\"geometry\":{\"type\":\"Point\",\"coordinates\":[7.0,2.0]}}");
stuff.clear();
addWritable(stuff, 4L);
addWritable(stuff, new Point(7.0, 2.0));
row = runSerDe(stuff, jserde, rowOI);
fieldData = getField("num", row, rowOI);
Assert.assertEquals(4, ((LongWritable)fieldData).get());
fieldData = getField("shape", row, rowOI);
ckPoint(new Point(7.0, 2.0), (BytesWritable)fieldData);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscSlashLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140)));
}
#location 8
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscSlashLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc3.json", 44, 140)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEachOnce() throws IOException {
//Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121)));
Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187)));
Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264)));
Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412)));
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41)));
// Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
}
#location 7
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEachOnce() throws Exception {
//Each record exactly once - see commit b8f6d6dfaf11cce7d8cba54e6011e8684ade0e85, issue #68
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 63)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 63, 121)));
Assert.assertArrayEquals(new int[] { 4 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 121, 187)));
Assert.assertArrayEquals(new int[] { 5, 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 187, 264)));
Assert.assertArrayEquals(new int[] { 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 264, 352)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 352, 412)));
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 23)));
Assert.assertArrayEquals(new int[] { 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 23, 41)));
// Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestWhitespace() throws IOException {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
#location 7
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestWhitespace() throws Exception {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestArbitrarySplitLocations() throws Exception {
//int totalSize = 415;
//int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415)));
}
#location 10
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestArbitrarySplitLocations() throws Exception {
//int totalSize = 415;
//int [] recordBreaks = new int[] { 0, 40, 80, 120, 160, 200, 240, 280, 320, 372 };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 40)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 41)));
Assert.assertArrayEquals(new int[] { 0, 1 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 0, 42)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 39, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 20, 123)));
Assert.assertArrayEquals(new int[] { 1, 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 40, 123)));
Assert.assertArrayEquals(new int[] { 2, 3 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 41, 123)));
Assert.assertArrayEquals(new int[] { 6, 7, 8 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 240, 340)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 353, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 354, 415)));
Assert.assertArrayEquals(new int[] { 9 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-simple.json", 355, 415)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestNullGeom() throws Exception {
Configuration config = new Configuration();
Text value = new Text();
SerDe jserde = new GeoJsonSerDe();
Properties proptab = new Properties();
proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "shape");
proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "binary");
jserde.initialize(config, proptab);
StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector();
value.set("{\"properties\":{},\"geometry\":{\"type\":\"Point\",\"coordinates\":[15.0,5.0]}}");
Object row = jserde.deserialize(value);
StructField f0 = rowOI.getStructFieldRef("shape");
Object fieldData = rowOI.getStructFieldData(row, f0);
ckPoint(new Point(15.0, 5.0), (BytesWritable)fieldData);
value.set("{\"properties\":{},\"coordinates\":null}");
row = jserde.deserialize(value);
f0 = rowOI.getStructFieldRef("shape");
fieldData = rowOI.getStructFieldData(row, f0);
Assert.assertEquals(null, fieldData);
}
#location 15
#vulnerability type NULL_DEREFERENCE
|
#fixed code
@Test
public void TestNullGeom() throws Exception {
ArrayList<Object> stuff = new ArrayList<Object>();
Properties proptab = new Properties();
proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "shape");
proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "binary");
SerDe jserde = mkSerDe(proptab);
StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector();
//value.set("{\"properties\":{},\"geometry\":{\"type\":\"Point\",\"coordinates\":[15.0,5.0]}}");
addWritable(stuff, new Point(15.0, 5.0));
Object row = runSerDe(stuff, jserde, rowOI);
Object fieldData = getField("shape", row, rowOI);
ckPoint(new Point(15.0, 5.0), (BytesWritable)fieldData);
//value.set("{\"properties\":{},\"coordinates\":null}");
stuff.set(0, null);
row = runSerDe(stuff, jserde, rowOI);
fieldData = getField("shape", row, rowOI);
Assert.assertNull(fieldData);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestWhitespace() throws IOException {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
#location 13
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestWhitespace() throws Exception {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-return.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Ignore // May not be guaranteed behavior
public void TestComma() throws IOException {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
#location 13
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Ignore // May not be guaranteed behavior
public void TestComma() throws Exception {
//int [] recordBreaks = new int[] { 0, 57, 111, , };
int[] rslt = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 222), true);
Assert.assertEquals(4, rslt.length);
int[] before = null, after = null;
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 56), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 56, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 57), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 57, 222), true);
Assert.assertEquals(4, before.length + after.length);
before = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 0, 58), true);
after = getRecordIndexesInReader(getReaderFor("unenclosed-json-comma.json", 58, 222), true);
Assert.assertEquals(4, before.length + after.length);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
private static void validatePoint(Point point, BytesWritable geometryAsWritable) {
ST_X getX = new ST_X();
DoubleWritable xAsWritable = getX.evaluate(geometryAsWritable);
assertNotNull("The x writable must not be null!", xAsWritable);
ST_Y getY = new ST_Y();
DoubleWritable yAsWritable = getY.evaluate(geometryAsWritable);
assertNotNull("The y writable must not be null!", yAsWritable);
assertEquals("Longitude is different!", point.getX(), xAsWritable.get(), Epsilon);
assertEquals("Latitude is different!", point.getY(), yAsWritable.get(), Epsilon);
}
#location 11
#vulnerability type NULL_DEREFERENCE
|
#fixed code
private static void validatePoint(Point point, BytesWritable geometryAsWritable) {
ST_X getX = new ST_X();
ST_Y getY = new ST_Y();
DoubleWritable xAsWritable = getX.evaluate(geometryAsWritable);
DoubleWritable yAsWritable = getY.evaluate(geometryAsWritable);
if (null == xAsWritable || null == yAsWritable ||
Math.abs(point.getX() - xAsWritable.get()) > Epsilon ||
Math.abs(point.getY() - yAsWritable.get()) > Epsilon)
System.err.println("validateCentroid: " + (new ST_AsText()).evaluate(geometryAsWritable)
+ " ~ " + point);
assertNotNull("The x writable must not be null!", xAsWritable);
assertNotNull("The y writable must not be null!", yAsWritable);
assertEquals("Longitude is different!", point.getX(), xAsWritable.get(), Epsilon);
assertEquals("Latitude is different!", point.getY(), yAsWritable.get(), Epsilon);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestPointOnly() throws Exception {
Configuration config = new Configuration();
Text value = new Text();
SerDe jserde = new GeoJsonSerDe();
Properties proptab = new Properties();
proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "shape");
proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "binary");
jserde.initialize(config, proptab);
StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector();
value.set("{\"properties\":{},\"geometry\":{\"type\":\"Point\",\"coordinates\":[15.0,5.0]}}");
Object row = jserde.deserialize(value);
StructField f0 = rowOI.getStructFieldRef("shape");
Object fieldData = rowOI.getStructFieldData(row, f0);
ckPoint(new Point(15.0, 5.0), (BytesWritable)fieldData);
value.set("{\"properties\":{},\"geometry\":{\"type\":\"Point\",\"type\":\"Point\",\"coordinates\":[7.0,4.0]}}");
row = jserde.deserialize(value);
f0 = rowOI.getStructFieldRef("shape");
fieldData = rowOI.getStructFieldData(row, f0);
ckPoint(new Point(7.0, 4.0), (BytesWritable)fieldData);
}
#location 15
#vulnerability type NULL_DEREFERENCE
|
#fixed code
@Test
public void TestPointOnly() throws Exception {
ArrayList<Object> stuff = new ArrayList<Object>();
Properties proptab = new Properties();
proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMNS, "shape");
proptab.setProperty(HiveShims.serdeConstants.LIST_COLUMN_TYPES, "binary");
SerDe jserde = mkSerDe(proptab);
StructObjectInspector rowOI = (StructObjectInspector)jserde.getObjectInspector();
//value.set("{\"properties\":{},\"geometry\":{\"type\":\"Point\",\"coordinates\":[15.0,5.0]}}");
addWritable(stuff, new Point(15.0, 5.0));
Object row = runSerDe(stuff, jserde, rowOI);
Object fieldData = getField("shape", row, rowOI);
ckPoint(new Point(15.0, 5.0), (BytesWritable)fieldData);
//value.set("{\"properties\":{},\"geometry\":{\"type\":\"Point\",\"type\":\"Point\",\"coordinates\":[7.0,4.0]}}");
stuff.clear();
addWritable(stuff, new Point(7.0, 4.0));
row = runSerDe(stuff, jserde, rowOI);
fieldData = getField("shape", row, rowOI);
ckPoint(new Point(7.0, 4.0), (BytesWritable)fieldData);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void TestEscOpenLast() throws IOException {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140)));
Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280)));
}
#location 8
#vulnerability type RESOURCE_LEAK
|
#fixed code
@Test
public void TestEscOpenLast() throws Exception {
//int [] recordBreaks = new int[] { 0, 75, 146, 218, 290, 362, , , };
Assert.assertArrayEquals(new int[] { 0 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 44)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 45)));
Assert.assertArrayEquals(new int[] {0, 1}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 0, 46)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 19, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 26, 140)));
Assert.assertArrayEquals(new int[] {1,2,3}, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 44, 140)));
Assert.assertArrayEquals(new int[] { 6 }, getRecordIndexesInReader(getReaderFor("unenclosed-json-esc5.json", 268, 280)));
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
private PackrOutput buildMacBundle(PackrOutput output) throws IOException {
if (config.platform != PackrConfig.Platform.MacOS) {
return output;
}
// replacement strings for Info.plist
Map<String, String> values = new HashMap<>();
values.put("${executable}", config.executable);
if (config.bundleIdentifier != null) {
values.put("${bundleIdentifier}", config.bundleIdentifier);
} else {
values.put("${bundleIdentifier}", config.mainClass.substring(0, config.mainClass.lastIndexOf('.')));
}
// create folder structure
File root = output.executableFolder;
PackrFileUtils.mkdirs(new File(root, "Contents"));
new FileWriter(new File(root, "Contents/Info.plist")).write(readResourceAsString("/Info.plist", values));
File target = new File(root, "Contents/MacOS");
PackrFileUtils.mkdirs(target);
File resources = new File(root, "Contents/Resources");
PackrFileUtils.mkdirs(resources);
if (config.iconResource != null) {
// copy icon to Contents/Resources/icons.icns
if (config.iconResource.exists()) {
PackrFileUtils.copyFile(config.iconResource, new File(resources, "icons.icns"));
}
}
return new PackrOutput(target, resources);
}
#location 23
#vulnerability type RESOURCE_LEAK
|
#fixed code
private PackrOutput buildMacBundle(PackrOutput output) throws IOException {
if (config.platform != PackrConfig.Platform.MacOS) {
return output;
}
// replacement strings for Info.plist
Map<String, String> values = new HashMap<>();
values.put("${executable}", config.executable);
if (config.bundleIdentifier != null) {
values.put("${bundleIdentifier}", config.bundleIdentifier);
} else {
values.put("${bundleIdentifier}", config.mainClass.substring(0, config.mainClass.lastIndexOf('.')));
}
// create folder structure
File root = output.executableFolder;
PackrFileUtils.mkdirs(new File(root, "Contents"));
try (FileWriter info = new FileWriter(new File(root, "Contents/Info.plist"))) {
String plist = readResourceAsString("/Info.plist", values);
info.write(plist);
}
File target = new File(root, "Contents/MacOS");
PackrFileUtils.mkdirs(target);
File resources = new File(root, "Contents/Resources");
PackrFileUtils.mkdirs(resources);
if (config.iconResource != null) {
// copy icon to Contents/Resources/icons.icns
if (config.iconResource.exists()) {
PackrFileUtils.copyFile(config.iconResource, new File(resources, "icons.icns"));
}
}
return new PackrOutput(target, resources);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
private void copyExecutableAndClasspath(PackrOutput output) throws IOException {
byte[] exe = null;
String extension = "";
switch (config.platform) {
case Windows32:
exe = readResource("/packr-windows.exe");
extension = ".exe";
break;
case Windows64:
exe = readResource("/packr-windows-x64.exe");
extension = ".exe";
break;
case Linux32:
exe = readResource("/packr-linux");
break;
case Linux64:
exe = readResource("/packr-linux-x64");
break;
case MacOS:
exe = readResource("/packr-mac");
break;
}
System.out.println("Copying executable ...");
new FileOutputStream(new File(output.executableFolder, config.executable + extension)).write(exe);
PackrFileUtils.chmodX(new File(output.executableFolder, config.executable + extension));
System.out.println("Copying classpath(s) ...");
for (String file : config.classpath) {
File cpSrc = new File(file);
File cpDst = new File(output.resourcesFolder, new File(file).getName());
if (cpSrc.isFile()) {
PackrFileUtils.copyFile(cpSrc, cpDst);
} else if (cpSrc.isDirectory()) {
PackrFileUtils.copyDirectory(cpSrc, cpDst);
} else {
System.err.println("Warning! Classpath not found: " + cpSrc);
}
}
}
#location 26
#vulnerability type RESOURCE_LEAK
|
#fixed code
private void copyExecutableAndClasspath(PackrOutput output) throws IOException {
byte[] exe = null;
String extension = "";
switch (config.platform) {
case Windows32:
exe = readResource("/packr-windows.exe");
extension = ".exe";
break;
case Windows64:
exe = readResource("/packr-windows-x64.exe");
extension = ".exe";
break;
case Linux32:
exe = readResource("/packr-linux");
break;
case Linux64:
exe = readResource("/packr-linux-x64");
break;
case MacOS:
exe = readResource("/packr-mac");
break;
}
System.out.println("Copying executable ...");
try (OutputStream writer = new FileOutputStream(
new File(output.executableFolder, config.executable + extension))) {
writer.write(exe);
}
PackrFileUtils.chmodX(new File(output.executableFolder, config.executable + extension));
System.out.println("Copying classpath(s) ...");
for (String file : config.classpath) {
File cpSrc = new File(file);
File cpDst = new File(output.resourcesFolder, new File(file).getName());
if (cpSrc.isFile()) {
PackrFileUtils.copyFile(cpSrc, cpDst);
} else if (cpSrc.isDirectory()) {
PackrFileUtils.copyDirectory(cpSrc, cpDst);
} else {
System.err.println("Warning! Classpath not found: " + cpSrc);
}
}
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
private void writeConfig(PackrOutput output) throws IOException {
StringBuilder builder = new StringBuilder();
builder.append("{\n");
builder.append(" \"classPath\": [");
String delim = "\n";
for (String f : config.classpath) {
builder.append(delim).append(" \"").append(new File(f).getName()).append("\"");
delim = ",\n";
}
builder.append("\n ],\n");
builder.append(" \"mainClass\": \"").append(config.mainClass).append("\",\n");
builder.append(" \"vmArgs\": [\n");
for (int i = 0; i < config.vmArgs.size(); i++) {
String vmArg = config.vmArgs.get(i);
builder.append(" \"");
if (!vmArg.startsWith("-")) {
builder.append("-");
}
builder.append(vmArg).append("\"");
if (i < config.vmArgs.size() - 1) {
builder.append(",");
}
builder.append("\n");
}
builder.append(" ]\n");
builder.append("}");
new FileWriter(new File(output.resourcesFolder, "config.json")).write(builder.toString());
}
#location 32
#vulnerability type RESOURCE_LEAK
|
#fixed code
private void writeConfig(PackrOutput output) throws IOException {
StringBuilder builder = new StringBuilder();
builder.append("{\n");
builder.append(" \"classPath\": [");
String delim = "\n";
for (String f : config.classpath) {
builder.append(delim).append(" \"").append(new File(f).getName()).append("\"");
delim = ",\n";
}
builder.append("\n ],\n");
builder.append(" \"mainClass\": \"").append(config.mainClass).append("\",\n");
builder.append(" \"vmArgs\": [\n");
for (int i = 0; i < config.vmArgs.size(); i++) {
String vmArg = config.vmArgs.get(i);
builder.append(" \"");
if (!vmArg.startsWith("-")) {
builder.append("-");
}
builder.append(vmArg).append("\"");
if (i < config.vmArgs.size() - 1) {
builder.append(",");
}
builder.append("\n");
}
builder.append(" ]\n");
builder.append("}");
try (Writer writer = new FileWriter(new File(output.resourcesFolder, "config.json"))) {
writer.write(builder.toString());
}
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
public Promise synwrite(BaseMessage message){
Channel ch = fetchOneWritable();
AbstractSessionStateManager session = (AbstractSessionStateManager)ch.pipeline().get(sessionHandler);
return session.writeMessagesync( message);
}
#location 3
#vulnerability type NULL_DEREFERENCE
|
#fixed code
public Promise synwrite(BaseMessage message){
Channel ch = fetchOneWritable();
if(ch == null) return null;
AbstractSessionStateManager session = (AbstractSessionStateManager)ch.pipeline().get(sessionHandler);
return session.writeMessagesync( message);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
public SmsAlphabet getAlphabet()
{
switch (getGroup())
{
case GENERAL_DATA_CODING:
// General Data Coding Indication
if (dcs_ == 0x00)
{
return SmsAlphabet.ASCII;
}
switch (dcs_ & 0x0C)
{
case 0x00: return SmsAlphabet.ASCII;
case 0x04: return SmsAlphabet.LATIN1;
case 0x08: return SmsAlphabet.UCS2;
case 0x0C: return SmsAlphabet.RESERVED;
default: return null;
}
case MESSAGE_WAITING_STORE_GSM:
return SmsAlphabet.ASCII;
case MESSAGE_WAITING_STORE_UCS2:
return SmsAlphabet.UCS2;
case DATA_CODING_MESSAGE:
switch (dcs_ & 0x04)
{
case 0x00: return SmsAlphabet.ASCII;
case 0x04: return SmsAlphabet.LATIN1;
default: return null;
}
default:
return null;
}
}
#location 3
#vulnerability type NULL_DEREFERENCE
|
#fixed code
public SmsAlphabet getAlphabet()
{
switch (getGroup())
{
case GENERAL_DATA_CODING:
// General Data Coding Indication
if (dcs_ == 0x00)
{
return SmsAlphabet.ASCII;
}
switch (dcs_ & 0x0C)
{
case 0x00: return SmsAlphabet.ASCII;
case 0x04: return SmsAlphabet.LATIN1;
case 0x08: return SmsAlphabet.UCS2;
case 0x0C: return SmsAlphabet.RESERVED;
default: return SmsAlphabet.UCS2;
}
case MESSAGE_WAITING_STORE_GSM:
return SmsAlphabet.ASCII;
case MESSAGE_WAITING_STORE_UCS2:
return SmsAlphabet.UCS2;
case DATA_CODING_MESSAGE:
switch (dcs_ & 0x04)
{
case 0x00: return SmsAlphabet.ASCII;
case 0x04: return SmsAlphabet.LATIN1;
default: return SmsAlphabet.UCS2;
}
default:
return SmsAlphabet.UCS2;
}
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
public ChannelFuture asynwrite(Object msg){
Channel ch = fetchOneWritable();
ChannelFuture future = ch.writeAndFlush(msg);
return future;
}
#location 3
#vulnerability type NULL_DEREFERENCE
|
#fixed code
public ChannelFuture asynwrite(Object msg){
Channel ch = fetchOneWritable();
if(ch == null) return null;
ChannelFuture future = ch.writeAndFlush(msg);
return future;
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
private Class<?> loadTestClassWithDistinctClassLoader() throws Exception {
URL[] classpath = {temp.getRoot().toURI().toURL()};
URLClassLoader loader = new URLClassLoader(classpath);
return loader.loadClass(CLASS_NAME);
}
#location 4
#vulnerability type RESOURCE_LEAK
|
#fixed code
private Class<?> loadTestClassWithDistinctClassLoader() throws Exception {
URL[] classpath = {temp.getRoot().toURI().toURL()};
URLClassLoader loader = new URLClassLoader(classpath);
Class<?> clazz = loader.loadClass(CLASS_NAME);
loader.close();
return clazz;
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Override
public void disconnect()
{
if (!isConnected())
{
logger.warn("ClusterManager " + _instanceName + " already disconnected");
return;
}
logger.info("disconnect " + _instanceName + "(" + _instanceType + ") from "
+ _clusterName);
/**
* shutdown thread pool first to avoid reset() being invoked in the middle of state
* transition
*/
_messagingService.getExecutor().shutDown();
resetHandlers();
_helixAccessor.shutdown();
if (_leaderElectionHandler != null)
{
_leaderElectionHandler.reset();
}
if (_participantHealthCheckInfoCollector != null)
{
_participantHealthCheckInfoCollector.stop();
}
if (_timer != null)
{
_timer.cancel();
_timer = null;
}
if (_instanceType == InstanceType.CONTROLLER)
{
stopTimerTasks();
}
// unsubscribe accessor from controllerChange
_zkClient.unsubscribeAll();
_zkClient.close();
// HACK seems that zkClient is not sending DISCONNECT event
_zkStateChangeListener.disconnect();
logger.info("Cluster manager: " + _instanceName + " disconnected");
}
#location 25
#vulnerability type THREAD_SAFETY_VIOLATION
|
#fixed code
@Override
public void disconnect()
{
if (!isConnected())
{
logger.error("ClusterManager " + _instanceName + " already disconnected");
return;
}
disconnectInternal();
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test (groups = {"integrationTest"})
public void testFileBasedClusterManager() throws Exception
{
List<FileBasedClusterManager.DBParam> dbParams = new ArrayList<FileBasedClusterManager.DBParam>();
dbParams.add(new FileBasedClusterManager.DBParam("BizFollow", 1));
dbParams.add(new FileBasedClusterManager.DBParam("BizProfile", 1));
dbParams.add(new FileBasedClusterManager.DBParam("EspressoDB", 10));
dbParams.add(new FileBasedClusterManager.DBParam("MailboxDB", 128));
dbParams.add(new FileBasedClusterManager.DBParam("MyDB", 8));
dbParams.add(new FileBasedClusterManager.DBParam("schemata", 1));
String[] nodesInfo =
{ "localhost:8900", "localhost:8901", "localhost:8902", "localhost:8903",
"localhost:8904" };
String file = "/tmp/clusterView.json";
int replica = 0;
// ClusterViewSerializer serializer = new ClusterViewSerializer(file);
ClusterView view = FileBasedClusterManager.generateStaticConfigClusterView(nodesInfo, dbParams, replica);
view.setExternalView(new LinkedList<ZNRecord>());
ClusterViewSerializer.serialize(view, new File(file));
ClusterView restoredView = ClusterViewSerializer.deserialize(new File(file));
VerifyClusterViews(view, restoredView);
}
#location 23
#vulnerability type NULL_DEREFERENCE
|
#fixed code
@Test (groups = {"integrationTest"})
public void testFileBasedClusterManager() throws Exception
{
List<FileBasedClusterManager.DBParam> dbParams = new ArrayList<FileBasedClusterManager.DBParam>();
dbParams.add(new FileBasedClusterManager.DBParam("BizFollow", 1));
dbParams.add(new FileBasedClusterManager.DBParam("BizProfile", 1));
dbParams.add(new FileBasedClusterManager.DBParam("EspressoDB", 10));
dbParams.add(new FileBasedClusterManager.DBParam("MailboxDB", 128));
dbParams.add(new FileBasedClusterManager.DBParam("MyDB", 8));
dbParams.add(new FileBasedClusterManager.DBParam("schemata", 1));
String[] nodesInfo =
{ "localhost:8900", "localhost:8901", "localhost:8902", "localhost:8903",
"localhost:8904" };
String file = "/tmp/clusterView.json";
int replica = 0;
// ClusterViewSerializer serializer = new ClusterViewSerializer(file);
ClusterView view = FileBasedClusterManager.generateStaticConfigClusterView(nodesInfo, dbParams, replica);
view.setExternalView(new LinkedList<ZNRecord>());
ClusterViewSerializer.serialize(view, new File(file));
ClusterView restoredView = ClusterViewSerializer.deserialize(new File(file));
verifyClusterViews(view, restoredView);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void testZkClientMonitor() throws Exception {
final String TEST_TAG = "test_monitor";
final String TEST_KEY = "test_key";
final String TEST_DATA = "testData";
final String TEST_ROOT = "/my_cluster/IDEALSTATES";
final String TEST_NODE = "/test_zkclient_monitor";
final String TEST_PATH = TEST_ROOT + TEST_NODE;
ZkClient zkClient = new ZkClient(ZK_ADDR, TEST_TAG, TEST_KEY);
final long TEST_DATA_SIZE = zkClient.serialize(TEST_DATA, TEST_PATH).length;
if (_zkClient.exists(TEST_PATH)) {
_zkClient.delete(TEST_PATH);
}
if (!_zkClient.exists(TEST_ROOT)) {
_zkClient.createPersistent(TEST_ROOT, true);
}
MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName name = MBeanRegistrar
.buildObjectName(MonitorDomainNames.HelixZkClient.name(), ZkClientMonitor.MONITOR_TYPE,
TEST_TAG, ZkClientMonitor.MONITOR_KEY, TEST_KEY);
ObjectName rootname = MBeanRegistrar
.buildObjectName(MonitorDomainNames.HelixZkClient.name(), ZkClientMonitor.MONITOR_TYPE,
TEST_TAG, ZkClientMonitor.MONITOR_KEY, TEST_KEY, ZkClientPathMonitor.MONITOR_PATH,
"Root");
ObjectName idealStatename = MBeanRegistrar
.buildObjectName(MonitorDomainNames.HelixZkClient.name(), ZkClientMonitor.MONITOR_TYPE,
TEST_TAG, ZkClientMonitor.MONITOR_KEY, TEST_KEY, ZkClientPathMonitor.MONITOR_PATH,
"IdealStates");
Assert.assertTrue(beanServer.isRegistered(rootname));
Assert.assertTrue(beanServer.isRegistered(idealStatename));
// Test exists
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadTotalLatencyCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadMaxLatencyGauge"), 0);
zkClient.exists(TEST_ROOT);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 1);
Assert.assertTrue((long) beanServer.getAttribute(rootname, "ReadTotalLatencyCounter") >= 0);
Assert.assertTrue((long) beanServer.getAttribute(rootname, "ReadMaxLatencyGauge") >= 0);
// Test create
Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteBytesCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteBytesCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteTotalLatencyCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteMaxLatencyGauge"), 0);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteTotalLatencyCounter"),
0);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteMaxLatencyGauge"), 0);
zkClient.create(TEST_PATH, TEST_DATA, CreateMode.PERSISTENT);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteCounter"), 1);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteBytesCounter"),
TEST_DATA_SIZE);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteCounter"), 1);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteBytesCounter"),
TEST_DATA_SIZE);
long origWriteTotalLatencyCounter =
(long) beanServer.getAttribute(rootname, "WriteTotalLatencyCounter");
Assert.assertTrue(origWriteTotalLatencyCounter >= 0);
Assert.assertTrue((long) beanServer.getAttribute(rootname, "WriteMaxLatencyGauge") >= 0);
long origIdealStatesWriteTotalLatencyCounter =
(long) beanServer.getAttribute(idealStatename, "WriteTotalLatencyCounter");
Assert.assertTrue(origIdealStatesWriteTotalLatencyCounter >= 0);
Assert.assertTrue((long) beanServer.getAttribute(idealStatename, "WriteMaxLatencyGauge") >= 0);
// Test read
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 1);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadBytesCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadBytesCounter"), 0);
long origReadTotalLatencyCounter =
(long) beanServer.getAttribute(rootname, "ReadTotalLatencyCounter");
long origIdealStatesReadTotalLatencyCounter =
(long) beanServer.getAttribute(idealStatename, "ReadTotalLatencyCounter");
Assert.assertEquals(origIdealStatesReadTotalLatencyCounter, 0);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadMaxLatencyGauge"), 0);
zkClient.readData(TEST_PATH, new Stat());
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 2);
Assert
.assertEquals((long) beanServer.getAttribute(rootname, "ReadBytesCounter"), TEST_DATA_SIZE);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadCounter"), 1);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadBytesCounter"),
TEST_DATA_SIZE);
Assert.assertTrue((long) beanServer.getAttribute(rootname, "ReadTotalLatencyCounter")
>= origReadTotalLatencyCounter);
Assert.assertTrue((long) beanServer.getAttribute(idealStatename, "ReadTotalLatencyCounter")
>= origIdealStatesReadTotalLatencyCounter);
Assert.assertTrue((long) beanServer.getAttribute(idealStatename, "ReadMaxLatencyGauge") >= 0);
zkClient.getChildren(TEST_PATH);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 3);
Assert
.assertEquals((long) beanServer.getAttribute(rootname, "ReadBytesCounter"), TEST_DATA_SIZE);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadCounter"), 2);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadBytesCounter"),
TEST_DATA_SIZE);
zkClient.getStat(TEST_PATH);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 4);
Assert
.assertEquals((long) beanServer.getAttribute(rootname, "ReadBytesCounter"), TEST_DATA_SIZE);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadCounter"), 3);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadBytesCounter"),
TEST_DATA_SIZE);
zkClient.readDataAndStat(TEST_PATH, new Stat(), true);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 5);
ZkAsyncCallbacks.ExistsCallbackHandler callbackHandler =
new ZkAsyncCallbacks.ExistsCallbackHandler();
zkClient.asyncExists(TEST_PATH, callbackHandler);
callbackHandler.waitForSuccess();
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 6);
// Test write
zkClient.writeData(TEST_PATH, TEST_DATA);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteCounter"), 2);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteBytesCounter"),
TEST_DATA_SIZE * 2);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteCounter"), 2);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteBytesCounter"),
TEST_DATA_SIZE * 2);
Assert.assertTrue((long) beanServer.getAttribute(rootname, "WriteTotalLatencyCounter")
>= origWriteTotalLatencyCounter);
Assert.assertTrue((long) beanServer.getAttribute(idealStatename, "WriteTotalLatencyCounter")
>= origIdealStatesWriteTotalLatencyCounter);
// Test data change count
final Lock lock = new ReentrantLock();
final Condition callbackFinish = lock.newCondition();
zkClient.subscribeDataChanges(TEST_PATH, new IZkDataListener() {
@Override
public void handleDataChange(String dataPath, Object data) throws Exception {
}
@Override
public void handleDataDeleted(String dataPath) throws Exception {
lock.lock();
try {
callbackFinish.signal();
} finally {
lock.unlock();
}
}
});
lock.lock();
_zkClient.delete(TEST_PATH);
Assert.assertTrue(callbackFinish.await(10, TimeUnit.SECONDS));
Assert.assertEquals((long) beanServer.getAttribute(name, "DataChangeEventCounter"), 1);
}
#location 15
#vulnerability type THREAD_SAFETY_VIOLATION
|
#fixed code
@Test
public void testZkClientMonitor() throws Exception {
final String TEST_TAG = "test_monitor";
final String TEST_KEY = "test_key";
final String TEST_DATA = "testData";
final String TEST_ROOT = "/my_cluster/IDEALSTATES";
final String TEST_NODE = "/test_zkclient_monitor";
final String TEST_PATH = TEST_ROOT + TEST_NODE;
ZkClient.Builder builder = new ZkClient.Builder();
builder.setZkServer(ZK_ADDR).setMonitorKey(TEST_KEY).setMonitorType(TEST_TAG)
.setMonitorRootPathOnly(false);
ZkClient zkClient = builder.build();
final long TEST_DATA_SIZE = zkClient.serialize(TEST_DATA, TEST_PATH).length;
if (_zkClient.exists(TEST_PATH)) {
_zkClient.delete(TEST_PATH);
}
if (!_zkClient.exists(TEST_ROOT)) {
_zkClient.createPersistent(TEST_ROOT, true);
}
MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName name = MBeanRegistrar
.buildObjectName(MonitorDomainNames.HelixZkClient.name(), ZkClientMonitor.MONITOR_TYPE,
TEST_TAG, ZkClientMonitor.MONITOR_KEY, TEST_KEY);
ObjectName rootname = MBeanRegistrar
.buildObjectName(MonitorDomainNames.HelixZkClient.name(), ZkClientMonitor.MONITOR_TYPE,
TEST_TAG, ZkClientMonitor.MONITOR_KEY, TEST_KEY, ZkClientPathMonitor.MONITOR_PATH,
"Root");
ObjectName idealStatename = MBeanRegistrar
.buildObjectName(MonitorDomainNames.HelixZkClient.name(), ZkClientMonitor.MONITOR_TYPE,
TEST_TAG, ZkClientMonitor.MONITOR_KEY, TEST_KEY, ZkClientPathMonitor.MONITOR_PATH,
"IdealStates");
Assert.assertTrue(beanServer.isRegistered(rootname));
Assert.assertTrue(beanServer.isRegistered(idealStatename));
// Test exists
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadTotalLatencyCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadLatencyGauge.Max"), 0);
zkClient.exists(TEST_ROOT);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 1);
Assert.assertTrue((long) beanServer.getAttribute(rootname, "ReadTotalLatencyCounter") >= 0);
Assert.assertTrue((long) beanServer.getAttribute(rootname, "ReadLatencyGauge.Max") >= 0);
// Test create
Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteBytesCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteBytesCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteTotalLatencyCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteLatencyGauge.Max"), 0);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteTotalLatencyCounter"),
0);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteLatencyGauge.Max"), 0);
zkClient.create(TEST_PATH, TEST_DATA, CreateMode.PERSISTENT);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteCounter"), 1);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteBytesCounter"),
TEST_DATA_SIZE);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteCounter"), 1);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteBytesCounter"),
TEST_DATA_SIZE);
long origWriteTotalLatencyCounter =
(long) beanServer.getAttribute(rootname, "WriteTotalLatencyCounter");
Assert.assertTrue(origWriteTotalLatencyCounter >= 0);
Assert.assertTrue((long) beanServer.getAttribute(rootname, "WriteLatencyGauge.Max") >= 0);
long origIdealStatesWriteTotalLatencyCounter =
(long) beanServer.getAttribute(idealStatename, "WriteTotalLatencyCounter");
Assert.assertTrue(origIdealStatesWriteTotalLatencyCounter >= 0);
Assert.assertTrue((long) beanServer.getAttribute(idealStatename, "WriteLatencyGauge.Max") >= 0);
// Test read
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 1);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadBytesCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadCounter"), 0);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadBytesCounter"), 0);
long origReadTotalLatencyCounter =
(long) beanServer.getAttribute(rootname, "ReadTotalLatencyCounter");
long origIdealStatesReadTotalLatencyCounter =
(long) beanServer.getAttribute(idealStatename, "ReadTotalLatencyCounter");
Assert.assertEquals(origIdealStatesReadTotalLatencyCounter, 0);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadLatencyGauge.Max"), 0);
zkClient.readData(TEST_PATH, new Stat());
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 2);
Assert
.assertEquals((long) beanServer.getAttribute(rootname, "ReadBytesCounter"), TEST_DATA_SIZE);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadCounter"), 1);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadBytesCounter"),
TEST_DATA_SIZE);
Assert.assertTrue((long) beanServer.getAttribute(rootname, "ReadTotalLatencyCounter")
>= origReadTotalLatencyCounter);
Assert.assertTrue((long) beanServer.getAttribute(idealStatename, "ReadTotalLatencyCounter")
>= origIdealStatesReadTotalLatencyCounter);
Assert.assertTrue((long) beanServer.getAttribute(idealStatename, "ReadLatencyGauge.Max") >= 0);
zkClient.getChildren(TEST_PATH);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 3);
Assert
.assertEquals((long) beanServer.getAttribute(rootname, "ReadBytesCounter"), TEST_DATA_SIZE);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadCounter"), 2);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadBytesCounter"),
TEST_DATA_SIZE);
zkClient.getStat(TEST_PATH);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 4);
Assert
.assertEquals((long) beanServer.getAttribute(rootname, "ReadBytesCounter"), TEST_DATA_SIZE);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadCounter"), 3);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "ReadBytesCounter"),
TEST_DATA_SIZE);
zkClient.readDataAndStat(TEST_PATH, new Stat(), true);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 5);
ZkAsyncCallbacks.ExistsCallbackHandler callbackHandler =
new ZkAsyncCallbacks.ExistsCallbackHandler();
zkClient.asyncExists(TEST_PATH, callbackHandler);
callbackHandler.waitForSuccess();
Assert.assertEquals((long) beanServer.getAttribute(rootname, "ReadCounter"), 6);
// Test write
zkClient.writeData(TEST_PATH, TEST_DATA);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteCounter"), 2);
Assert.assertEquals((long) beanServer.getAttribute(rootname, "WriteBytesCounter"),
TEST_DATA_SIZE * 2);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteCounter"), 2);
Assert.assertEquals((long) beanServer.getAttribute(idealStatename, "WriteBytesCounter"),
TEST_DATA_SIZE * 2);
Assert.assertTrue((long) beanServer.getAttribute(rootname, "WriteTotalLatencyCounter")
>= origWriteTotalLatencyCounter);
Assert.assertTrue((long) beanServer.getAttribute(idealStatename, "WriteTotalLatencyCounter")
>= origIdealStatesWriteTotalLatencyCounter);
// Test data change count
final Lock lock = new ReentrantLock();
final Condition callbackFinish = lock.newCondition();
zkClient.subscribeDataChanges(TEST_PATH, new IZkDataListener() {
@Override
public void handleDataChange(String dataPath, Object data) throws Exception {
}
@Override
public void handleDataDeleted(String dataPath) throws Exception {
lock.lock();
try {
callbackFinish.signal();
} finally {
lock.unlock();
}
}
});
lock.lock();
_zkClient.delete(TEST_PATH);
Assert.assertTrue(callbackFinish.await(10, TimeUnit.SECONDS));
Assert.assertEquals((long) beanServer.getAttribute(name, "DataChangeEventCounter"), 1);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Override
public void disconnect() {
if (_zkclient == null || _zkclient.isClosed()) {
LOG.info("instanceName: " + _instanceName + " already disconnected");
return;
}
LOG.info("disconnect " + _instanceName + "(" + _instanceType + ") from " + _clusterName);
try {
/**
* stop all timer tasks
*/
stopTimerTasks();
/**
* shutdown thread pool first to avoid reset() being invoked in the middle of state
* transition
*/
_messagingService.getExecutor().shutdown();
// TODO reset user defined handlers only
// TODO Fix the issue that when connection disconnected, reset handlers will be blocked. -- JJ
// This is because reset logic contains ZK operations.
resetHandlers(true);
if (_leaderElectionHandler != null) {
_leaderElectionHandler.reset(true);
}
} finally {
GenericHelixController controller = _controller;
if (controller != null) {
try {
controller.shutdown();
} catch (InterruptedException e) {
LOG.info("Interrupted shutting down GenericHelixController", e);
}
}
ParticipantManager participantManager = _participantManager;
if (participantManager != null) {
participantManager.disconnect();
}
for (HelixCallbackMonitor callbackMonitor : _callbackMonitors.values()) {
callbackMonitor.unregister();
}
_helixPropertyStore = null;
synchronized (this) {
if (_controller != null) {
_controller = null;
_leaderElectionHandler = null;
}
if (_participantManager != null) {
_participantManager = null;
}
if (_zkclient != null) {
_zkclient.close();
}
}
_sessionStartTime = null;
LOG.info("Cluster manager: " + _instanceName + " disconnected");
}
}
#location 43
#vulnerability type THREAD_SAFETY_VIOLATION
|
#fixed code
@Override
public void disconnect() {
if (_zkclient == null || _zkclient.isClosed()) {
LOG.info("instanceName: " + _instanceName + " already disconnected");
return;
}
LOG.info("disconnect " + _instanceName + "(" + _instanceType + ") from " + _clusterName);
try {
/**
* stop all timer tasks
*/
stopTimerTasks();
/**
* shutdown thread pool first to avoid reset() being invoked in the middle of state
* transition
*/
_messagingService.getExecutor().shutdown();
if (!cleanupCallbackHandlers()) {
LOG.warn(
"The callback handler cleanup has been cleanly done. "
+ "Some callback handlers might not be reset properly. "
+ "Continue to finish the other Helix Mananger disconnect tasks.");
}
} finally {
GenericHelixController controller = _controller;
if (controller != null) {
try {
controller.shutdown();
} catch (InterruptedException e) {
LOG.info("Interrupted shutting down GenericHelixController", e);
}
}
for (HelixCallbackMonitor callbackMonitor : _callbackMonitors.values()) {
callbackMonitor.unregister();
}
_helixPropertyStore = null;
synchronized (this) {
if (_controller != null) {
_controller = null;
_leaderElectionHandler = null;
}
if (_participantManager != null) {
_participantManager = null;
}
if (_zkclient != null) {
_zkclient.close();
}
}
_sessionStartTime = null;
LOG.info("Cluster manager: " + _instanceName + " disconnected");
}
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
public void setRequestedState(String partitionName, String state) {
Map<String, Map<String, String>> mapFields = _record.getMapFields();
if (mapFields.get(partitionName) == null) {
mapFields.put(partitionName, new TreeMap<String, String>());
}
mapFields.get(partitionName).put(CurrentStateProperty.REQUESTED_STATE.name(), state);
}
#location 6
#vulnerability type NULL_DEREFERENCE
|
#fixed code
public void setRequestedState(String partitionName, String state) {
setProperty(partitionName, CurrentStateProperty.REQUESTED_STATE, state);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Override
public void process(ClusterEvent event) throws Exception
{
ClusterManager manager = event.getAttribute("clustermanager");
if (manager == null)
{
throw new StageException("ClusterManager attribute value is null");
}
ClusterDataAccessor dataAccessor = manager.getDataAccessor();
Map<String, ResourceGroup> resourceGroupMap = event
.getAttribute(AttributeName.RESOURCE_GROUPS.toString());
MessageSelectionStageOutput messageSelectionStageOutput = event
.getAttribute(AttributeName.MESSAGES_SELECTED.toString());
for (String resourceGroupName : resourceGroupMap.keySet())
{
ResourceGroup resourceGroup = resourceGroupMap.get(resourceGroupName);
for (ResourceKey resource : resourceGroup.getResourceKeys())
{
List<Message> messages = messageSelectionStageOutput.getMessages(
resourceGroupName, resource);
sendMessages(dataAccessor, messages);
}
}
}
#location 14
#vulnerability type NULL_DEREFERENCE
|
#fixed code
@Override
public void process(ClusterEvent event) throws Exception
{
ClusterManager manager = event.getAttribute("clustermanager");
if (manager == null)
{
throw new StageException("ClusterManager attribute value is null");
}
ClusterDataAccessor dataAccessor = manager.getDataAccessor();
Map<String, ResourceGroup> resourceGroupMap = event
.getAttribute(AttributeName.RESOURCE_GROUPS.toString());
if (resourceGroupMap == null)
{
throw new StageException("ResourceGroupMap attribute value is null");
}
MessageSelectionStageOutput messageSelectionStageOutput = event
.getAttribute(AttributeName.MESSAGES_SELECTED.toString());
for (String resourceGroupName : resourceGroupMap.keySet())
{
ResourceGroup resourceGroup = resourceGroupMap.get(resourceGroupName);
for (ResourceKey resource : resourceGroup.getResourceKeys())
{
List<Message> messages = messageSelectionStageOutput.getMessages(
resourceGroupName, resource);
sendMessages(dataAccessor, messages);
}
}
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void testInvocationAnnotated() throws Exception
{
System.out.println("TestCMTaskHandler.testInvocationAnnotated()");
Message message = new Message(MessageType.STATE_TRANSITION);
message.setSrcName("cm-instance-0");
message.setTgtSessionId("1234");
message.setFromState("Offline");
message.setToState("Slave");
message.setStateUnitKey("Teststateunitkey");
message.setId("Some unique id");
message.setMsgId("Some unique message id");
MockStateModelAnnotated stateModel = new MockStateModelAnnotated();
NotificationContext context;
context = new NotificationContext(new MockManager());
CMTaskHandler handler;
handler = new CMTaskHandler(message, context, null, null);
handler.call();
AssertJUnit.assertTrue(stateModel.stateModelInvoked);
}
#location 19
#vulnerability type NULL_DEREFERENCE
|
#fixed code
@Test
public void testInvocationAnnotated() throws Exception
{
System.out.println("TestCMTaskHandler.testInvocationAnnotated()");
Message message = new Message(MessageType.STATE_TRANSITION);
message.setSrcName("cm-instance-0");
message.setTgtSessionId("1234");
message.setFromState("Offline");
message.setToState("Slave");
message.setStateUnitKey("Teststateunitkey");
message.setId("Some unique id");
message.setMsgId("Some unique message id");
MockStateModelAnnotated stateModel = new MockStateModelAnnotated();
NotificationContext context;
context = new NotificationContext(new MockManager());
CMTaskHandler handler;
CMStateTransitionHandler stHandler = new CMStateTransitionHandler(stateModel);
handler = new CMTaskHandler(message, context, stHandler, null);
handler.call();
AssertJUnit.assertTrue(stateModel.stateModelInvoked);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Override
public void handleDataDeleted(String dataPath) {
if (_zkClientForListener == null || _zkClientForListener.isClosed()) {
return;
}
// Resubscribe
_zkClientForListener.unsubscribeAll();
_zkClientForListener.subscribeRoutingDataChanges(this, this);
resetZkResources();
}
#location 8
#vulnerability type THREAD_SAFETY_VIOLATION
|
#fixed code
@Override
public void handleDataDeleted(String dataPath) {
if (_zkClientForRoutingDataListener == null || _zkClientForRoutingDataListener.isClosed()) {
return;
}
// Resubscribe
_zkClientForRoutingDataListener.unsubscribeAll();
_zkClientForRoutingDataListener.subscribeRoutingDataChanges(this, this);
resetZkResources();
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void testSimpleCS() {
// setup resource
Map<String, Resource> resourceMap = getResourceMap();
setupLiveInstances(5);
event.addAttribute(AttributeName.RESOURCES.name(), resourceMap);
CurrentStateComputationStage stage = new CurrentStateComputationStage();
runStage(event, new ReadClusterDataStage());
runStage(event, stage);
CurrentStateOutput output1 = event.getAttribute(AttributeName.CURRENT_STATE.name());
AssertJUnit.assertEquals(
output1.getCurrentStateMap("testResourceName", new Partition("testResourceName_0")).size(),
0);
// Add a state transition messages
Message message = new Message(Message.MessageType.STATE_TRANSITION, "msg1");
message.setFromState("OFFLINE");
message.setToState("SLAVE");
message.setResourceName("testResourceName");
message.setPartitionName("testResourceName_1");
message.setTgtName("localhost_3");
message.setTgtSessionId("session_3");
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.message("localhost_" + 3, message.getId()), message);
runStage(event, new ReadClusterDataStage());
runStage(event, stage);
CurrentStateOutput output2 = event.getAttribute(AttributeName.CURRENT_STATE.name());
String pendingState =
output2.getPendingState("testResourceName", new Partition("testResourceName_1"),
"localhost_3").getToState();
AssertJUnit.assertEquals(pendingState, "SLAVE");
ZNRecord record1 = new ZNRecord("testResourceName");
// Add a current state that matches sessionId and one that does not match
CurrentState stateWithLiveSession = new CurrentState(record1);
stateWithLiveSession.setSessionId("session_3");
stateWithLiveSession.setStateModelDefRef("MasterSlave");
stateWithLiveSession.setState("testResourceName_1", "OFFLINE");
ZNRecord record2 = new ZNRecord("testResourceName");
CurrentState stateWithDeadSession = new CurrentState(record2);
stateWithDeadSession.setSessionId("session_dead");
stateWithDeadSession.setStateModelDefRef("MasterSlave");
stateWithDeadSession.setState("testResourceName_1", "MASTER");
accessor.setProperty(keyBuilder.currentState("localhost_3", "session_3", "testResourceName"),
stateWithLiveSession);
accessor.setProperty(
keyBuilder.currentState("localhost_3", "session_dead", "testResourceName"),
stateWithDeadSession);
runStage(event, new ReadClusterDataStage());
runStage(event, stage);
CurrentStateOutput output3 = event.getAttribute(AttributeName.CURRENT_STATE.name());
String currentState =
output3.getCurrentState("testResourceName", new Partition("testResourceName_1"),
"localhost_3");
AssertJUnit.assertEquals(currentState, "OFFLINE");
}
#location 58
#vulnerability type NULL_DEREFERENCE
|
#fixed code
@Test
public void testSimpleCS() {
// setup resource
Map<String, Resource> resourceMap = getResourceMap();
setupLiveInstances(5);
event.addAttribute(AttributeName.RESOURCES.name(), resourceMap);
event.addAttribute(AttributeName.RESOURCES_TO_REBALANCE.name(), resourceMap);
CurrentStateComputationStage stage = new CurrentStateComputationStage();
runStage(event, new ReadClusterDataStage());
runStage(event, stage);
CurrentStateOutput output1 = event.getAttribute(AttributeName.CURRENT_STATE.name());
AssertJUnit.assertEquals(
output1.getCurrentStateMap("testResourceName", new Partition("testResourceName_0")).size(),
0);
// Add a state transition messages
Message message = new Message(Message.MessageType.STATE_TRANSITION, "msg1");
message.setFromState("OFFLINE");
message.setToState("SLAVE");
message.setResourceName("testResourceName");
message.setPartitionName("testResourceName_1");
message.setTgtName("localhost_3");
message.setTgtSessionId("session_3");
Builder keyBuilder = accessor.keyBuilder();
accessor.setProperty(keyBuilder.message("localhost_" + 3, message.getId()), message);
runStage(event, new ReadClusterDataStage());
runStage(event, stage);
CurrentStateOutput output2 = event.getAttribute(AttributeName.CURRENT_STATE.name());
String pendingState =
output2.getPendingState("testResourceName", new Partition("testResourceName_1"),
"localhost_3").getToState();
AssertJUnit.assertEquals(pendingState, "SLAVE");
ZNRecord record1 = new ZNRecord("testResourceName");
// Add a current state that matches sessionId and one that does not match
CurrentState stateWithLiveSession = new CurrentState(record1);
stateWithLiveSession.setSessionId("session_3");
stateWithLiveSession.setStateModelDefRef("MasterSlave");
stateWithLiveSession.setState("testResourceName_1", "OFFLINE");
ZNRecord record2 = new ZNRecord("testResourceName");
CurrentState stateWithDeadSession = new CurrentState(record2);
stateWithDeadSession.setSessionId("session_dead");
stateWithDeadSession.setStateModelDefRef("MasterSlave");
stateWithDeadSession.setState("testResourceName_1", "MASTER");
accessor.setProperty(keyBuilder.currentState("localhost_3", "session_3", "testResourceName"),
stateWithLiveSession);
accessor.setProperty(
keyBuilder.currentState("localhost_3", "session_dead", "testResourceName"),
stateWithDeadSession);
runStage(event, new ReadClusterDataStage());
runStage(event, stage);
CurrentStateOutput output3 = event.getAttribute(AttributeName.CURRENT_STATE.name());
String currentState =
output3.getCurrentState("testResourceName", new Partition("testResourceName_1"),
"localhost_3");
AssertJUnit.assertEquals(currentState, "OFFLINE");
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
void VerifyEmptyCurrentState(ClusterDataAccessor accessor, ZkClient client, String clusterName, String instanceName, String dbName)
{
String path = CMUtil.getInstancePropertyPath(clusterName, instanceName, InstancePropertyType.CURRENTSTATES);
List<String> subPaths = accessor.getInstancePropertySubPaths(instanceName, InstancePropertyType.CURRENTSTATES);
for(String previousSessionId : subPaths)
{
if(client.exists(path+"/"+previousSessionId+"/" + dbName))
{
ZNRecord previousCurrentState = accessor.getInstanceProperty(instanceName, InstancePropertyType.CURRENTSTATES, previousSessionId, dbName);
AssertJUnit.assertTrue(previousCurrentState.getMapFields().size() == 0);
}
}
}
#location 11
#vulnerability type NULL_DEREFERENCE
|
#fixed code
void verifyEmptyCurrentState(ClusterDataAccessor accessor, ZkClient client, String clusterName, String instanceName, String dbName)
{
String path = CMUtil.getInstancePropertyPath(clusterName, instanceName, InstancePropertyType.CURRENTSTATES);
List<String> subPaths = accessor.getInstancePropertySubPaths(instanceName, InstancePropertyType.CURRENTSTATES);
for(String previousSessionId : subPaths)
{
if(client.exists(path+"/"+previousSessionId+"/" + dbName))
{
ZNRecord previousCurrentState = accessor.getInstanceProperty(instanceName, InstancePropertyType.CURRENTSTATES, previousSessionId, dbName);
AssertJUnit.assertTrue(previousCurrentState.getMapFields().size() == 0);
}
}
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Override
public void disconnect() {
if (_zkclient == null || _zkclient.isClosed()) {
LOG.info("instanceName: " + _instanceName + " already disconnected");
return;
}
LOG.info("disconnect " + _instanceName + "(" + _instanceType + ") from " + _clusterName);
try {
/**
* stop all timer tasks
*/
stopTimerTasks();
/**
* shutdown thread pool first to avoid reset() being invoked in the middle of state
* transition
*/
_messagingService.getExecutor().shutdown();
// TODO reset user defined handlers only
// TODO Fix the issue that when connection disconnected, reset handlers will be blocked. -- JJ
// This is because reset logic contains ZK operations.
resetHandlers(true);
if (_leaderElectionHandler != null) {
_leaderElectionHandler.reset(true);
}
} finally {
GenericHelixController controller = _controller;
if (controller != null) {
try {
controller.shutdown();
} catch (InterruptedException e) {
LOG.info("Interrupted shutting down GenericHelixController", e);
}
}
ParticipantManager participantManager = _participantManager;
if (participantManager != null) {
participantManager.disconnect();
}
for (HelixCallbackMonitor callbackMonitor : _callbackMonitors.values()) {
callbackMonitor.unregister();
}
_helixPropertyStore = null;
synchronized (this) {
if (_controller != null) {
_controller = null;
_leaderElectionHandler = null;
}
if (_participantManager != null) {
_participantManager = null;
}
if (_zkclient != null) {
_zkclient.close();
}
}
_sessionStartTime = null;
LOG.info("Cluster manager: " + _instanceName + " disconnected");
}
}
#location 28
#vulnerability type THREAD_SAFETY_VIOLATION
|
#fixed code
@Override
public void disconnect() {
if (_zkclient == null || _zkclient.isClosed()) {
LOG.info("instanceName: " + _instanceName + " already disconnected");
return;
}
LOG.info("disconnect " + _instanceName + "(" + _instanceType + ") from " + _clusterName);
try {
/**
* stop all timer tasks
*/
stopTimerTasks();
/**
* shutdown thread pool first to avoid reset() being invoked in the middle of state
* transition
*/
_messagingService.getExecutor().shutdown();
if (!cleanupCallbackHandlers()) {
LOG.warn(
"The callback handler cleanup has been cleanly done. "
+ "Some callback handlers might not be reset properly. "
+ "Continue to finish the other Helix Mananger disconnect tasks.");
}
} finally {
GenericHelixController controller = _controller;
if (controller != null) {
try {
controller.shutdown();
} catch (InterruptedException e) {
LOG.info("Interrupted shutting down GenericHelixController", e);
}
}
for (HelixCallbackMonitor callbackMonitor : _callbackMonitors.values()) {
callbackMonitor.unregister();
}
_helixPropertyStore = null;
synchronized (this) {
if (_controller != null) {
_controller = null;
_leaderElectionHandler = null;
}
if (_participantManager != null) {
_participantManager = null;
}
if (_zkclient != null) {
_zkclient.close();
}
}
_sessionStartTime = null;
LOG.info("Cluster manager: " + _instanceName + " disconnected");
}
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
public void testSimpleCS()
{
// setup resource group
Map<String, ResourceGroup> resourceGroupMap = getResourceGroupMap();
setupLiveInstances(5);
event.addAttribute(AttributeName.RESOURCE_GROUPS.toString(),
resourceGroupMap);
CurrentStateComputationStage stage = new CurrentStateComputationStage();
runStage(event, stage);
CurrentStateOutput output1 = event.getAttribute(AttributeName.CURRENT_STATE
.toString());
Assert.assertEquals(
output1.getCurrentStateMap("testResourceGroupName",
new ResourceKey("testResourceGroupName_0")).size(), 0);
// Add a state transition messages
Message message = new Message(Message.MessageType.STATE_TRANSITION, "msg1");
message.setFromState("OFFLINE");
message.setToState("SLAVE");
message.setStateUnitGroup("testResourceGroupName");
message.setStateUnitKey("testResourceGroupName_1");
message.setTgtName("localhost_3");
message.setTgtSessionId("session_3");
accessor.setProperty(PropertyType.MESSAGES, message.getRecord(),
"localhost_" + 3, message.getId());
runStage(event, stage);
CurrentStateOutput output2 = event.getAttribute(AttributeName.CURRENT_STATE
.toString());
String pendingState = output2.getPendingState("testResourceGroupName",
new ResourceKey("testResourceGroupName_1"), "localhost_3");
Assert.assertEquals(pendingState, "SLAVE");
ZNRecord record1 = new ZNRecord("testResourceGroupName");
// Add a current state that matches sessionId and one that does not match
CurrentState stateWithLiveSession = new CurrentState(record1);
stateWithLiveSession.setSessionId("session_3");
stateWithLiveSession.setStateModelDefRef("MasterSlave");
stateWithLiveSession.setState("testResourceGroupName_1", "OFFLINE");
ZNRecord record2 = new ZNRecord("testResourceGroupName");
CurrentState stateWithDeadSession = new CurrentState(record2);
stateWithDeadSession.setSessionId("session_dead");
stateWithDeadSession.setStateModelDefRef("MasterSlave");
stateWithDeadSession.setState("testResourceGroupName_1", "MASTER");
accessor.setProperty(PropertyType.CURRENTSTATES,
stateWithLiveSession.getRecord(), "localhost_3", "session_3",
"testResourceGroupName");
accessor.setProperty(PropertyType.CURRENTSTATES,
stateWithDeadSession.getRecord(), "localhost_3", "session_dead",
"testResourceGroupName");
runStage(event, stage);
CurrentStateOutput output3 = event.getAttribute(AttributeName.CURRENT_STATE
.toString());
String currentState = output3.getCurrentState("testResourceGroupName",
new ResourceKey("testResourceGroupName_1"), "localhost_3");
Assert.assertEquals(currentState, "OFFLINE");
}
#location 56
#vulnerability type NULL_DEREFERENCE
|
#fixed code
public void testSimpleCS()
{
// setup resource group
Map<String, ResourceGroup> resourceGroupMap = getResourceGroupMap();
setupLiveInstances(5);
event.addAttribute(AttributeName.RESOURCE_GROUPS.toString(),
resourceGroupMap);
CurrentStateComputationStage stage = new CurrentStateComputationStage();
runStage(event, new ReadClusterDataStage());
runStage(event, stage);
CurrentStateOutput output1 = event.getAttribute(AttributeName.CURRENT_STATE
.toString());
Assert.assertEquals(
output1.getCurrentStateMap("testResourceGroupName",
new ResourceKey("testResourceGroupName_0")).size(), 0);
// Add a state transition messages
Message message = new Message(Message.MessageType.STATE_TRANSITION, "msg1");
message.setFromState("OFFLINE");
message.setToState("SLAVE");
message.setStateUnitGroup("testResourceGroupName");
message.setStateUnitKey("testResourceGroupName_1");
message.setTgtName("localhost_3");
message.setTgtSessionId("session_3");
accessor.setProperty(PropertyType.MESSAGES, message.getRecord(),
"localhost_" + 3, message.getId());
runStage(event, new ReadClusterDataStage());
runStage(event, stage);
CurrentStateOutput output2 = event.getAttribute(AttributeName.CURRENT_STATE
.toString());
String pendingState = output2.getPendingState("testResourceGroupName",
new ResourceKey("testResourceGroupName_1"), "localhost_3");
Assert.assertEquals(pendingState, "SLAVE");
ZNRecord record1 = new ZNRecord("testResourceGroupName");
// Add a current state that matches sessionId and one that does not match
CurrentState stateWithLiveSession = new CurrentState(record1);
stateWithLiveSession.setSessionId("session_3");
stateWithLiveSession.setStateModelDefRef("MasterSlave");
stateWithLiveSession.setState("testResourceGroupName_1", "OFFLINE");
ZNRecord record2 = new ZNRecord("testResourceGroupName");
CurrentState stateWithDeadSession = new CurrentState(record2);
stateWithDeadSession.setSessionId("session_dead");
stateWithDeadSession.setStateModelDefRef("MasterSlave");
stateWithDeadSession.setState("testResourceGroupName_1", "MASTER");
accessor.setProperty(PropertyType.CURRENTSTATES,
stateWithLiveSession.getRecord(), "localhost_3", "session_3",
"testResourceGroupName");
accessor.setProperty(PropertyType.CURRENTSTATES,
stateWithDeadSession.getRecord(), "localhost_3", "session_dead",
"testResourceGroupName");
runStage(event, new ReadClusterDataStage());
runStage(event, stage);
CurrentStateOutput output3 = event.getAttribute(AttributeName.CURRENT_STATE
.toString());
String currentState = output3.getCurrentState("testResourceGroupName",
new ResourceKey("testResourceGroupName_1"), "localhost_3");
Assert.assertEquals(currentState, "OFFLINE");
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
public void download(String zkPath, String fsPath) throws Exception
{
List<String> children = client.getChildren(zkPath);
if (children != null && children.size() > 0)
{
new File(fsPath).mkdirs();
for (String child : children)
{
String childPath = zkPath.equals("/")? "/" + child : zkPath + "/" + child;
download(childPath, fsPath + "/" + child);
}
} else
{
System.out.println("Saving " + zkPath + " to "
+ new File(fsPath + suffix).getCanonicalPath());
FileWriter fileWriter = new FileWriter(fsPath + suffix);
Object readData = client.readData(zkPath);
if (readData != null)
{
fileWriter.write((String) readData);
}
fileWriter.close();
}
}
#location 12
#vulnerability type RESOURCE_LEAK
|
#fixed code
public void download(String zkPath, String fsPath) throws Exception {
List<String> children = client.getChildren(zkPath);
if (children != null && children.size() > 0) {
new File(fsPath).mkdirs();
for (String child : children) {
String childPath = zkPath.equals("/") ? "/" + child : zkPath + "/" + child;
download(childPath, fsPath + "/" + child);
}
} else {
System.out
.println("Saving " + zkPath + " to " + new File(fsPath + suffix).getCanonicalPath());
OutputStream out = new FileOutputStream(fsPath + suffix);
Object readData = client.readData(zkPath);
if (readData != null) {
out.write((byte[]) readData);
}
out.close();
}
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
void stopRebalancingTimer() {
if (_rebalanceTimer != null) {
_rebalanceTimer.cancel();
_rebalanceTimer = null;
}
_timerPeriod = Integer.MAX_VALUE;
}
#location 6
#vulnerability type THREAD_SAFETY_VIOLATION
|
#fixed code
void startRebalancingTimer(long period, HelixManager manager) {
if (period != _timerPeriod) {
logger.info("Controller starting timer at period " + period);
if (_rebalanceTimer != null) {
_rebalanceTimer.cancel();
}
_rebalanceTimer = new Timer(true);
_timerPeriod = period;
_rebalanceTimer
.scheduleAtFixedRate(new RebalanceTask(manager), _timerPeriod, _timerPeriod);
} else {
logger.info("Controller already has timer at period " + _timerPeriod);
}
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
protected void handleNewSession()
{
boolean isConnected = _zkClient.waitUntilConnected(CONNECTIONTIMEOUT, TimeUnit.MILLISECONDS);
while (!isConnected)
{
logger.error("Could NOT connect to zk server in " + CONNECTIONTIMEOUT + "ms. zkServer: "
+ _zkConnectString + ", expiredSessionId: " + _sessionId + ", clusterName: "
+ _clusterName);
isConnected = _zkClient.waitUntilConnected(CONNECTIONTIMEOUT, TimeUnit.MILLISECONDS);
}
ZkConnection zkConnection = ((ZkConnection) _zkClient.getConnection());
synchronized (this)
{
_sessionId = Long.toHexString(zkConnection.getZookeeper().getSessionId());
}
_baseDataAccessor.reset();
// reset all handlers so they have a chance to unsubscribe zk changes from zkclient
// abandon all callback-handlers added in expired session
resetHandlers();
_handlers = new ArrayList<CallbackHandler>();
logger.info("Handling new session, session id:" + _sessionId + ", instance:"
+ _instanceName + ", instanceTye: " + _instanceType + ", cluster: " + _clusterName);
logger.info(zkConnection.getZookeeper());
if (!ZKUtil.isClusterSetup(_clusterName, _zkClient))
{
throw new HelixException("Initial cluster structure is not set up for cluster:"
+ _clusterName);
}
// Read cluster config and see if instance can auto join the cluster
boolean autoJoin = false;
try
{
ConfigScope scope =
new ConfigScopeBuilder().forCluster(getClusterName())
.build();
autoJoin = Boolean.parseBoolean(getConfigAccessor().get(scope, ALLOW_PARTICIPANT_AUTO_JOIN));
logger.info("Auto joining " + _clusterName +" is true");
}
catch(Exception e)
{
}
if (!ZKUtil.isInstanceSetup(_zkClient, _clusterName, _instanceName, _instanceType))
{
if(!autoJoin)
{
throw new HelixException("Initial cluster structure is not set up for instance:"
+ _instanceName + " instanceType:" + _instanceType);
}
else
{
logger.info("Auto joining instance " + _instanceName);
InstanceConfig instanceConfig = new InstanceConfig(_instanceName);
String hostName = _instanceName;
String port = "";
int lastPos = _instanceName.lastIndexOf("_");
if (lastPos > 0)
{
hostName = _instanceName.substring(0, lastPos);
port = _instanceName.substring(lastPos + 1);
}
instanceConfig.setHostName(hostName);
instanceConfig.setPort(port);
instanceConfig.setInstanceEnabled(true);
getClusterManagmentTool().addInstance(_clusterName, instanceConfig);
}
}
if (_instanceType == InstanceType.PARTICIPANT
|| _instanceType == InstanceType.CONTROLLER_PARTICIPANT)
{
handleNewSessionAsParticipant();
}
if (_instanceType == InstanceType.CONTROLLER
|| _instanceType == InstanceType.CONTROLLER_PARTICIPANT)
{
addControllerMessageListener(_messagingService.getExecutor());
MessageHandlerFactory defaultControllerMsgHandlerFactory =
new DefaultControllerMessageHandlerFactory();
_messagingService.getExecutor()
.registerMessageHandlerFactory(defaultControllerMsgHandlerFactory.getMessageType(),
defaultControllerMsgHandlerFactory);
MessageHandlerFactory defaultSchedulerMsgHandlerFactory =
new DefaultSchedulerMessageHandlerFactory(this);
_messagingService.getExecutor()
.registerMessageHandlerFactory(defaultSchedulerMsgHandlerFactory.getMessageType(),
defaultSchedulerMsgHandlerFactory);
MessageHandlerFactory defaultParticipantErrorMessageHandlerFactory =
new DefaultParticipantErrorMessageHandlerFactory(this);
_messagingService.getExecutor()
.registerMessageHandlerFactory(defaultParticipantErrorMessageHandlerFactory.getMessageType(),
defaultParticipantErrorMessageHandlerFactory);
// create a new leader-election handler for a new session
if (_leaderElectionHandler != null) {
_leaderElectionHandler.reset();
}
_leaderElectionHandler =
createCallBackHandler(new Builder(_clusterName).controller(),
new DistClusterControllerElection(_zkConnectString),
new EventType[] { EventType.NodeChildrenChanged,
EventType.NodeDeleted, EventType.NodeCreated },
ChangeType.CONTROLLER);
}
if (_instanceType == InstanceType.PARTICIPANT
|| _instanceType == InstanceType.CONTROLLER_PARTICIPANT
|| (_instanceType == InstanceType.CONTROLLER && isLeader()))
{
initHandlers();
}
}
#location 23
#vulnerability type THREAD_SAFETY_VIOLATION
|
#fixed code
protected void handleNewSession()
{
boolean isConnected = _zkClient.waitUntilConnected(CONNECTIONTIMEOUT, TimeUnit.MILLISECONDS);
while (!isConnected)
{
logger.error("Could NOT connect to zk server in " + CONNECTIONTIMEOUT + "ms. zkServer: "
+ _zkConnectString + ", expiredSessionId: " + _sessionId + ", clusterName: "
+ _clusterName);
isConnected = _zkClient.waitUntilConnected(CONNECTIONTIMEOUT, TimeUnit.MILLISECONDS);
}
ZkConnection zkConnection = ((ZkConnection) _zkClient.getConnection());
synchronized (this)
{
_sessionId = Long.toHexString(zkConnection.getZookeeper().getSessionId());
}
_baseDataAccessor.reset();
// reset all handlers so they have a chance to unsubscribe zk changes from zkclient
// abandon all callback-handlers added in expired session
resetHandlers();
logger.info("Handling new session, session id:" + _sessionId + ", instance:"
+ _instanceName + ", instanceTye: " + _instanceType + ", cluster: " + _clusterName);
logger.info(zkConnection.getZookeeper());
if (!ZKUtil.isClusterSetup(_clusterName, _zkClient))
{
throw new HelixException("Initial cluster structure is not set up for cluster:"
+ _clusterName);
}
// Read cluster config and see if instance can auto join the cluster
boolean autoJoin = false;
try
{
ConfigScope scope =
new ConfigScopeBuilder().forCluster(getClusterName())
.build();
autoJoin = Boolean.parseBoolean(getConfigAccessor().get(scope, ALLOW_PARTICIPANT_AUTO_JOIN));
logger.info("Auto joining " + _clusterName +" is true");
}
catch(Exception e)
{
}
if (!ZKUtil.isInstanceSetup(_zkClient, _clusterName, _instanceName, _instanceType))
{
if(!autoJoin)
{
throw new HelixException("Initial cluster structure is not set up for instance:"
+ _instanceName + " instanceType:" + _instanceType);
}
else
{
logger.info("Auto joining instance " + _instanceName);
InstanceConfig instanceConfig = new InstanceConfig(_instanceName);
String hostName = _instanceName;
String port = "";
int lastPos = _instanceName.lastIndexOf("_");
if (lastPos > 0)
{
hostName = _instanceName.substring(0, lastPos);
port = _instanceName.substring(lastPos + 1);
}
instanceConfig.setHostName(hostName);
instanceConfig.setPort(port);
instanceConfig.setInstanceEnabled(true);
getClusterManagmentTool().addInstance(_clusterName, instanceConfig);
}
}
if (_instanceType == InstanceType.PARTICIPANT
|| _instanceType == InstanceType.CONTROLLER_PARTICIPANT)
{
handleNewSessionAsParticipant();
}
if (_instanceType == InstanceType.CONTROLLER
|| _instanceType == InstanceType.CONTROLLER_PARTICIPANT)
{
addControllerMessageListener(_messagingService.getExecutor());
MessageHandlerFactory defaultControllerMsgHandlerFactory =
new DefaultControllerMessageHandlerFactory();
_messagingService.getExecutor()
.registerMessageHandlerFactory(defaultControllerMsgHandlerFactory.getMessageType(),
defaultControllerMsgHandlerFactory);
MessageHandlerFactory defaultSchedulerMsgHandlerFactory =
new DefaultSchedulerMessageHandlerFactory(this);
_messagingService.getExecutor()
.registerMessageHandlerFactory(defaultSchedulerMsgHandlerFactory.getMessageType(),
defaultSchedulerMsgHandlerFactory);
MessageHandlerFactory defaultParticipantErrorMessageHandlerFactory =
new DefaultParticipantErrorMessageHandlerFactory(this);
_messagingService.getExecutor()
.registerMessageHandlerFactory(defaultParticipantErrorMessageHandlerFactory.getMessageType(),
defaultParticipantErrorMessageHandlerFactory);
if (_leaderElectionHandler != null) {
_leaderElectionHandler.reset();
_leaderElectionHandler.init();
} else {
_leaderElectionHandler =
createCallBackHandler(new Builder(_clusterName).controller(),
new DistClusterControllerElection(_zkConnectString),
new EventType[] { EventType.NodeChildrenChanged,
EventType.NodeDeleted, EventType.NodeCreated },
ChangeType.CONTROLLER);
}
}
if (_instanceType == InstanceType.PARTICIPANT
|| _instanceType == InstanceType.CONTROLLER_PARTICIPANT
|| (_instanceType == InstanceType.CONTROLLER && isLeader()))
{
initHandlers();
}
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
private BestPossibleStateOutput compute(ClusterEvent event, Map<String, Resource> resourceMap,
CurrentStateOutput currentStateOutput) {
ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());
BestPossibleStateOutput output = new BestPossibleStateOutput();
PriorityQueue<ResourcePriority> resourcePriorityQueue = new PriorityQueue<>();
TaskDriver taskDriver = null;
HelixManager helixManager = event.getAttribute(AttributeName.helixmanager.name());
if (helixManager != null) {
taskDriver = new TaskDriver(helixManager);
}
for (Resource resource : resourceMap.values()) {
resourcePriorityQueue.add(new ResourcePriority(resource, cache.getIdealState(resource.getResourceName()),
taskDriver));
}
final List<String> failureResources = new ArrayList<>();
Iterator<ResourcePriority> itr = resourcePriorityQueue.iterator();
while (itr.hasNext()) {
Resource resource = itr.next().getResource();
if (!computeResourceBestPossibleState(event, cache, currentStateOutput, resource, output)) {
failureResources.add(resource.getResourceName());
LogUtil.logWarn(logger, _eventId, "Failed to calculate best possible states for " + resource.getResourceName());
}
}
// Check and report if resource rebalance has failure
if (!cache.isTaskCache()) {
ClusterStatusMonitor clusterStatusMonitor =
event.getAttribute(AttributeName.clusterStatusMonitor.name());
updateRebalanceStatus(!failureResources.isEmpty(), helixManager, cache, clusterStatusMonitor,
"Failed to calculate best possible states for " + failureResources.size()
+ " resources.");
}
return output;
}
#location 13
#vulnerability type NULL_DEREFERENCE
|
#fixed code
private BestPossibleStateOutput compute(ClusterEvent event, Map<String, Resource> resourceMap,
CurrentStateOutput currentStateOutput) {
ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());
BestPossibleStateOutput output = new BestPossibleStateOutput();
HelixManager helixManager = event.getAttribute(AttributeName.helixmanager.name());
final List<String> failureResources = new ArrayList<>();
Iterator<Resource> itr = resourceMap.values().iterator();
while (itr.hasNext()) {
Resource resource = itr.next();
if (!computeResourceBestPossibleState(event, cache, currentStateOutput, resource, output)) {
failureResources.add(resource.getResourceName());
LogUtil.logWarn(logger, _eventId,
"Failed to calculate best possible states for " + resource.getResourceName());
}
}
// Check and report if resource rebalance has failure
ClusterStatusMonitor clusterStatusMonitor =
event.getAttribute(AttributeName.clusterStatusMonitor.name());
updateRebalanceStatus(!failureResources.isEmpty(), helixManager, cache, clusterStatusMonitor,
"Failed to calculate best possible states for " + failureResources.size() + " resources.");
return output;
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
void createClient() throws Exception {
final RealmAwareZkClient newClient = createSingleRealmZkClient();
synchronized (this) {
if (_zkclient != null) {
_zkclient.close();
}
_zkclient = newClient;
_baseDataAccessor = createBaseDataAccessor();
_dataAccessor = new ZKHelixDataAccessor(_clusterName, _instanceType, _baseDataAccessor);
_configAccessor = new ConfigAccessor(_zkclient);
if (_instanceType == InstanceType.CONTROLLER
|| _instanceType == InstanceType.CONTROLLER_PARTICIPANT) {
addBuiltInStateModelDefinitions();
}
}
// subscribe to state change
_zkclient.subscribeStateChanges(this);
int retryCount = 0;
while (retryCount < 3) {
try {
final long sessionId =
_zkclient.waitForEstablishedSession(_connectionInitTimeout, TimeUnit.MILLISECONDS);
handleStateChanged(KeeperState.SyncConnected);
/*
* This listener is subscribed after SyncConnected and firing new session events,
* which means this listener has not yet handled new session, so we have to handle new
* session here just for this listener.
*/
handleNewSession(ZKUtil.toHexSessionId(sessionId));
break;
} catch (HelixException e) {
LOG.error("fail to createClient.", e);
throw e;
} catch (Exception e) {
retryCount++;
LOG.error("fail to createClient. retry " + retryCount, e);
if (retryCount == 3) {
throw e;
}
}
}
}
#location 17
#vulnerability type THREAD_SAFETY_VIOLATION
|
#fixed code
void checkConnected() {
checkConnected(-1);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
public void setInfo(String partitionName, String info) {
Map<String, Map<String, String>> mapFields = _record.getMapFields();
if (mapFields.get(partitionName) == null) {
mapFields.put(partitionName, new TreeMap<String, String>());
}
mapFields.get(partitionName).put(CurrentStateProperty.INFO.name(), info);
}
#location 6
#vulnerability type NULL_DEREFERENCE
|
#fixed code
public void setInfo(String partitionName, String info) {
setProperty(partitionName, CurrentStateProperty.INFO, info);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Override
public Object deserialize(byte[] bytes) throws ZkMarshallingError {
if (bytes == null || bytes.length == 0) {
LOG.error("ZNode is empty.");
return null;
}
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ZNRecord record = null;
try {
JsonFactory f = new JsonFactory();
JsonParser jp = f.createJsonParser(bais);
jp.nextToken(); // will return JsonToken.START_OBJECT (verify?)
while (jp.nextToken() != JsonToken.END_OBJECT) {
String fieldname = jp.getCurrentName();
jp.nextToken(); // move to value, or START_OBJECT/START_ARRAY
if ("id".equals(fieldname)) {
// contains an object
record = new ZNRecord(jp.getText());
} else if ("simpleFields".equals(fieldname)) {
while (jp.nextToken() != JsonToken.END_OBJECT) {
String key = jp.getCurrentName();
jp.nextToken(); // move to value
record.setSimpleField(key, jp.getText());
}
} else if ("mapFields".equals(fieldname)) {
// user.setVerified(jp.getCurrentToken() == JsonToken.VALUE_TRUE);
while (jp.nextToken() != JsonToken.END_OBJECT) {
String key = jp.getCurrentName();
record.setMapField(key, new TreeMap<String, String>());
jp.nextToken(); // move to value
while (jp.nextToken() != JsonToken.END_OBJECT) {
String mapKey = jp.getCurrentName();
jp.nextToken(); // move to value
record.getMapField(key).put(mapKey, jp.getText());
}
}
} else if ("listFields".equals(fieldname)) {
// user.setUserImage(jp.getBinaryValue());
while (jp.nextToken() != JsonToken.END_OBJECT) {
String key = jp.getCurrentName();
record.setListField(key, new ArrayList<String>());
jp.nextToken(); // move to value
while (jp.nextToken() != JsonToken.END_ARRAY) {
record.getListField(key).add(jp.getText());
}
}
} else if ("rawPayload".equals(fieldname)) {
record.setRawPayload(Base64.decode(jp.getText()));
} else {
throw new IllegalStateException("Unrecognized field '" + fieldname + "'!");
}
}
jp.close(); // ensure resources get cleaned up timely and properly
} catch (Exception e) {
LOG.error("Exception during deserialization of bytes: " + new String(bytes), e);
}
return record;
}
#location 55
#vulnerability type NULL_DEREFERENCE
|
#fixed code
@Override
public Object deserialize(byte[] bytes) throws ZkMarshallingError {
if (bytes == null || bytes.length == 0) {
LOG.error("ZNode is empty.");
return null;
}
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ZNRecord record = null;
String id = null;
Map<String, String> simpleFields = Maps.newHashMap();
Map<String, List<String>> listFields = Maps.newHashMap();
Map<String, Map<String, String>> mapFields = Maps.newHashMap();
byte[] rawPayload = null;
try {
JsonFactory f = new JsonFactory();
JsonParser jp = f.createJsonParser(bais);
jp.nextToken(); // will return JsonToken.START_OBJECT (verify?)
while (jp.nextToken() != JsonToken.END_OBJECT) {
String fieldname = jp.getCurrentName();
jp.nextToken(); // move to value, or START_OBJECT/START_ARRAY
if ("id".equals(fieldname)) {
// contains an object
id = jp.getText();
} else if ("simpleFields".equals(fieldname)) {
while (jp.nextToken() != JsonToken.END_OBJECT) {
String key = jp.getCurrentName();
jp.nextToken(); // move to value
simpleFields.put(key, jp.getText());
}
} else if ("mapFields".equals(fieldname)) {
// user.setVerified(jp.getCurrentToken() == JsonToken.VALUE_TRUE);
while (jp.nextToken() != JsonToken.END_OBJECT) {
String key = jp.getCurrentName();
mapFields.put(key, new TreeMap<String, String>());
jp.nextToken(); // move to value
while (jp.nextToken() != JsonToken.END_OBJECT) {
String mapKey = jp.getCurrentName();
jp.nextToken(); // move to value
mapFields.get(key).put(mapKey, jp.getText());
}
}
} else if ("listFields".equals(fieldname)) {
// user.setUserImage(jp.getBinaryValue());
while (jp.nextToken() != JsonToken.END_OBJECT) {
String key = jp.getCurrentName();
listFields.put(key, new ArrayList<String>());
jp.nextToken(); // move to value
while (jp.nextToken() != JsonToken.END_ARRAY) {
listFields.get(key).add(jp.getText());
}
}
} else if ("rawPayload".equals(fieldname)) {
rawPayload = Base64.decode(jp.getText());
} else {
throw new IllegalStateException("Unrecognized field '" + fieldname + "'!");
}
}
jp.close(); // ensure resources get cleaned up timely and properly
if (id == null) {
throw new IllegalStateException("ZNRecord id field is required!");
}
record = new ZNRecord(id);
record.setSimpleFields(simpleFields);
record.setListFields(listFields);
record.setMapFields(mapFields);
record.setRawPayload(rawPayload);
} catch (Exception e) {
LOG.error("Exception during deserialization of bytes: " + new String(bytes), e);
}
return record;
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
public boolean waitForKeeperState(KeeperState keeperState, long time, TimeUnit timeUnit)
throws ZkInterruptedException {
if (_zookeeperEventThread != null && Thread.currentThread() == _zookeeperEventThread) {
throw new IllegalArgumentException("Must not be done in the zookeeper event thread.");
}
Date timeout = new Date(System.currentTimeMillis() + timeUnit.toMillis(time));
LOG.debug("Waiting for keeper state " + keeperState);
acquireEventLock();
try {
boolean stillWaiting = true;
while (_currentState != keeperState) {
if (!stillWaiting) {
return false;
}
stillWaiting = getEventLock().getStateChangedCondition().awaitUntil(timeout);
}
LOG.debug("State is " + (_currentState == null ? "CLOSED" : _currentState));
return true;
} catch (InterruptedException e) {
throw new ZkInterruptedException(e);
} finally {
getEventLock().unlock();
}
}
#location 3
#vulnerability type THREAD_SAFETY_VIOLATION
|
#fixed code
public boolean waitForKeeperState(KeeperState keeperState, long time, TimeUnit timeUnit)
throws ZkInterruptedException {
validateCurrentThread();
Date timeout = new Date(System.currentTimeMillis() + timeUnit.toMillis(time));
LOG.debug("Waiting for keeper state " + keeperState);
acquireEventLock();
try {
boolean stillWaiting = true;
while (_currentState != keeperState) {
if (!stillWaiting) {
return false;
}
stillWaiting = getEventLock().getStateChangedCondition().awaitUntil(timeout);
}
LOG.debug("State is " + (_currentState == null ? "CLOSED" : _currentState));
return true;
} catch (InterruptedException e) {
throw new ZkInterruptedException(e);
} finally {
getEventLock().unlock();
}
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Override
public void onControllerChange(NotificationContext changeContext) {
logger.info("START: GenericClusterController.onControllerChange() for cluster " + _clusterName);
_cache.requireFullRefresh();
if (changeContext != null && changeContext.getType() == Type.FINALIZE) {
logger.info("GenericClusterController.onControllerChange() FINALIZE for cluster " + _clusterName);
return;
}
HelixDataAccessor accessor = changeContext.getManager().getHelixDataAccessor();
// double check if this controller is the leader
Builder keyBuilder = accessor.keyBuilder();
LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
if (leader == null) {
logger
.warn("No controller exists for cluster:" + changeContext.getManager().getClusterName());
return;
} else {
String leaderName = leader.getInstanceName();
String instanceName = changeContext.getManager().getInstanceName();
if (leaderName == null || !leaderName.equals(instanceName)) {
logger.warn("leader name does NOT match, my name: " + instanceName + ", leader: " + leader);
return;
}
}
PauseSignal pauseSignal = accessor.getProperty(keyBuilder.pause());
if (pauseSignal != null) {
if (!_paused) {
_paused = true;
logger.info("controller is now paused");
}
} else {
if (_paused) {
_paused = false;
logger.info("controller is now resumed");
ClusterEvent event = new ClusterEvent(_clusterName, ClusterEventType.Resume);
event.addAttribute(AttributeName.changeContext.name(), changeContext);
event.addAttribute(AttributeName.helixmanager.name(), changeContext.getManager());
event.addAttribute(AttributeName.eventData.name(), pauseSignal);
_eventQueue.put(event);
}
}
if (_clusterStatusMonitor == null) {
_clusterStatusMonitor = new ClusterStatusMonitor(changeContext.getManager().getClusterName());
}
_clusterStatusMonitor.setEnabled(!_paused);
logger.info("END: GenericClusterController.onControllerChange() for cluster " + _clusterName);
}
#location 46
#vulnerability type THREAD_SAFETY_VIOLATION
|
#fixed code
@Override
public void onControllerChange(NotificationContext changeContext) {
logger.info("START: GenericClusterController.onControllerChange() for cluster " + _clusterName);
_cache.requireFullRefresh();
_taskCache.requireFullRefresh();
if (changeContext != null && changeContext.getType() == Type.FINALIZE) {
logger.info("GenericClusterController.onControllerChange() FINALIZE for cluster " + _clusterName);
return;
}
HelixDataAccessor accessor = changeContext.getManager().getHelixDataAccessor();
// double check if this controller is the leader
Builder keyBuilder = accessor.keyBuilder();
LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
if (leader == null) {
logger
.warn("No controller exists for cluster:" + changeContext.getManager().getClusterName());
return;
} else {
String leaderName = leader.getInstanceName();
String instanceName = changeContext.getManager().getInstanceName();
if (leaderName == null || !leaderName.equals(instanceName)) {
logger.warn("leader name does NOT match, my name: " + instanceName + ", leader: " + leader);
return;
}
}
PauseSignal pauseSignal = accessor.getProperty(keyBuilder.pause());
if (pauseSignal != null) {
if (!_paused) {
_paused = true;
logger.info("controller is now paused");
}
} else {
if (_paused) {
_paused = false;
logger.info("controller is now resumed");
ClusterEvent event = new ClusterEvent(_clusterName, ClusterEventType.Resume);
event.addAttribute(AttributeName.changeContext.name(), changeContext);
event.addAttribute(AttributeName.helixmanager.name(), changeContext.getManager());
event.addAttribute(AttributeName.eventData.name(), pauseSignal);
_eventQueue.put(event);
_taskEventQueue.put(event.clone());
}
}
if (_clusterStatusMonitor == null) {
_clusterStatusMonitor = new ClusterStatusMonitor(changeContext.getManager().getClusterName());
}
_clusterStatusMonitor.setEnabled(!_paused);
logger.info("END: GenericClusterController.onControllerChange() for cluster " + _clusterName);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test
public void testInvocation() throws Exception
{
System.out.println("TestCMTaskHandler.testInvocation()");
Message message = new Message(MessageType.STATE_TRANSITION);
message.setSrcName("cm-instance-0");
message.setTgtSessionId("1234");
message.setFromState("Offline");
message.setToState("Slave");
message.setStateUnitKey("Teststateunitkey");
message.setId("Some unique id");
message.setMsgId("Some unique message id");
message.setStateUnitGroup("TeststateunitGroup");
MockStateModel stateModel = new MockStateModel();
NotificationContext context;
context = new NotificationContext(new MockManager());
CMTaskHandler handler;
handler = new CMTaskHandler(message, context, null, null);
handler.call();
AssertJUnit.assertTrue(stateModel.stateModelInvoked);
}
#location 20
#vulnerability type NULL_DEREFERENCE
|
#fixed code
@Test
public void testInvocation() throws Exception
{
System.out.println("TestCMTaskHandler.testInvocation()");
Message message = new Message(MessageType.STATE_TRANSITION);
message.setSrcName("cm-instance-0");
message.setTgtSessionId("1234");
message.setFromState("Offline");
message.setToState("Slave");
message.setStateUnitKey("Teststateunitkey");
message.setId("Some unique id");
message.setMsgId("Some unique message id");
message.setStateUnitGroup("TeststateunitGroup");
MockStateModel stateModel = new MockStateModel();
NotificationContext context;
CMStateTransitionHandler stHandler = new CMStateTransitionHandler(stateModel);
context = new NotificationContext(new MockManager());
CMTaskHandler handler;
handler = new CMTaskHandler(message, context, stHandler, null);
handler.call();
AssertJUnit.assertTrue(stateModel.stateModelInvoked);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
void checkRebalancingTimer(HelixManager manager, List<IdealState> idealStates) {
if (manager.getConfigAccessor() == null) {
logger.warn(manager.getInstanceName()
+ " config accessor doesn't exist. should be in file-based mode.");
return;
}
for (IdealState idealState : idealStates) {
int period = idealState.getRebalanceTimerPeriod();
if (period > 0) {
startRebalancingTimer(period, manager);
}
}
}
#location 11
#vulnerability type THREAD_SAFETY_VIOLATION
|
#fixed code
void startRebalancingTimer(long period, HelixManager manager) {
if (period != _timerPeriod) {
logger.info("Controller starting timer at period " + period);
if (_rebalanceTimer != null) {
_rebalanceTimer.cancel();
}
_rebalanceTimer = new Timer(true);
_timerPeriod = period;
_rebalanceTimer.scheduleAtFixedRate(new RebalanceTask(manager), _timerPeriod, _timerPeriod);
} else {
logger.info("Controller already has timer at period " + _timerPeriod);
}
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Override
public void execute(final ClusterEvent event) throws Exception {
_eventId = event.getEventId();
HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES.name());
ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());
if (manager == null || resourceMap == null || cache == null) {
throw new StageException("Missing attributes in event:" + event
+ ". Requires ClusterManager|RESOURCES|DataCache");
}
HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
CurrentStateOutput currentStateOutput =
event.getAttribute(AttributeName.CURRENT_STATE.name());
List<ExternalView> newExtViews = new ArrayList<>();
Map<String, ExternalView> curExtViews = cache.getExternalViews();
for (String resourceName : resourceMap.keySet()) {
ExternalView view = new ExternalView(resourceName);
// view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
// if resource ideal state has bucket size, set it
// otherwise resource has been dropped, use bucket size from current state instead
Resource resource = resourceMap.get(resourceName);
if (resource.getBucketSize() > 0) {
view.setBucketSize(resource.getBucketSize());
} else {
view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
}
int totalPendingMessageCount = 0;
for (Partition partition : resource.getPartitions()) {
Map<String, String> currentStateMap =
currentStateOutput.getCurrentStateMap(resourceName, partition);
if (currentStateMap != null && currentStateMap.size() > 0) {
// Set<String> disabledInstances
// = cache.getDisabledInstancesForResource(resource.toString());
for (String instance : currentStateMap.keySet()) {
// if (!disabledInstances.contains(instance))
// {
view.setState(partition.getPartitionName(), instance, currentStateMap.get(instance));
// }
}
}
totalPendingMessageCount +=
currentStateOutput.getPendingMessageMap(resource.getResourceName(), partition).size();
}
// Update cluster status monitor mbean
IdealState idealState = cache.getIdealState(resourceName);
if (!cache.isTaskCache()) {
ResourceConfig resourceConfig = cache.getResourceConfig(resourceName);
ClusterStatusMonitor clusterStatusMonitor =
event.getAttribute(AttributeName.clusterStatusMonitor.name());
if (clusterStatusMonitor != null) {
if (idealState != null && (resourceConfig == null || !resourceConfig
.isMonitoringDisabled())) {
if (!idealState.getStateModelDefRef()
.equalsIgnoreCase(DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE)) {
StateModelDefinition stateModelDef =
cache.getStateModelDef(idealState.getStateModelDefRef());
clusterStatusMonitor
.setResourceStatus(view, cache.getIdealState(view.getResourceName()),
stateModelDef);
clusterStatusMonitor
.updatePendingMessages(resource.getResourceName(), totalPendingMessageCount);
}
} else {
// Drop the metrics if the resource is dropped, or the MonitorDisabled is changed to true.
clusterStatusMonitor.unregisterResource(view.getResourceName());
}
}
}
ExternalView curExtView = curExtViews.get(resourceName);
// copy simplefields from IS, in cases where IS is deleted copy it from existing ExternalView
if (idealState != null) {
view.getRecord().getSimpleFields().putAll(idealState.getRecord().getSimpleFields());
} else if (curExtView != null) {
view.getRecord().getSimpleFields().putAll(curExtView.getRecord().getSimpleFields());
}
// compare the new external view with current one, set only on different
if (curExtView == null || !curExtView.getRecord().equals(view.getRecord())) {
// Add external view to the list which will be written to ZK later.
newExtViews.add(view);
// For SCHEDULER_TASK_RESOURCE resource group (helix task queue), we need to find out which
// task partitions are finished (COMPLETED or ERROR), update the status update of the original
// scheduler message, and then remove the partitions from the ideal state
if (idealState != null
&& idealState.getStateModelDefRef().equalsIgnoreCase(
DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE)) {
updateScheduledTaskStatus(view, manager, idealState);
}
}
}
List<String> externalviewsToRemove = new ArrayList<>();
// TODO: consider not setting the externalview of SCHEDULER_TASK_QUEUE at all.
// Are there any entity that will be interested in its change?
// For the resource with DisableExternalView option turned on in IdealState
// We will not actually create or write the externalView to ZooKeeper.
List<PropertyKey> keys = new ArrayList<>();
for(Iterator<ExternalView> it = newExtViews.iterator(); it.hasNext(); ) {
ExternalView view = it.next();
String resourceName = view.getResourceName();
IdealState idealState = cache.getIdealState(resourceName);
if (idealState != null && idealState.isExternalViewDisabled()) {
it.remove();
// remove the external view if the external view exists
if (curExtViews.containsKey(resourceName)) {
LogUtil
.logInfo(LOG, _eventId, "Remove externalView for resource: " + resourceName);
dataAccessor.removeProperty(keyBuilder.externalView(resourceName));
externalviewsToRemove.add(resourceName);
}
} else {
keys.add(keyBuilder.externalView(resourceName));
}
}
// add/update external-views
if (newExtViews.size() > 0) {
dataAccessor.setChildren(keys, newExtViews);
cache.updateExternalViews(newExtViews);
}
// remove dead external-views
for (String resourceName : curExtViews.keySet()) {
if (!resourceMap.keySet().contains(resourceName)) {
LogUtil.logInfo(LOG, _eventId, "Remove externalView for resource: " + resourceName);
dataAccessor.removeProperty(keyBuilder.externalView(resourceName));
externalviewsToRemove.add(resourceName);
}
}
cache.removeExternalViews(externalviewsToRemove);
}
#location 32
#vulnerability type NULL_DEREFERENCE
|
#fixed code
@Override
public void execute(final ClusterEvent event) throws Exception {
_eventId = event.getEventId();
HelixManager manager = event.getAttribute(AttributeName.helixmanager.name());
Map<String, Resource> resourceMap = event.getAttribute(AttributeName.RESOURCES.name());
ClusterDataCache cache = event.getAttribute(AttributeName.ClusterDataCache.name());
if (manager == null || resourceMap == null || cache == null) {
throw new StageException("Missing attributes in event:" + event
+ ". Requires ClusterManager|RESOURCES|DataCache");
}
HelixDataAccessor dataAccessor = manager.getHelixDataAccessor();
PropertyKey.Builder keyBuilder = dataAccessor.keyBuilder();
CurrentStateOutput currentStateOutput =
event.getAttribute(AttributeName.CURRENT_STATE.name());
ClusterStatusMonitor clusterStatusMonitor =
event.getAttribute(AttributeName.clusterStatusMonitor.name());
List<ExternalView> newExtViews = new ArrayList<>();
Set<String> monitoringResources = new HashSet<>();
Map<String, ExternalView> curExtViews = cache.getExternalViews();
for (String resourceName : resourceMap.keySet()) {
ExternalView view = new ExternalView(resourceName);
// view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
// if resource ideal state has bucket size, set it
// otherwise resource has been dropped, use bucket size from current state instead
Resource resource = resourceMap.get(resourceName);
if (resource.getBucketSize() > 0) {
view.setBucketSize(resource.getBucketSize());
} else {
view.setBucketSize(currentStateOutput.getBucketSize(resourceName));
}
int totalPendingMessageCount = 0;
for (Partition partition : resource.getPartitions()) {
Map<String, String> currentStateMap =
currentStateOutput.getCurrentStateMap(resourceName, partition);
if (currentStateMap != null && currentStateMap.size() > 0) {
// Set<String> disabledInstances
// = cache.getDisabledInstancesForResource(resource.toString());
for (String instance : currentStateMap.keySet()) {
// if (!disabledInstances.contains(instance))
// {
view.setState(partition.getPartitionName(), instance, currentStateMap.get(instance));
// }
}
}
totalPendingMessageCount +=
currentStateOutput.getPendingMessageMap(resource.getResourceName(), partition).size();
}
// Update cluster status monitor mbean
IdealState idealState = cache.getIdealState(resourceName);
if (!cache.isTaskCache()) {
ResourceConfig resourceConfig = cache.getResourceConfig(resourceName);
if (clusterStatusMonitor != null) {
if (idealState != null // has ideal state
&& (resourceConfig == null || !resourceConfig.isMonitoringDisabled()) // monitoring not disabled
&& !idealState.getStateModelDefRef() // and not a job resource
.equalsIgnoreCase(DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE)) {
StateModelDefinition stateModelDef =
cache.getStateModelDef(idealState.getStateModelDefRef());
clusterStatusMonitor
.setResourceStatus(view, cache.getIdealState(view.getResourceName()),
stateModelDef);
clusterStatusMonitor
.updatePendingMessages(resource.getResourceName(), totalPendingMessageCount);
monitoringResources.add(resourceName);
}
}
}
ExternalView curExtView = curExtViews.get(resourceName);
// copy simplefields from IS, in cases where IS is deleted copy it from existing ExternalView
if (idealState != null) {
view.getRecord().getSimpleFields().putAll(idealState.getRecord().getSimpleFields());
} else if (curExtView != null) {
view.getRecord().getSimpleFields().putAll(curExtView.getRecord().getSimpleFields());
}
// compare the new external view with current one, set only on different
if (curExtView == null || !curExtView.getRecord().equals(view.getRecord())) {
// Add external view to the list which will be written to ZK later.
newExtViews.add(view);
// For SCHEDULER_TASK_RESOURCE resource group (helix task queue), we need to find out which
// task partitions are finished (COMPLETED or ERROR), update the status update of the original
// scheduler message, and then remove the partitions from the ideal state
if (idealState != null
&& idealState.getStateModelDefRef().equalsIgnoreCase(
DefaultSchedulerMessageHandlerFactory.SCHEDULER_TASK_QUEUE)) {
updateScheduledTaskStatus(view, manager, idealState);
}
}
}
// Keep MBeans for existing resources and unregister MBeans for dropped resources
if (clusterStatusMonitor != null) {
clusterStatusMonitor.retainResourceMonitor(monitoringResources);
}
List<String> externalViewsToRemove = new ArrayList<>();
// TODO: consider not setting the externalview of SCHEDULER_TASK_QUEUE at all.
// Are there any entity that will be interested in its change?
// For the resource with DisableExternalView option turned on in IdealState
// We will not actually create or write the externalView to ZooKeeper.
List<PropertyKey> keys = new ArrayList<>();
for(Iterator<ExternalView> it = newExtViews.iterator(); it.hasNext(); ) {
ExternalView view = it.next();
String resourceName = view.getResourceName();
IdealState idealState = cache.getIdealState(resourceName);
if (idealState != null && idealState.isExternalViewDisabled()) {
it.remove();
// remove the external view if the external view exists
if (curExtViews.containsKey(resourceName)) {
LogUtil
.logInfo(LOG, _eventId, "Remove externalView for resource: " + resourceName);
dataAccessor.removeProperty(keyBuilder.externalView(resourceName));
externalViewsToRemove.add(resourceName);
}
} else {
keys.add(keyBuilder.externalView(resourceName));
}
}
// add/update external-views
if (newExtViews.size() > 0) {
dataAccessor.setChildren(keys, newExtViews);
cache.updateExternalViews(newExtViews);
}
// remove dead external-views
for (String resourceName : curExtViews.keySet()) {
if (!resourceMap.keySet().contains(resourceName)) {
LogUtil.logInfo(LOG, _eventId, "Remove externalView for resource: " + resourceName);
dataAccessor.removeProperty(keyBuilder.externalView(resourceName));
externalViewsToRemove.add(resourceName);
}
}
cache.removeExternalViews(externalViewsToRemove);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Test(groups = { "unitTest" })
public void testStaticFileCM()
{
final String clusterName = "TestSTaticFileCM";
final String controllerName = "controller_0";
ClusterView view;
String[] illegalNodesInfo = {"localhost_8900", "localhost_8901"};
List<DBParam> dbParams = new ArrayList<DBParam>();
dbParams.add(new DBParam("TestDB0", 10));
dbParams.add(new DBParam("TestDB1", 10));
boolean exceptionCaught = false;
try
{
view = FileBasedClusterManager.generateStaticConfigClusterView(illegalNodesInfo, dbParams, 3);
} catch (IllegalArgumentException e)
{
exceptionCaught = true;
}
Assert.assertTrue(exceptionCaught);
String[] nodesInfo = {"localhost:8900", "localhost:8901", "localhost:8902"};
view = FileBasedClusterManager.generateStaticConfigClusterView(nodesInfo, dbParams, 2);
String configFile = "/tmp/" + clusterName;
ClusterViewSerializer.serialize(view, new File(configFile));
ClusterView restoredView = ClusterViewSerializer.deserialize(new File(configFile));
// System.out.println(restoredView);
// byte[] bytes = ClusterViewSerializer.serialize(restoredView);
// System.out.println(new String(bytes));
FileBasedClusterManager controller = new FileBasedClusterManager(clusterName, controllerName,
InstanceType.CONTROLLER, configFile);
controller.disconnect();
Assert.assertFalse(controller.isConnected());
controller.connect();
Assert.assertTrue(controller.isConnected());
String sessionId = controller.getSessionId();
Assert.assertEquals(DynamicFileClusterManager._sessionId, sessionId);
Assert.assertEquals(clusterName, controller.getClusterName());
Assert.assertEquals(0, controller.getLastNotificationTime());
Assert.assertEquals(InstanceType.CONTROLLER, controller.getInstanceType());
Assert.assertNull(controller.getPropertyStore());
Assert.assertNull(controller.getHealthReportCollector());
Assert.assertEquals(controllerName, controller.getInstanceName());
Assert.assertNull(controller.getClusterManagmentTool());
Assert.assertNull(controller.getMessagingService());
MockListener controllerListener = new MockListener();
Assert.assertFalse(controller.removeListener(controllerListener));
controllerListener.reset();
controller.addIdealStateChangeListener(controllerListener);
Assert.assertTrue(controllerListener.isIdealStateChangeListenerInvoked);
controller.addMessageListener(controllerListener, "localhost_8900");
Assert.assertTrue(controllerListener.isMessageListenerInvoked);
exceptionCaught = false;
try
{
controller.addLiveInstanceChangeListener(controllerListener);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
Assert.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
controller.addCurrentStateChangeListener(controllerListener, "localhost_8900", sessionId);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
Assert.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
controller.addConfigChangeListener(controllerListener);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
Assert.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
controller.addExternalViewChangeListener(controllerListener);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
Assert.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
controller.addControllerListener(controllerListener);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
Assert.assertTrue(exceptionCaught);
}
#location 54
#vulnerability type NULL_DEREFERENCE
|
#fixed code
@Test(groups = { "unitTest" })
public void testStaticFileCM()
{
final String clusterName = "TestSTaticFileCM";
final String controllerName = "controller_0";
ClusterView view;
String[] illegalNodesInfo = {"localhost_8900", "localhost_8901"};
List<DBParam> dbParams = new ArrayList<DBParam>();
dbParams.add(new DBParam("TestDB0", 10));
dbParams.add(new DBParam("TestDB1", 10));
boolean exceptionCaught = false;
try
{
view = FileBasedClusterManager.generateStaticConfigClusterView(illegalNodesInfo, dbParams, 3);
} catch (IllegalArgumentException e)
{
exceptionCaught = true;
}
Assert.assertTrue(exceptionCaught);
String[] nodesInfo = {"localhost:8900", "localhost:8901", "localhost:8902"};
view = FileBasedClusterManager.generateStaticConfigClusterView(nodesInfo, dbParams, 2);
String configFile = "/tmp/" + clusterName;
ClusterViewSerializer.serialize(view, new File(configFile));
ClusterView restoredView = ClusterViewSerializer.deserialize(new File(configFile));
// System.out.println(restoredView);
// byte[] bytes = ClusterViewSerializer.serialize(restoredView);
// System.out.println(new String(bytes));
FileBasedClusterManager.verifyFileBasedClusterStates("localhost_8900",
configFile, configFile);
FileBasedClusterManager controller = new FileBasedClusterManager(clusterName, controllerName,
InstanceType.CONTROLLER, configFile);
controller.disconnect();
Assert.assertFalse(controller.isConnected());
controller.connect();
Assert.assertTrue(controller.isConnected());
String sessionId = controller.getSessionId();
Assert.assertEquals(DynamicFileClusterManager._sessionId, sessionId);
Assert.assertEquals(clusterName, controller.getClusterName());
Assert.assertEquals(0, controller.getLastNotificationTime());
Assert.assertEquals(InstanceType.CONTROLLER, controller.getInstanceType());
Assert.assertNull(controller.getPropertyStore());
Assert.assertNull(controller.getHealthReportCollector());
Assert.assertEquals(controllerName, controller.getInstanceName());
Assert.assertNull(controller.getClusterManagmentTool());
Assert.assertNull(controller.getMessagingService());
MockListener controllerListener = new MockListener();
Assert.assertFalse(controller.removeListener(controllerListener));
controllerListener.reset();
controller.addIdealStateChangeListener(controllerListener);
Assert.assertTrue(controllerListener.isIdealStateChangeListenerInvoked);
controller.addMessageListener(controllerListener, "localhost_8900");
Assert.assertTrue(controllerListener.isMessageListenerInvoked);
exceptionCaught = false;
try
{
controller.addLiveInstanceChangeListener(controllerListener);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
Assert.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
controller.addCurrentStateChangeListener(controllerListener, "localhost_8900", sessionId);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
Assert.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
controller.addConfigChangeListener(controllerListener);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
Assert.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
controller.addExternalViewChangeListener(controllerListener);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
Assert.assertTrue(exceptionCaught);
exceptionCaught = false;
try
{
controller.addControllerListener(controllerListener);
} catch (UnsupportedOperationException e)
{
exceptionCaught = true;
}
Assert.assertTrue(exceptionCaught);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
@Override
public void process(ClusterEvent event) throws Exception
{
ClusterDataCache cache = event.getAttribute("ClusterDataCache");
Map<String, IdealState> idealStates = cache.getIdealStates();
Map<String, ResourceGroup> resourceGroupMap = new LinkedHashMap<String, ResourceGroup>();
if (idealStates != null && idealStates.size() > 0)
{
for (IdealState idealState : idealStates.values())
{
Set<String> resourceSet = idealState.getResourceKeySet();
String resourceGroupName = idealState.getResourceGroup();
for (String resourceKey : resourceSet)
{
addResource(resourceKey, resourceGroupName, resourceGroupMap);
ResourceGroup resourceGroup = resourceGroupMap
.get(resourceGroupName);
resourceGroup.setStateModelDefRef(idealState.getStateModelDefRef());
}
}
}
// It's important to get resourceKeys from CurrentState as well since the
// idealState might be removed.
Map<String, LiveInstance> availableInstances = cache.getLiveInstances();
if (availableInstances != null && availableInstances.size() > 0)
{
for (LiveInstance instance : availableInstances.values())
{
String instanceName = instance.getInstanceName();
String clientSessionId = instance.getSessionId();
Map<String, CurrentState> currentStateMap = cache.getCurrentState(instanceName, clientSessionId);
if (currentStateMap == null || currentStateMap.size() == 0)
{
continue;
}
for (CurrentState currentState : currentStateMap.values())
{
String resourceGroupName = currentState.getResourceGroupName();
Map<String, String> resourceStateMap = currentState.getResourceKeyStateMap();
for (String resourceKey : resourceStateMap.keySet())
{
addResource(resourceKey, resourceGroupName, resourceGroupMap);
ResourceGroup resourceGroup = resourceGroupMap
.get(resourceGroupName);
resourceGroup.setStateModelDefRef(currentState.getStateModelDefRef());
}
}
}
}
event.addAttribute(AttributeName.RESOURCE_GROUPS.toString(),
resourceGroupMap);
}
#location 5
#vulnerability type NULL_DEREFERENCE
|
#fixed code
@Override
public void process(ClusterEvent event) throws Exception
{
ClusterDataCache cache = event.getAttribute("ClusterDataCache");
if (cache == null)
{
throw new StageException("Missing attributes in event:" + event
+ ". Requires DataCache");
}
Map<String, IdealState> idealStates = cache.getIdealStates();
Map<String, ResourceGroup> resourceGroupMap =
new LinkedHashMap<String, ResourceGroup>();
if (idealStates != null && idealStates.size() > 0)
{
for (IdealState idealState : idealStates.values())
{
Set<String> resourceSet = idealState.getResourceKeySet();
String resourceGroupName = idealState.getResourceGroup();
for (String resourceKey : resourceSet)
{
addResource(resourceKey, resourceGroupName, resourceGroupMap);
ResourceGroup resourceGroup = resourceGroupMap.get(resourceGroupName);
resourceGroup.setStateModelDefRef(idealState.getStateModelDefRef());
}
}
}
// It's important to get resourceKeys from CurrentState as well since the
// idealState might be removed.
Map<String, LiveInstance> availableInstances = cache.getLiveInstances();
if (availableInstances != null && availableInstances.size() > 0)
{
for (LiveInstance instance : availableInstances.values())
{
String instanceName = instance.getInstanceName();
String clientSessionId = instance.getSessionId();
Map<String, CurrentState> currentStateMap =
cache.getCurrentState(instanceName, clientSessionId);
if (currentStateMap == null || currentStateMap.size() == 0)
{
continue;
}
for (CurrentState currentState : currentStateMap.values())
{
String resourceGroupName = currentState.getResourceGroupName();
Map<String, String> resourceStateMap = currentState.getResourceKeyStateMap();
for (String resourceKey : resourceStateMap.keySet())
{
addResource(resourceKey, resourceGroupName, resourceGroupMap);
ResourceGroup resourceGroup = resourceGroupMap.get(resourceGroupName);
resourceGroup.setStateModelDefRef(currentState.getStateModelDefRef());
}
}
}
}
event.addAttribute(AttributeName.RESOURCE_GROUPS.toString(), resourceGroupMap);
}
|
Below is the vulnerable code, please generate the patch based on the following information.
|
#vulnerable code
public void onExternalViewChange(ExternalView externalView, IdealState idealState) {
try {
String resourceName = externalView.getId();
if (!_resourceMbeanMap.containsKey(resourceName)) {
synchronized (this) {
if (!_resourceMbeanMap.containsKey(resourceName)) {
ResourceMonitor bean = new ResourceMonitor(_clusterName, resourceName);
String beanName =
CLUSTER_DN_KEY + "=" + _clusterName + "," + RESOURCE_DN_KEY + "=" + resourceName;
register(bean, getObjectName(beanName));
_resourceMbeanMap.put(resourceName, bean);
}
}
}
_resourceMbeanMap.get(resourceName).updateExternalView(externalView, idealState);
} catch (Exception e) {
LOG.warn(e);
}
}
#location 15
#vulnerability type THREAD_SAFETY_VIOLATION
|
#fixed code
public void onExternalViewChange(ExternalView externalView, IdealState idealState) {
try {
String resourceName = externalView.getId();
if (!_resourceMbeanMap.containsKey(resourceName)) {
synchronized (this) {
if (!_resourceMbeanMap.containsKey(resourceName)) {
ResourceMonitor bean = new ResourceMonitor(_clusterName, resourceName);
bean.updateExternalView(externalView, idealState);
registerResources(Arrays.asList(bean));
}
}
}
ResourceMonitor bean = _resourceMbeanMap.get(resourceName);
String oldSensorName = bean.getSensorName();
bean.updateExternalView(externalView, idealState);
String newSensorName = bean.getSensorName();
if (!oldSensorName.equals(newSensorName)) {
unregisterResources(Arrays.asList(resourceName));
registerResources(Arrays.asList(bean));
}
} catch (Exception e) {
LOG.warn(e);
}
}
|
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.