-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(java): refactoring java bugs for 3 projects
- Loading branch information
1 parent
e6bf6b5
commit cff1bdc
Showing
392 changed files
with
37,988 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
Java/commons-validator-AbstractCalendarValidatorTest_230/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM ghcr.io/kupl/starlab-benchmarks/java-base:commons-validator | ||
|
||
ENV TZ=Asia/Seoul | ||
|
||
COPY ./metadata.json . | ||
COPY ./npe.json . | ||
COPY ./buggy.java /tmp/buggy.java | ||
RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ | ||
&& export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ | ||
&& export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ | ||
&& mv /tmp/buggy.java $BUGGY_PATH \ | ||
&& echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json | ||
|
||
RUN git init . && git add -A | ||
|
||
RUN $(cat metadata.json | jq -r ".buildCommand") | ||
|
||
RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi |
272 changes: 272 additions & 0 deletions
272
Java/commons-validator-AbstractCalendarValidatorTest_230/buggy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,272 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.commons.validator.routines; | ||
|
||
import junit.framework.TestCase; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.ObjectInputStream; | ||
import java.io.ObjectOutputStream; | ||
import java.util.Date; | ||
import java.util.Calendar; | ||
import java.util.Locale; | ||
import java.util.TimeZone; | ||
|
||
/** | ||
* Base Calendar Test Case. | ||
* | ||
* @version $Revision$ | ||
*/ | ||
public abstract class AbstractCalendarValidatorTest extends TestCase { | ||
|
||
protected AbstractCalendarValidator validator; | ||
|
||
protected static final TimeZone GMT = TimeZone.getTimeZone("GMT"); // 0 offset | ||
protected static final TimeZone EST = TimeZone.getTimeZone("EST"); // - 5 hours | ||
protected static final TimeZone EET = TimeZone.getTimeZone("EET"); // + 2 hours | ||
protected static final TimeZone UTC = TimeZone.getTimeZone("UTC"); // + 2 hours | ||
|
||
protected String[] patternValid = new String[] { | ||
"2005-01-01" | ||
,"2005-12-31" | ||
,"2004-02-29" // valid leap | ||
,"2005-04-30" | ||
,"05-12-31" | ||
,"2005-1-1" | ||
,"05-1-1"}; | ||
protected String[] localeValid = new String[] { | ||
"01/01/2005" | ||
,"12/31/2005" | ||
,"02/29/2004" // valid leap | ||
,"04/30/2005" | ||
,"12/31/05" | ||
,"1/1/2005" | ||
,"1/1/05"}; | ||
protected Date[] patternExpect = new Date[] { | ||
createDate(null, 20050101, 0) | ||
,createDate(null, 20051231, 0) | ||
,createDate(null, 20040229, 0) | ||
,createDate(null, 20050430, 0) | ||
,createDate(null, 20051231, 0) | ||
,createDate(null, 20050101, 0) | ||
,createDate(null, 20050101, 0)}; | ||
protected String[] patternInvalid = new String[] { | ||
"2005-00-01" // zero month | ||
,"2005-01-00" // zero day | ||
,"2005-13-03" // month invalid | ||
,"2005-04-31" // invalid day | ||
,"2005-03-32" // invalid day | ||
,"2005-02-29" // invalid leap | ||
,"200X-01-01" // invalid char | ||
,"2005-0X-01" // invalid char | ||
,"2005-01-0X" // invalid char | ||
,"01/01/2005" // invalid pattern | ||
,"2005-01" // invalid pattern | ||
,"2005--01" // invalid pattern | ||
,"2005-01-"}; // invalid pattern | ||
protected String[] localeInvalid = new String[] { | ||
"01/00/2005" // zero month | ||
,"00/01/2005" // zero day | ||
,"13/01/2005" // month invalid | ||
,"04/31/2005" // invalid day | ||
,"03/32/2005" // invalid day | ||
,"02/29/2005" // invalid leap | ||
,"01/01/200X" // invalid char | ||
,"01/0X/2005" // invalid char | ||
,"0X/01/2005" // invalid char | ||
,"01-01-2005" // invalid pattern | ||
,"01/2005" // invalid pattern | ||
// -------- ,"/01/2005" ---- passes on some JDK | ||
,"01//2005"}; // invalid pattern | ||
|
||
/** | ||
* Constructor | ||
* @param name test name | ||
*/ | ||
public AbstractCalendarValidatorTest(String name) { | ||
super(name); | ||
} | ||
|
||
/** | ||
* Set Up. | ||
* @throws Exception | ||
*/ | ||
@Override | ||
protected void setUp() throws Exception { | ||
super.setUp(); | ||
} | ||
|
||
/** | ||
* Tear down | ||
* @throws Exception | ||
*/ | ||
@Override | ||
protected void tearDown() throws Exception { | ||
super.tearDown(); | ||
validator = null; | ||
} | ||
|
||
/** | ||
* Test Valid Dates with "pattern" validation | ||
*/ | ||
public void testPatternValid() { | ||
for (int i = 0; i < patternValid.length; i++) { | ||
String text = i + " value=[" +patternValid[i]+"] failed "; | ||
Object date = validator.parse(patternValid[i], "yy-MM-dd", null, null); | ||
assertNotNull("validateObj() " + text + date, date); | ||
assertTrue("isValid() " + text, validator.isValid(patternValid[i], "yy-MM-dd")); | ||
if (date instanceof Calendar) { | ||
date = ((Calendar)date).getTime(); | ||
} | ||
assertEquals("compare " + text, patternExpect[i], date); | ||
} | ||
} | ||
|
||
/** | ||
* Test Invalid Dates with "pattern" validation | ||
*/ | ||
public void testPatternInvalid() { | ||
for (int i = 0; i < patternInvalid.length; i++) { | ||
String text = i + " value=[" +patternInvalid[i]+"] passed "; | ||
Object date = validator.parse(patternInvalid[i], "yy-MM-dd", null, null); | ||
assertNull("validateObj() " + text + date, date); | ||
assertFalse("isValid() " + text, validator.isValid(patternInvalid[i], "yy-MM-dd")); | ||
} | ||
} | ||
|
||
/** | ||
* Test Valid Dates with "locale" validation | ||
*/ | ||
public void testLocaleValid() { | ||
for (int i = 0; i < localeValid.length; i++) { | ||
String text = i + " value=[" +localeValid[i]+"] failed "; | ||
Object date = validator.parse(localeValid[i], null, Locale.US, null); | ||
assertNotNull("validateObj() " + text + date, date); | ||
assertTrue("isValid() " + text, validator.isValid(localeValid[i], Locale.US)); | ||
if (date instanceof Calendar) { | ||
date = ((Calendar)date).getTime(); | ||
} | ||
assertEquals("compare " + text, patternExpect[i], date); | ||
} | ||
} | ||
|
||
/** | ||
* Test Invalid Dates with "locale" validation | ||
*/ | ||
public void testLocaleInvalid() { | ||
for (int i = 0; i < localeInvalid.length; i++) { | ||
String text = i + " value=[" +localeInvalid[i]+"] passed "; | ||
Object date = validator.parse(localeInvalid[i], null, Locale.US, null); | ||
assertNull("validateObj() " + text + date, date); | ||
assertFalse("isValid() " + text, validator.isValid(localeInvalid[i], Locale.US)); | ||
} | ||
} | ||
|
||
/** | ||
* Test Invalid Dates with "locale" validation | ||
*/ | ||
public void testFormat() { | ||
|
||
// Create a Date or Calendar | ||
Object test = validator.parse("2005-11-28", "yyyy-MM-dd", null, null); | ||
assertNotNull("Test Date ", test); | ||
assertEquals("Format pattern", "28.11.05", validator.format(test, "dd.MM.yy")); | ||
assertEquals("Format locale", "11/28/05", validator.format(test, Locale.US)); | ||
} | ||
|
||
/** | ||
* Test validator serialization. | ||
*/ | ||
public void testSerialization() { | ||
// Serialize the check digit routine | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
try { | ||
ObjectOutputStream oos = new ObjectOutputStream(baos); | ||
oos.writeObject(validator); | ||
oos.flush(); | ||
oos.close(); | ||
} catch (Exception e) { | ||
fail(validator.getClass().getName() + " error during serialization: " + e); | ||
} | ||
|
||
// Deserialize the test object | ||
Object result = null; | ||
try { | ||
ByteArrayInputStream bais = | ||
new ByteArrayInputStream(baos.toByteArray()); | ||
ObjectInputStream ois = new ObjectInputStream(bais); | ||
result = ois.readObject(); | ||
bais.close(); | ||
} catch (Exception e) { | ||
fail(validator.getClass().getName() + " error during deserialization: " + e); | ||
} | ||
assertNotNull(result); | ||
} | ||
|
||
/** | ||
* Create a calendar instance for a specified time zone, date and time. | ||
* | ||
* @param zone The time zone | ||
* @param date The date in yyyyMMdd format | ||
* @param time the time in HH:mm:ss format | ||
* @return the new Calendar instance. | ||
*/ | ||
/** | ||
* Create a calendar instance for a specified time zone, date and time. | ||
* | ||
* @param zone | ||
* The time zone | ||
* @param date | ||
* The date in yyyyMMdd format | ||
* @param time | ||
* the time in HH:mm:ss format | ||
* @return the new Calendar instance. | ||
*/ | ||
protected static java.util.Calendar createCalendar(java.util.TimeZone zone, int date, int time) { | ||
java.util.Calendar calendar = java.util.Calendar.getInstance(/* NPEX_NULL_EXP */ | ||
zone); | ||
int year = (date / 10000) * 10000; | ||
int mth = ((date / 100) * 100) - year; | ||
int day = date - (year + mth); | ||
int hour = (time / 10000) * 10000; | ||
int min = ((time / 100) * 100) - hour; | ||
int sec = time - (hour + min); | ||
calendar.set(java.util.Calendar.YEAR, year / 10000); | ||
calendar.set(java.util.Calendar.MONTH, (mth / 100) - 1); | ||
calendar.set(java.util.Calendar.DATE, day); | ||
calendar.set(java.util.Calendar.HOUR_OF_DAY, hour / 10000); | ||
calendar.set(java.util.Calendar.MINUTE, min / 100); | ||
calendar.set(java.util.Calendar.SECOND, sec); | ||
calendar.set(java.util.Calendar.MILLISECOND, 0); | ||
return calendar; | ||
} | ||
|
||
/** | ||
* Create a date instance for a specified time zone, date and time. | ||
* | ||
* @param zone The time zone | ||
* @param date The date in yyyyMMdd format | ||
* @param time the time in HH:mm:ss format | ||
* @return the new Date instance. | ||
*/ | ||
protected static Date createDate(TimeZone zone, int date, int time) { | ||
Calendar calendar = createCalendar(zone, date, time); | ||
return calendar.getTime(); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
Java/commons-validator-AbstractCalendarValidatorTest_230/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"language": "java", | ||
"id": "commons-validator-AbstractCalendarValidatorTest_230", | ||
"buggyPath": ".", | ||
"referencePath": null, | ||
"buildCommand": "mvn package -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100 -DskipTests=true -DskipITs=true -Dtest=None -DfailIfNoTests=false", | ||
"testCommand": "mvn test -V -B -Denforcer.skip=true -Dcheckstyle.skip=true -Dcobertura.skip=true -Drat.skip=true -Dlicense.skip=true -Dfindbugs.skip=true -Dgpg.skip=true -Dskip.npm=true -Dskip.gulp=true -Dskip.bower=true -Drat.numUnapprovedLicenses=100", | ||
"categories": [ | ||
"safety", | ||
"npe" | ||
], | ||
"npe": { | ||
"filepath": "src/test/java/org/apache/commons/validator/routines/AbstractCalendarValidatorTest.java", | ||
"line": 242, | ||
"npe_method": "createCalendar", | ||
"deref_field": "zone", | ||
"npe_class": "AbstractCalendarValidatorTest", | ||
"repo": "commons-validator", | ||
"bug_id": "AbstractCalendarValidatorTest_230" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
Java/commons-validator-AbstractCalendarValidatorTest_230/npe.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"filepath": "src/test/java/org/apache/commons/validator/routines/AbstractCalendarValidatorTest.java", | ||
"line": 242, | ||
"npe_method": "createCalendar", | ||
"deref_field": "zone", | ||
"npe_class": "AbstractCalendarValidatorTest" | ||
} |
18 changes: 18 additions & 0 deletions
18
Java/commons-validator-AbstractCalendarValidator_141/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM ghcr.io/kupl/starlab-benchmarks/java-base:commons-validator | ||
|
||
ENV TZ=Asia/Seoul | ||
|
||
COPY ./metadata.json . | ||
COPY ./npe.json . | ||
COPY ./buggy.java /tmp/buggy.java | ||
RUN export BUGGY_PATH=$(cat metadata.json | jq -r ".npe.filepath") \ | ||
&& export BUGGY_LINE=$(cat metadata.json | jq -r ".npe.line") \ | ||
&& export BUGGY_MTHD=$(cat metadata.json | jq -r ".npe.npe_method") \ | ||
&& mv /tmp/buggy.java $BUGGY_PATH \ | ||
&& echo "[{\"filepath\": \"$BUGGY_PATH\", \"line\": $BUGGY_LINE, \"method_name\": \"$BUGGY_MTHD\"}]" | jq . > traces.json | ||
|
||
RUN git init . && git add -A | ||
|
||
RUN $(cat metadata.json | jq -r ".buildCommand") | ||
|
||
RUN $(cat metadata.json | jq -r ".testCommand"); if [ $? -eq 0 ]; then exit 1; fi |
Oops, something went wrong.