Skip to content

Commit

Permalink
refactor(java): commons-lang C-classes (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
henrylee97 authored Nov 30, 2023
1 parent 699c133 commit b7103e5
Show file tree
Hide file tree
Showing 176 changed files with 31,794 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Java/commons-lang-CharEncoding_93/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM ghcr.io/kupl/starlab-benchmarks/java-base:commons-lang

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
114 changes: 114 additions & 0 deletions Java/commons-lang-CharEncoding_93/buggy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* 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.lang3;

import java.nio.charset.Charset;
import java.nio.charset.IllegalCharsetNameException;

/**
* <p>Character encoding names required of every implementation of the Java platform.</p>
*
* <p>According to <a href="http://docs.oracle.com/javase/1.3/docs/api/java/lang/package-summary.html#charenc">JRE character
* encoding names</a>:</p>
*
* <p><cite>Every implementation of the Java platform is required to support the following character encodings.
* Consult the release documentation for your implementation to see if any other encodings are supported.
* </cite></p>
*
* @see <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/intl/encoding.doc.html">JRE character encoding names</a>
* @since 2.1
*/
public class CharEncoding {

/**
* <p>ISO Latin Alphabet #1, also known as ISO-LATIN-1.</p>
*
* <p>Every implementation of the Java platform is required to support this character encoding.</p>
*/
public static final String ISO_8859_1 = "ISO-8859-1";

/**
* <p>Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block
* of the Unicode character set.</p>
*
* <p>Every implementation of the Java platform is required to support this character encoding.</p>
*/
public static final String US_ASCII = "US-ASCII";

/**
* <p>Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial
* byte-order mark (either order accepted on input, big-endian used on output).</p>
*
* <p>Every implementation of the Java platform is required to support this character encoding.</p>
*/
public static final String UTF_16 = "UTF-16";

/**
* <p>Sixteen-bit Unicode Transformation Format, big-endian byte order.</p>
*
* <p>Every implementation of the Java platform is required to support this character encoding.</p>
*/
public static final String UTF_16BE = "UTF-16BE";

/**
* <p>Sixteen-bit Unicode Transformation Format, little-endian byte order.</p>
*
* <p>Every implementation of the Java platform is required to support this character encoding.</p>
*/
public static final String UTF_16LE = "UTF-16LE";

/**
* <p>Eight-bit Unicode Transformation Format.</p>
*
* <p>Every implementation of the Java platform is required to support this character encoding.</p>
*/
public static final String UTF_8 = "UTF-8";

/**
* <p>Returns whether the named charset is supported.</p>
*
* <p>This is similar to <a
* href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html#isSupported%28java.lang.String%29">
* java.nio.charset.Charset.isSupported(String)</a> but handles more formats</p>
*
* @param name the name of the requested charset; may be either a canonical name or an alias, null returns false
* @return {@code true} if the charset is available in the current Java virtual machine
*/
/**
* <p>Returns whether the named charset is supported.</p>
*
* <p>This is similar to <a
* href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html#isSupported%28java.lang.String%29">
* java.nio.charset.Charset.isSupported(String)</a> but handles more formats</p>
*
* @param name
* the name of the requested charset; may be either a canonical name or an alias, null returns false
* @return {@code true} if the charset is available in the current Java virtual machine
*/
public static boolean isSupported(final java.lang.String name) {
{
try {
return java.nio.charset.Charset.isSupported(/* NPEX_NULL_EXP */
name);
} catch (final java.nio.charset.IllegalCharsetNameException ex) {
return false;
}
}
}

}
21 changes: 21 additions & 0 deletions Java/commons-lang-CharEncoding_93/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"language": "java",
"id": "commons-lang-CharEncoding_93",
"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/main/java/org/apache/commons/lang3/CharEncoding.java",
"line": 107,
"npe_method": "isSupported",
"deref_field": "name",
"npe_class": "CharEncoding",
"repo": "commons-lang",
"bug_id": "CharEncoding_93"
}
}
7 changes: 7 additions & 0 deletions Java/commons-lang-CharEncoding_93/npe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"filepath": "src/main/java/org/apache/commons/lang3/CharEncoding.java",
"line": 107,
"npe_method": "isSupported",
"deref_field": "name",
"npe_class": "CharEncoding"
}
18 changes: 18 additions & 0 deletions Java/commons-lang-CharSequenceTranslator_55/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM ghcr.io/kupl/starlab-benchmarks/java-base:commons-lang

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
142 changes: 142 additions & 0 deletions Java/commons-lang-CharSequenceTranslator_55/buggy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/*
* 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.lang3.text.translate;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Locale;

/**
* An API for translating text.
* Its core use is to escape and unescape text. Because escaping and unescaping
* is completely contextual, the API does not present two separate signatures.
*
* @since 3.0
*/
public abstract class CharSequenceTranslator {

static final char[] HEX_DIGITS = new char[] {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};

/**
* Translate a set of codepoints, represented by an int index into a CharSequence,
* into another set of codepoints. The number of codepoints consumed must be returned,
* and the only IOExceptions thrown must be from interacting with the Writer so that
* the top level API may reliably ignore StringWriter IOExceptions.
*
* @param input CharSequence that is being translated
* @param index int representing the current point of translation
* @param out Writer to translate the text to
* @return int count of codepoints consumed
* @throws IOException if and only if the Writer produces an IOException
*/
public abstract int translate(CharSequence input, int index, Writer out) throws IOException;

/**
* Helper for non-Writer usage.
* @param input CharSequence to be translated
* @return String output of translation
*/
/**
* Helper for non-Writer usage.
*
* @param input
* CharSequence to be translated
* @return String output of translation
*/
public final java.lang.String translate(final java.lang.CharSequence input) {
{
try {
final java.io.StringWriter writer = new java.io.StringWriter(/* NPEX_NULL_EXP */
input.length() * 2);
translate(input, writer);
return writer.toString();
} catch (final java.io.IOException ioe) {
// this should never ever happen while writing to a StringWriter
throw new java.lang.RuntimeException(ioe);
}
}
}

/**
* Translate an input onto a Writer. This is intentionally final as its algorithm is
* tightly coupled with the abstract method of this class.
*
* @param input CharSequence that is being translated
* @param out Writer to translate the text to
* @throws IOException if and only if the Writer produces an IOException
*/
public final void translate(final CharSequence input, final Writer out) throws IOException {
if (out == null) {
throw new IllegalArgumentException("The Writer must not be null");
}
if (input == null) {
return;
}
int pos = 0;
final int len = input.length();
while (pos < len) {
final int consumed = translate(input, pos, out);
if (consumed == 0) {
// inlined implementation of Character.toChars(Character.codePointAt(input, pos))
// avoids allocating temp char arrays and duplicate checks
char c1 = input.charAt(pos);
out.write(c1);
pos++;
if (Character.isHighSurrogate(c1) && pos < len) {
char c2 = input.charAt(pos);
if (Character.isLowSurrogate(c2)) {
out.write(c2);
pos++;
}
}
continue;
}
// contract with translators is that they have to understand codepoints
// and they just took care of a surrogate pair
for (int pt = 0; pt < consumed; pt++) {
pos += Character.charCount(Character.codePointAt(input, pos));
}
}
}

/**
* Helper method to create a merger of this translator with another set of
* translators. Useful in customizing the standard functionality.
*
* @param translators CharSequenceTranslator array of translators to merge with this one
* @return CharSequenceTranslator merging this translator with the others
*/
public final CharSequenceTranslator with(final CharSequenceTranslator... translators) {
final CharSequenceTranslator[] newArray = new CharSequenceTranslator[translators.length + 1];
newArray[0] = this;
System.arraycopy(translators, 0, newArray, 1, translators.length);
return new AggregateTranslator(newArray);
}

/**
* <p>Returns an upper case hexadecimal <code>String</code> for the given
* character.</p>
*
* @param codepoint The codepoint to convert.
* @return An upper case hexadecimal <code>String</code>
*/
public static String hex(final int codepoint) {
return Integer.toHexString(codepoint).toUpperCase(Locale.ENGLISH);
}

}
21 changes: 21 additions & 0 deletions Java/commons-lang-CharSequenceTranslator_55/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"language": "java",
"id": "commons-lang-CharSequenceTranslator_55",
"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/main/java/org/apache/commons/lang3/text/translate/CharSequenceTranslator.java",
"line": 65,
"npe_method": "translate",
"deref_field": "input",
"npe_class": "CharSequenceTranslator",
"repo": "commons-lang",
"bug_id": "CharSequenceTranslator_55"
}
}
7 changes: 7 additions & 0 deletions Java/commons-lang-CharSequenceTranslator_55/npe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"filepath": "src/main/java/org/apache/commons/lang3/text/translate/CharSequenceTranslator.java",
"line": 65,
"npe_method": "translate",
"deref_field": "input",
"npe_class": "CharSequenceTranslator"
}
18 changes: 18 additions & 0 deletions Java/commons-lang-CharSequenceTranslator_77/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM ghcr.io/kupl/starlab-benchmarks/java-base:commons-lang

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
Loading

0 comments on commit b7103e5

Please sign in to comment.