diff --git a/Java/commons-lang-HashCodeBuilder_358/Dockerfile b/Java/commons-lang-HashCodeBuilder_358/Dockerfile new file mode 100644 index 000000000..7b7fbe349 --- /dev/null +++ b/Java/commons-lang-HashCodeBuilder_358/Dockerfile @@ -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 diff --git a/Java/commons-lang-HashCodeBuilder_358/buggy.java b/Java/commons-lang-HashCodeBuilder_358/buggy.java new file mode 100644 index 000000000..a2886e9be --- /dev/null +++ b/Java/commons-lang-HashCodeBuilder_358/buggy.java @@ -0,0 +1,1043 @@ +/* + * 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.builder; + +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.Validate; + +/** + *
+ * Assists in implementing {@link Object#hashCode()} methods. + *
+ * + *
+ * This class enables a good hashCode
method to be built for any class. It follows the rules laid out in
+ * the book Effective Java by Joshua Bloch. Writing a
+ * good hashCode
method is actually quite difficult. This class aims to simplify the process.
+ *
+ * The following is the approach taken. When appending a data field, the current total is multiplied by the + * multiplier then a relevant value + * for that data type is added. For example, if the current hashCode is 17, and the multiplier is 37, then + * appending the integer 45 will create a hashcode of 674, namely 17 * 37 + 45. + *
+ * + *
+ * All relevant fields from the object should be included in the hashCode
method. Derived fields may be
+ * excluded. In general, any field used in the equals
method must be used in the hashCode
+ * method.
+ *
+ * To use this class write code as follows: + *
+ * + *+ * public class Person { + * String name; + * int age; + * boolean smoker; + * ... + * + * public int hashCode() { + * // you pick a hard-coded, randomly chosen, non-zero, odd number + * // ideally different for each class + * return new HashCodeBuilder(17, 37). + * append(name). + * append(age). + * append(smoker). + * toHashCode(); + * } + * } + *+ * + *
+ * If required, the superclass hashCode()
can be added using {@link #appendSuper}.
+ *
+ * Alternatively, there is a method that uses reflection to determine the fields to test. Because these fields are
+ * usually private, the method, reflectionHashCode
, uses AccessibleObject.setAccessible
+ * to change the visibility of the fields. This will fail under a security manager, unless the appropriate permissions
+ * are set up correctly. It is also slower than testing explicitly.
+ *
+ * A typical invocation for this method would look like: + *
+ * + *+ * public int hashCode() { + * return HashCodeBuilder.reflectionHashCode(this); + * } + *+ * + *
The {@link HashCodeExclude} annotation can be used to exclude fields from being
+ * used by the reflectionHashCode
methods.
+ * A registry of objects used by reflection methods to detect cyclical object references and avoid infinite loops. + *
+ * + * @since 2.3 + */ + private static final ThreadLocal+ * Returns the registry of objects being traversed by the reflection methods in the current thread. + *
+ * + * @return Set the registry of objects being traversed + * @since 2.3 + */ + static Set
+ * Returns true
if the registry contains the given object. Used by the reflection methods to avoid
+ * infinite loops.
+ *
true
if the registry contains the given object.
+ * @since 2.3
+ */
+ static boolean isRegistered(final Object value) {
+ final Set
+ * Appends the fields and values defined by the given object of the given Class
.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}. + *
+ * + *
+ * It uses AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ *
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ * Object
.
+ *
+ * Static fields will not be tested. Superclass fields will be included. + *
+ * + *+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class, + * however this is not vital. Prime numbers are preferred, especially for the multiplier. + *
+ * + * @param initialNonZeroOddNumber + * a non-zero, odd number used as the initial value. This will be the returned + * value if no fields are found to include in the hash code + * @param multiplierNonZeroOddNumber + * a non-zero, odd number used as the multiplier + * @param object + * the Object to create ahashCode
for
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, false, null);
+ }
+
+ /**
+ * + * Uses reflection to build a valid hash code from the fields of {@code object}. + *
+ * + *
+ * It uses AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ *
+ * If the TestTransients parameter is set to true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ *
+ * Static fields will not be tested. Superclass fields will be included. + *
+ * + *+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class, + * however this is not vital. Prime numbers are preferred, especially for the multiplier. + *
+ * + * @param initialNonZeroOddNumber + * a non-zero, odd number used as the initial value. This will be the returned + * value if no fields are found to include in the hash code + * @param multiplierNonZeroOddNumber + * a non-zero, odd number used as the multiplier + * @param object + * the Object to create ahashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object,
+ final boolean testTransients) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients, null);
+ }
+
+ /**
+ * + * Uses reflection to build a valid hash code from the fields of {@code object}. + *
+ * + *
+ * It uses AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ *
+ * If the TestTransients parameter is set to true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ *
+ * Static fields will not be included. Superclass fields will be included up to and including the specified + * superclass. A null superclass is treated as java.lang.Object. + *
+ * + *+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class, + * however this is not vital. Prime numbers are preferred, especially for the multiplier. + *
+ * + * @paramhashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @param reflectUpToClass
+ * the superclass to reflect up to (inclusive), may be null
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ * @since 2.0
+ */
+/**
+ * + * Uses reflection to build a valid hash code from the fields of {@code object}. + *
+ * + *
+ * It uses AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ *
+ * If the TestTransients parameter is set to true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ *
+ * Static fields will not be included. Superclass fields will be included up to and including the specified + * superclass. A null superclass is treated as java.lang.Object. + *
+ * + *+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class, + * however this is not vital. Prime numbers are preferred, especially for the multiplier. + *
+ * + * @paramhashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @param reflectUpToClass
+ * the superclass to reflect up to (inclusive), may be null
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ * @see HashCodeExclude
+ * @since 2.0
+ */
+public static + * Uses reflection to build a valid hash code from the fields of {@code object}. + *
+ * + *+ * This constructor uses two hard coded choices for the constants needed to build a hash code. + *
+ * + *
+ * It uses AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ *
+ * If the TestTransients parameter is set to true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include + * in the hash code, the result of this method will be constant. + *
+ * + * @param object + * the Object to create ahashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final boolean testTransients) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object,
+ testTransients, null);
+ }
+
+ /**
+ * + * Uses reflection to build a valid hash code from the fields of {@code object}. + *
+ * + *+ * This constructor uses two hard coded choices for the constants needed to build a hash code. + *
+ * + *
+ * It uses AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ *
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ * Object
.
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include + * in the hash code, the result of this method will be constant. + *
+ * + * @param object + * the Object to create ahashCode
for
+ * @param excludeFields
+ * Collection of String field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final Collection+ * Uses reflection to build a valid hash code from the fields of {@code object}. + *
+ * + *+ * This constructor uses two hard coded choices for the constants needed to build a hash code. + *
+ * + *
+ * It uses AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ *
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ * Object
.
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include + * in the hash code, the result of this method will be constant. + *
+ * + * @param object + * the Object to create ahashCode
for
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final String... excludeFields) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object, false,
+ null, excludeFields);
+ }
+
+ /**
+ * + * Registers the given object. Used by the reflection methods to avoid infinite loops. + *
+ * + * @param value + * The object to register. + */ + private static void register(final Object value) { + Set+ * Unregisters the given object. + *
+ * + *
+ * Used by the reflection methods to avoid infinite loops.
+ *
+ * @param value
+ * The object to unregister.
+ * @since 2.3
+ */
+ private static void unregister(final Object value) {
+ Set
+ * Uses two hard coded choices for the constants needed to build a
+ * Two randomly chosen, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital.
+ *
+ * Prime numbers are preferred, especially for the multiplier.
+ *
+ * Append a
+ * This adds
+ * This is in contrast to the standard
+ * This is in accordance with the Effective Java design.
+ *
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Adds the result of super.hashCode() to this builder.
+ *
+ * Return the computed
+ * The computed
+ * Assists in implementing {@link Object#hashCode()} methods.
+ *
+ * This class enables a good
+ * The following is the approach taken. When appending a data field, the current total is multiplied by the
+ * multiplier then a relevant value
+ * for that data type is added. For example, if the current hashCode is 17, and the multiplier is 37, then
+ * appending the integer 45 will create a hashcode of 674, namely 17 * 37 + 45.
+ *
+ * All relevant fields from the object should be included in the
+ * To use this class write code as follows:
+ *
+ * If required, the superclass
+ * Alternatively, there is a method that uses reflection to determine the fields to test. Because these fields are
+ * usually private, the method,
+ * A typical invocation for this method would look like:
+ * The {@link HashCodeExclude} annotation can be used to exclude fields from being
+ * used by the
+ * A registry of objects used by reflection methods to detect cyclical object references and avoid infinite loops.
+ *
+ * Returns the registry of objects being traversed by the reflection methods in the current thread.
+ *
+ * Returns
+ * Appends the fields and values defined by the given object of the given
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be included. Superclass fields will be included up to and including the specified
+ * superclass. A null superclass is treated as java.lang.Object.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Registers the given object. Used by the reflection methods to avoid infinite loops.
+ *
+ * Unregisters the given object.
+ *
+ * Used by the reflection methods to avoid infinite loops.
+ *
+ * @param value
+ * The object to unregister.
+ * @since 2.3
+ */
+ private static void unregister(final Object value) {
+ Set
+ * Uses two hard coded choices for the constants needed to build a
+ * Two randomly chosen, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital.
+ *
+ * Prime numbers are preferred, especially for the multiplier.
+ *
+ * Append a
+ * This adds
+ * This is in contrast to the standard
+ * This is in accordance with the Effective Java design.
+ *
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Adds the result of super.hashCode() to this builder.
+ *
+ * Return the computed
+ * The computed
+ * Assists in implementing {@link Object#hashCode()} methods.
+ *
+ * This class enables a good
+ * The following is the approach taken. When appending a data field, the current total is multiplied by the
+ * multiplier then a relevant value
+ * for that data type is added. For example, if the current hashCode is 17, and the multiplier is 37, then
+ * appending the integer 45 will create a hashcode of 674, namely 17 * 37 + 45.
+ *
+ * All relevant fields from the object should be included in the
+ * To use this class write code as follows:
+ *
+ * If required, the superclass
+ * Alternatively, there is a method that uses reflection to determine the fields to test. Because these fields are
+ * usually private, the method,
+ * A typical invocation for this method would look like:
+ * The {@link HashCodeExclude} annotation can be used to exclude fields from being
+ * used by the
+ * A registry of objects used by reflection methods to detect cyclical object references and avoid infinite loops.
+ *
+ * Returns the registry of objects being traversed by the reflection methods in the current thread.
+ *
+ * Returns
+ * Appends the fields and values defined by the given object of the given
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be included. Superclass fields will be included up to and including the specified
+ * superclass. A null superclass is treated as java.lang.Object.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Registers the given object. Used by the reflection methods to avoid infinite loops.
+ *
+ * Unregisters the given object.
+ *
+ * Used by the reflection methods to avoid infinite loops.
+ *
+ * @param value
+ * The object to unregister.
+ * @since 2.3
+ */
+ private static void unregister(final Object value) {
+ Set
+ * Uses two hard coded choices for the constants needed to build a
+ * Two randomly chosen, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital.
+ *
+ * Prime numbers are preferred, especially for the multiplier.
+ *
+ * Append a
+ * This adds
+ * This is in contrast to the standard
+ * This is in accordance with the Effective Java design.
+ *
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Adds the result of super.hashCode() to this builder.
+ *
+ * Return the computed
+ * The computed
+ * Assists in implementing {@link Object#hashCode()} methods.
+ *
+ * This class enables a good
+ * The following is the approach taken. When appending a data field, the current total is multiplied by the
+ * multiplier then a relevant value
+ * for that data type is added. For example, if the current hashCode is 17, and the multiplier is 37, then
+ * appending the integer 45 will create a hashcode of 674, namely 17 * 37 + 45.
+ *
+ * All relevant fields from the object should be included in the
+ * To use this class write code as follows:
+ *
+ * If required, the superclass
+ * Alternatively, there is a method that uses reflection to determine the fields to test. Because these fields are
+ * usually private, the method,
+ * A typical invocation for this method would look like:
+ * The {@link HashCodeExclude} annotation can be used to exclude fields from being
+ * used by the
+ * A registry of objects used by reflection methods to detect cyclical object references and avoid infinite loops.
+ *
+ * Returns the registry of objects being traversed by the reflection methods in the current thread.
+ *
+ * Returns
+ * Appends the fields and values defined by the given object of the given
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be included. Superclass fields will be included up to and including the specified
+ * superclass. A null superclass is treated as java.lang.Object.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Registers the given object. Used by the reflection methods to avoid infinite loops.
+ *
+ * Unregisters the given object.
+ *
+ * Used by the reflection methods to avoid infinite loops.
+ *
+ * @param value
+ * The object to unregister.
+ * @since 2.3
+ */
+ private static void unregister(final Object value) {
+ Set
+ * Uses two hard coded choices for the constants needed to build a
+ * Two randomly chosen, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital.
+ *
+ * Prime numbers are preferred, especially for the multiplier.
+ *
+ * Append a
+ * This adds
+ * This is in contrast to the standard
+ * This is in accordance with the Effective Java design.
+ *
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Adds the result of super.hashCode() to this builder.
+ *
+ * Return the computed
+ * The computed
+ * Assists in implementing {@link Object#hashCode()} methods.
+ *
+ * This class enables a good
+ * The following is the approach taken. When appending a data field, the current total is multiplied by the
+ * multiplier then a relevant value
+ * for that data type is added. For example, if the current hashCode is 17, and the multiplier is 37, then
+ * appending the integer 45 will create a hashcode of 674, namely 17 * 37 + 45.
+ *
+ * All relevant fields from the object should be included in the
+ * To use this class write code as follows:
+ *
+ * If required, the superclass
+ * Alternatively, there is a method that uses reflection to determine the fields to test. Because these fields are
+ * usually private, the method,
+ * A typical invocation for this method would look like:
+ * The {@link HashCodeExclude} annotation can be used to exclude fields from being
+ * used by the
+ * A registry of objects used by reflection methods to detect cyclical object references and avoid infinite loops.
+ *
+ * Returns the registry of objects being traversed by the reflection methods in the current thread.
+ *
+ * Returns
+ * Appends the fields and values defined by the given object of the given
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be included. Superclass fields will be included up to and including the specified
+ * superclass. A null superclass is treated as java.lang.Object.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Registers the given object. Used by the reflection methods to avoid infinite loops.
+ *
+ * Unregisters the given object.
+ *
+ * Used by the reflection methods to avoid infinite loops.
+ *
+ * @param value
+ * The object to unregister.
+ * @since 2.3
+ */
+ private static void unregister(final Object value) {
+ Set
+ * Uses two hard coded choices for the constants needed to build a
+ * Two randomly chosen, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital.
+ *
+ * Prime numbers are preferred, especially for the multiplier.
+ *
+ * Append a
+ * This adds
+ * This is in contrast to the standard
+ * This is in accordance with the Effective Java design.
+ *
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Adds the result of super.hashCode() to this builder.
+ *
+ * Return the computed
+ * The computed
+ * Assists in implementing {@link Object#hashCode()} methods.
+ *
+ * This class enables a good
+ * The following is the approach taken. When appending a data field, the current total is multiplied by the
+ * multiplier then a relevant value
+ * for that data type is added. For example, if the current hashCode is 17, and the multiplier is 37, then
+ * appending the integer 45 will create a hashcode of 674, namely 17 * 37 + 45.
+ *
+ * All relevant fields from the object should be included in the
+ * To use this class write code as follows:
+ *
+ * If required, the superclass
+ * Alternatively, there is a method that uses reflection to determine the fields to test. Because these fields are
+ * usually private, the method,
+ * A typical invocation for this method would look like:
+ * The {@link HashCodeExclude} annotation can be used to exclude fields from being
+ * used by the
+ * A registry of objects used by reflection methods to detect cyclical object references and avoid infinite loops.
+ *
+ * Returns the registry of objects being traversed by the reflection methods in the current thread.
+ *
+ * Returns
+ * Appends the fields and values defined by the given object of the given
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be included. Superclass fields will be included up to and including the specified
+ * superclass. A null superclass is treated as java.lang.Object.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Registers the given object. Used by the reflection methods to avoid infinite loops.
+ *
+ * Unregisters the given object.
+ *
+ * Used by the reflection methods to avoid infinite loops.
+ *
+ * @param value
+ * The object to unregister.
+ * @since 2.3
+ */
+ private static void unregister(final Object value) {
+ Set
+ * Uses two hard coded choices for the constants needed to build a
+ * Two randomly chosen, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital.
+ *
+ * Prime numbers are preferred, especially for the multiplier.
+ *
+ * Append a
+ * This adds
+ * This is in contrast to the standard
+ * This is in accordance with the Effective Java design.
+ *
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Adds the result of super.hashCode() to this builder.
+ *
+ * Return the computed
+ * The computed
+ * Assists in implementing {@link Object#hashCode()} methods.
+ *
+ * This class enables a good
+ * The following is the approach taken. When appending a data field, the current total is multiplied by the
+ * multiplier then a relevant value
+ * for that data type is added. For example, if the current hashCode is 17, and the multiplier is 37, then
+ * appending the integer 45 will create a hashcode of 674, namely 17 * 37 + 45.
+ *
+ * All relevant fields from the object should be included in the
+ * To use this class write code as follows:
+ *
+ * If required, the superclass
+ * Alternatively, there is a method that uses reflection to determine the fields to test. Because these fields are
+ * usually private, the method,
+ * A typical invocation for this method would look like:
+ * The {@link HashCodeExclude} annotation can be used to exclude fields from being
+ * used by the
+ * A registry of objects used by reflection methods to detect cyclical object references and avoid infinite loops.
+ *
+ * Returns the registry of objects being traversed by the reflection methods in the current thread.
+ *
+ * Returns
+ * Appends the fields and values defined by the given object of the given
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be included. Superclass fields will be included up to and including the specified
+ * superclass. A null superclass is treated as java.lang.Object.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Registers the given object. Used by the reflection methods to avoid infinite loops.
+ *
+ * Unregisters the given object.
+ *
+ * Used by the reflection methods to avoid infinite loops.
+ *
+ * @param value
+ * The object to unregister.
+ * @since 2.3
+ */
+ private static void unregister(final Object value) {
+ Set
+ * Uses two hard coded choices for the constants needed to build a
+ * Two randomly chosen, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital.
+ *
+ * Prime numbers are preferred, especially for the multiplier.
+ *
+ * Append a
+ * This adds
+ * This is in contrast to the standard
+ * This is in accordance with the Effective Java design.
+ *
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Adds the result of super.hashCode() to this builder.
+ *
+ * Return the computed
+ * The computed
+ * Assists in implementing {@link Object#hashCode()} methods.
+ *
+ * This class enables a good
+ * The following is the approach taken. When appending a data field, the current total is multiplied by the
+ * multiplier then a relevant value
+ * for that data type is added. For example, if the current hashCode is 17, and the multiplier is 37, then
+ * appending the integer 45 will create a hashcode of 674, namely 17 * 37 + 45.
+ *
+ * All relevant fields from the object should be included in the
+ * To use this class write code as follows:
+ *
+ * If required, the superclass
+ * Alternatively, there is a method that uses reflection to determine the fields to test. Because these fields are
+ * usually private, the method,
+ * A typical invocation for this method would look like:
+ * The {@link HashCodeExclude} annotation can be used to exclude fields from being
+ * used by the
+ * A registry of objects used by reflection methods to detect cyclical object references and avoid infinite loops.
+ *
+ * Returns the registry of objects being traversed by the reflection methods in the current thread.
+ *
+ * Returns
+ * Appends the fields and values defined by the given object of the given
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be included. Superclass fields will be included up to and including the specified
+ * superclass. A null superclass is treated as java.lang.Object.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Registers the given object. Used by the reflection methods to avoid infinite loops.
+ *
+ * Unregisters the given object.
+ *
+ * Used by the reflection methods to avoid infinite loops.
+ *
+ * @param value
+ * The object to unregister.
+ * @since 2.3
+ */
+ private static void unregister(final Object value) {
+ Set
+ * Uses two hard coded choices for the constants needed to build a
+ * Two randomly chosen, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital.
+ *
+ * Prime numbers are preferred, especially for the multiplier.
+ *
+ * Append a
+ * This adds
+ * This is in contrast to the standard
+ * This is in accordance with the Effective Java design.
+ *
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Adds the result of super.hashCode() to this builder.
+ *
+ * Return the computed
+ * The computed
+ * Assists in implementing {@link Object#hashCode()} methods.
+ *
+ * This class enables a good
+ * The following is the approach taken. When appending a data field, the current total is multiplied by the
+ * multiplier then a relevant value
+ * for that data type is added. For example, if the current hashCode is 17, and the multiplier is 37, then
+ * appending the integer 45 will create a hashcode of 674, namely 17 * 37 + 45.
+ *
+ * All relevant fields from the object should be included in the
+ * To use this class write code as follows:
+ *
+ * If required, the superclass
+ * Alternatively, there is a method that uses reflection to determine the fields to test. Because these fields are
+ * usually private, the method,
+ * A typical invocation for this method would look like:
+ * The {@link HashCodeExclude} annotation can be used to exclude fields from being
+ * used by the
+ * A registry of objects used by reflection methods to detect cyclical object references and avoid infinite loops.
+ *
+ * Returns the registry of objects being traversed by the reflection methods in the current thread.
+ *
+ * Returns
+ * Appends the fields and values defined by the given object of the given
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be included. Superclass fields will be included up to and including the specified
+ * superclass. A null superclass is treated as java.lang.Object.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Registers the given object. Used by the reflection methods to avoid infinite loops.
+ *
+ * Unregisters the given object.
+ *
+ * Used by the reflection methods to avoid infinite loops.
+ *
+ * @param value
+ * The object to unregister.
+ * @since 2.3
+ */
+ private static void unregister(final Object value) {
+ Set
+ * Uses two hard coded choices for the constants needed to build a
+ * Two randomly chosen, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital.
+ *
+ * Prime numbers are preferred, especially for the multiplier.
+ *
+ * Append a
+ * This adds
+ * This is in contrast to the standard
+ * This is in accordance with the Effective Java design.
+ *
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Adds the result of super.hashCode() to this builder.
+ *
+ * Return the computed
+ * The computed
+ * Assists in implementing {@link Object#hashCode()} methods.
+ *
+ * This class enables a good
+ * The following is the approach taken. When appending a data field, the current total is multiplied by the
+ * multiplier then a relevant value
+ * for that data type is added. For example, if the current hashCode is 17, and the multiplier is 37, then
+ * appending the integer 45 will create a hashcode of 674, namely 17 * 37 + 45.
+ *
+ * All relevant fields from the object should be included in the
+ * To use this class write code as follows:
+ *
+ * If required, the superclass
+ * Alternatively, there is a method that uses reflection to determine the fields to test. Because these fields are
+ * usually private, the method,
+ * A typical invocation for this method would look like:
+ * The {@link HashCodeExclude} annotation can be used to exclude fields from being
+ * used by the
+ * A registry of objects used by reflection methods to detect cyclical object references and avoid infinite loops.
+ *
+ * Returns the registry of objects being traversed by the reflection methods in the current thread.
+ *
+ * Returns
+ * Appends the fields and values defined by the given object of the given
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be included. Superclass fields will be included up to and including the specified
+ * superclass. A null superclass is treated as java.lang.Object.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Registers the given object. Used by the reflection methods to avoid infinite loops.
+ *
+ * Unregisters the given object.
+ *
+ * Used by the reflection methods to avoid infinite loops.
+ *
+ * @param value
+ * The object to unregister.
+ * @since 2.3
+ */
+ private static void unregister(final Object value) {
+ Set
+ * Uses two hard coded choices for the constants needed to build a
+ * Two randomly chosen, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital.
+ *
+ * Prime numbers are preferred, especially for the multiplier.
+ *
+ * Append a
+ * This adds
+ * This is in contrast to the standard
+ * This is in accordance with the Effective Java design.
+ *
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Adds the result of super.hashCode() to this builder.
+ *
+ * Return the computed
+ * The computed
+ * Assists in implementing {@link Object#hashCode()} methods.
+ *
+ * This class enables a good
+ * The following is the approach taken. When appending a data field, the current total is multiplied by the
+ * multiplier then a relevant value
+ * for that data type is added. For example, if the current hashCode is 17, and the multiplier is 37, then
+ * appending the integer 45 will create a hashcode of 674, namely 17 * 37 + 45.
+ *
+ * All relevant fields from the object should be included in the
+ * To use this class write code as follows:
+ *
+ * If required, the superclass
+ * Alternatively, there is a method that uses reflection to determine the fields to test. Because these fields are
+ * usually private, the method,
+ * A typical invocation for this method would look like:
+ * The {@link HashCodeExclude} annotation can be used to exclude fields from being
+ * used by the
+ * A registry of objects used by reflection methods to detect cyclical object references and avoid infinite loops.
+ *
+ * Returns the registry of objects being traversed by the reflection methods in the current thread.
+ *
+ * Returns
+ * Appends the fields and values defined by the given object of the given
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be included. Superclass fields will be included up to and including the specified
+ * superclass. A null superclass is treated as java.lang.Object.
+ *
+ * Two randomly chosen, non-zero, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital. Prime numbers are preferred, especially for the multiplier.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * If the TestTransients parameter is set to
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Uses reflection to build a valid hash code from the fields of {@code object}.
+ *
+ * This constructor uses two hard coded choices for the constants needed to build a hash code.
+ *
+ * It uses
+ * Transient members will be not be used, as they are likely derived fields, and not part of the value of the
+ *
+ * Static fields will not be tested. Superclass fields will be included. If no fields are found to include
+ * in the hash code, the result of this method will be constant.
+ *
+ * Registers the given object. Used by the reflection methods to avoid infinite loops.
+ *
+ * Unregisters the given object.
+ *
+ * Used by the reflection methods to avoid infinite loops.
+ *
+ * @param value
+ * The object to unregister.
+ * @since 2.3
+ */
+ private static void unregister(final Object value) {
+ Set
+ * Uses two hard coded choices for the constants needed to build a
+ * Two randomly chosen, odd numbers must be passed in. Ideally these should be different for each class,
+ * however this is not vital.
+ *
+ * Prime numbers are preferred, especially for the multiplier.
+ *
+ * Append a
+ * This adds
+ * This is in contrast to the standard
+ * This is in accordance with the Effective Java design.
+ *
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Append a
+ * Adds the result of super.hashCode() to this builder.
+ *
+ * Return the computed
+ * The computed hashCode
.
+ * hashCode
for a boolean
.
+ * 1
when true, and 0
when false to the hashCode
.
+ * java.lang.Boolean.hashCode
handling, which computes
+ * a hashCode
value of 1231
for java.lang.Boolean
instances
+ * that represent true
or 1237
for java.lang.Boolean
instances
+ * that represent false
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean value) {
+ iTotal = iTotal * iConstant + (value ? 0 : 1);
+ return this;
+ }
+
+ /**
+ * hashCode
for a boolean
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final boolean element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final byte element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final char element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a double
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double value) {
+ return append(Double.doubleToLongBits(value));
+ }
+
+ /**
+ * hashCode
for a double
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final double element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float value) {
+ iTotal = iTotal * iConstant + Float.floatToIntBits(value);
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final float element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final int element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
.
+ * hashCode
+ * @return this
+ */
+ // NOTE: This method uses >> and not >>> as Effective Java and
+ // Long.hashCode do. Ideally we should switch to >>> at
+ // some stage. There are backwards compat issues, so
+ // that will have to wait for the time being. cf LANG-342.
+ public HashCodeBuilder append(final long value) {
+ iTotal = iTotal * iConstant + ((int) (value ^ (value >> 32)));
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final long[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final long element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an Object
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object object) {
+ if (object == null) {
+ iTotal = iTotal * iConstant;
+
+ } else {
+ if (object.getClass().isArray()) {
+ // factor out array case in order to keep method small enough
+ // to be inlined
+ appendArray(object);
+ } else {
+ iTotal = iTotal * iConstant + object.hashCode();
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an array.
+ * hashCode
+ */
+ private void appendArray(final Object object) {
+ // 'Switch' on type of array, to dispatch to the correct handler
+ // This handles multi dimensional arrays
+ if (object instanceof long[]) {
+ append((long[]) object);
+ } else if (object instanceof int[]) {
+ append((int[]) object);
+ } else if (object instanceof short[]) {
+ append((short[]) object);
+ } else if (object instanceof char[]) {
+ append((char[]) object);
+ } else if (object instanceof byte[]) {
+ append((byte[]) object);
+ } else if (object instanceof double[]) {
+ append((double[]) object);
+ } else if (object instanceof float[]) {
+ append((float[]) object);
+ } else if (object instanceof boolean[]) {
+ append((boolean[]) object);
+ } else {
+ // Not an array of primitives
+ append((Object[]) object);
+ }
+ }
+
+ /**
+ * hashCode
for an Object
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final Object element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final short element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * super.hashCode()
+ * @return this HashCodeBuilder, used to chain calls.
+ * @since 2.0
+ */
+ public HashCodeBuilder appendSuper(final int superHashCode) {
+ iTotal = iTotal * iConstant + superHashCode;
+ return this;
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
based on the fields appended
+ */
+ public int toHashCode() {
+ return iTotal;
+ }
+
+ /**
+ * Returns the computed hashCode
.
+ *
+ * @return hashCode
based on the fields appended
+ *
+ * @since 3.0
+ */
+ @Override
+ public Integer build() {
+ return Integer.valueOf(toHashCode());
+ }
+
+ /**
+ * hashCode
from toHashCode() is returned due to the likelihood
+ * of bugs in mis-calling toHashCode() and the unlikeliness of it mattering what the hashCode for
+ * HashCodeBuilder itself is.hashCode
based on the fields appended
+ * @since 2.5
+ */
+ @Override
+ public int hashCode() {
+ return toHashCode();
+ }
+
+}
diff --git a/Java/commons-lang-HashCodeBuilder_358/metadata.json b/Java/commons-lang-HashCodeBuilder_358/metadata.json
new file mode 100644
index 000000000..62ba79ebc
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_358/metadata.json
@@ -0,0 +1,21 @@
+{
+ "language": "java",
+ "id": "commons-lang-HashCodeBuilder_358",
+ "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/builder/HashCodeBuilder.java",
+ "line": 408,
+ "npe_method": "reflectionHashCode",
+ "deref_field": "object",
+ "npe_class": "HashCodeBuilder",
+ "repo": "commons-lang",
+ "bug_id": "HashCodeBuilder_358"
+ }
+}
diff --git a/Java/commons-lang-HashCodeBuilder_358/npe.json b/Java/commons-lang-HashCodeBuilder_358/npe.json
new file mode 100644
index 000000000..3448b8f0d
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_358/npe.json
@@ -0,0 +1,7 @@
+{
+ "filepath": "src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java",
+ "line": 408,
+ "npe_method": "reflectionHashCode",
+ "deref_field": "object",
+ "npe_class": "HashCodeBuilder"
+}
\ No newline at end of file
diff --git a/Java/commons-lang-HashCodeBuilder_611/Dockerfile b/Java/commons-lang-HashCodeBuilder_611/Dockerfile
new file mode 100644
index 000000000..7b7fbe349
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_611/Dockerfile
@@ -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
diff --git a/Java/commons-lang-HashCodeBuilder_611/buggy.java b/Java/commons-lang-HashCodeBuilder_611/buggy.java
new file mode 100644
index 000000000..fde6fe7ea
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_611/buggy.java
@@ -0,0 +1,1004 @@
+/*
+ * 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.builder;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * hashCode
method to be built for any class. It follows the rules laid out in
+ * the book Effective Java by Joshua Bloch. Writing a
+ * good hashCode
method is actually quite difficult. This class aims to simplify the process.
+ * hashCode
method. Derived fields may be
+ * excluded. In general, any field used in the equals
method must be used in the hashCode
+ * method.
+ *
+ * public class Person {
+ * String name;
+ * int age;
+ * boolean smoker;
+ * ...
+ *
+ * public int hashCode() {
+ * // you pick a hard-coded, randomly chosen, non-zero, odd number
+ * // ideally different for each class
+ * return new HashCodeBuilder(17, 37).
+ * append(name).
+ * append(age).
+ * append(smoker).
+ * toHashCode();
+ * }
+ * }
+ *
+ *
+ * hashCode()
can be added using {@link #appendSuper}.
+ * reflectionHashCode
, uses AccessibleObject.setAccessible
+ * to change the visibility of the fields. This will fail under a security manager, unless the appropriate permissions
+ * are set up correctly. It is also slower than testing explicitly.
+ *
+ * public int hashCode() {
+ * return HashCodeBuilder.reflectionHashCode(this);
+ * }
+ *
+ *
+ * reflectionHashCode
methods.true
if the registry contains the given object. Used by the reflection methods to avoid
+ * infinite loops.
+ * true
if the registry contains the given object.
+ * @since 2.3
+ */
+ static boolean isRegistered(final Object value) {
+ final SetClass
.
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, false, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object,
+ final boolean testTransients) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @param reflectUpToClass
+ * the superclass to reflect up to (inclusive), may be null
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ * @since 2.0
+ */
+ public static AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final boolean testTransients) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object,
+ testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * Collection of String field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final CollectionAccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final String... excludeFields) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object, false,
+ null, excludeFields);
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
for a boolean
.
+ * 1
when true, and 0
when false to the hashCode
.
+ * java.lang.Boolean.hashCode
handling, which computes
+ * a hashCode
value of 1231
for java.lang.Boolean
instances
+ * that represent true
or 1237
for java.lang.Boolean
instances
+ * that represent false
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean value) {
+ iTotal = iTotal * iConstant + (value ? 0 : 1);
+ return this;
+ }
+
+ /**
+ * hashCode
for a boolean
array.
+ * hashCode
+ * @return this
+ */
+/**
+ * hashCode
for a boolean
array.
+ * hashCode
+ * @return this
+ */
+public org.apache.commons.lang3.builder.HashCodeBuilder append(final boolean[] array) {
+ {
+ for (final boolean element : /* NPEX_NULL_EXP */
+ array) {
+ append(element);
+ }
+ }
+ return this;
+}
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final byte element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final char element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a double
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double value) {
+ return append(Double.doubleToLongBits(value));
+ }
+
+ /**
+ * hashCode
for a double
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final double element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float value) {
+ iTotal = iTotal * iConstant + Float.floatToIntBits(value);
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final float element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final int element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
.
+ * hashCode
+ * @return this
+ */
+ // NOTE: This method uses >> and not >>> as Effective Java and
+ // Long.hashCode do. Ideally we should switch to >>> at
+ // some stage. There are backwards compat issues, so
+ // that will have to wait for the time being. cf LANG-342.
+ public HashCodeBuilder append(final long value) {
+ iTotal = iTotal * iConstant + ((int) (value ^ (value >> 32)));
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final long[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final long element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an Object
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object object) {
+ if (object == null) {
+ iTotal = iTotal * iConstant;
+
+ } else {
+ if (object.getClass().isArray()) {
+ // factor out array case in order to keep method small enough
+ // to be inlined
+ appendArray(object);
+ } else {
+ iTotal = iTotal * iConstant + object.hashCode();
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an array.
+ * hashCode
+ */
+ private void appendArray(final Object object) {
+ // 'Switch' on type of array, to dispatch to the correct handler
+ // This handles multi dimensional arrays
+ if (object instanceof long[]) {
+ append((long[]) object);
+ } else if (object instanceof int[]) {
+ append((int[]) object);
+ } else if (object instanceof short[]) {
+ append((short[]) object);
+ } else if (object instanceof char[]) {
+ append((char[]) object);
+ } else if (object instanceof byte[]) {
+ append((byte[]) object);
+ } else if (object instanceof double[]) {
+ append((double[]) object);
+ } else if (object instanceof float[]) {
+ append((float[]) object);
+ } else if (object instanceof boolean[]) {
+ append((boolean[]) object);
+ } else {
+ // Not an array of primitives
+ append((Object[]) object);
+ }
+ }
+
+ /**
+ * hashCode
for an Object
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final Object element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final short element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * super.hashCode()
+ * @return this HashCodeBuilder, used to chain calls.
+ * @since 2.0
+ */
+ public HashCodeBuilder appendSuper(final int superHashCode) {
+ iTotal = iTotal * iConstant + superHashCode;
+ return this;
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
based on the fields appended
+ */
+ public int toHashCode() {
+ return iTotal;
+ }
+
+ /**
+ * Returns the computed hashCode
.
+ *
+ * @return hashCode
based on the fields appended
+ *
+ * @since 3.0
+ */
+ @Override
+ public Integer build() {
+ return Integer.valueOf(toHashCode());
+ }
+
+ /**
+ * hashCode
from toHashCode() is returned due to the likelihood
+ * of bugs in mis-calling toHashCode() and the unlikeliness of it mattering what the hashCode for
+ * HashCodeBuilder itself is.hashCode
based on the fields appended
+ * @since 2.5
+ */
+ @Override
+ public int hashCode() {
+ return toHashCode();
+ }
+
+}
diff --git a/Java/commons-lang-HashCodeBuilder_611/metadata.json b/Java/commons-lang-HashCodeBuilder_611/metadata.json
new file mode 100644
index 000000000..6cebd9fdb
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_611/metadata.json
@@ -0,0 +1,21 @@
+{
+ "language": "java",
+ "id": "commons-lang-HashCodeBuilder_611",
+ "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/builder/HashCodeBuilder.java",
+ "line": 622,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder",
+ "repo": "commons-lang",
+ "bug_id": "HashCodeBuilder_611"
+ }
+}
diff --git a/Java/commons-lang-HashCodeBuilder_611/npe.json b/Java/commons-lang-HashCodeBuilder_611/npe.json
new file mode 100644
index 000000000..faf3f1575
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_611/npe.json
@@ -0,0 +1,7 @@
+{
+ "filepath": "src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java",
+ "line": 622,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder"
+}
\ No newline at end of file
diff --git a/Java/commons-lang-HashCodeBuilder_649/Dockerfile b/Java/commons-lang-HashCodeBuilder_649/Dockerfile
new file mode 100644
index 000000000..7b7fbe349
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_649/Dockerfile
@@ -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
diff --git a/Java/commons-lang-HashCodeBuilder_649/buggy.java b/Java/commons-lang-HashCodeBuilder_649/buggy.java
new file mode 100644
index 000000000..0fba08245
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_649/buggy.java
@@ -0,0 +1,1005 @@
+/*
+ * 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.builder;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * hashCode
method to be built for any class. It follows the rules laid out in
+ * the book Effective Java by Joshua Bloch. Writing a
+ * good hashCode
method is actually quite difficult. This class aims to simplify the process.
+ * hashCode
method. Derived fields may be
+ * excluded. In general, any field used in the equals
method must be used in the hashCode
+ * method.
+ *
+ * public class Person {
+ * String name;
+ * int age;
+ * boolean smoker;
+ * ...
+ *
+ * public int hashCode() {
+ * // you pick a hard-coded, randomly chosen, non-zero, odd number
+ * // ideally different for each class
+ * return new HashCodeBuilder(17, 37).
+ * append(name).
+ * append(age).
+ * append(smoker).
+ * toHashCode();
+ * }
+ * }
+ *
+ *
+ * hashCode()
can be added using {@link #appendSuper}.
+ * reflectionHashCode
, uses AccessibleObject.setAccessible
+ * to change the visibility of the fields. This will fail under a security manager, unless the appropriate permissions
+ * are set up correctly. It is also slower than testing explicitly.
+ *
+ * public int hashCode() {
+ * return HashCodeBuilder.reflectionHashCode(this);
+ * }
+ *
+ *
+ * reflectionHashCode
methods.true
if the registry contains the given object. Used by the reflection methods to avoid
+ * infinite loops.
+ * true
if the registry contains the given object.
+ * @since 2.3
+ */
+ static boolean isRegistered(final Object value) {
+ final SetClass
.
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, false, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object,
+ final boolean testTransients) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @param reflectUpToClass
+ * the superclass to reflect up to (inclusive), may be null
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ * @since 2.0
+ */
+ public static AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final boolean testTransients) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object,
+ testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * Collection of String field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final CollectionAccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final String... excludeFields) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object, false,
+ null, excludeFields);
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
for a boolean
.
+ * 1
when true, and 0
when false to the hashCode
.
+ * java.lang.Boolean.hashCode
handling, which computes
+ * a hashCode
value of 1231
for java.lang.Boolean
instances
+ * that represent true
or 1237
for java.lang.Boolean
instances
+ * that represent false
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean value) {
+ iTotal = iTotal * iConstant + (value ? 0 : 1);
+ return this;
+ }
+
+ /**
+ * hashCode
for a boolean
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final boolean element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
array.
+ * hashCode
+ * @return this
+ */
+// -------------------------------------------------------------------------
+/**
+ * hashCode
for a byte
array.
+ * hashCode
+ * @return this
+ */
+public org.apache.commons.lang3.builder.HashCodeBuilder append(final byte[] array) {
+ {
+ for (final byte element : /* NPEX_NULL_EXP */
+ array) {
+ append(element);
+ }
+ }
+ return this;
+}
+
+ /**
+ * hashCode
for a char
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final char element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a double
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double value) {
+ return append(Double.doubleToLongBits(value));
+ }
+
+ /**
+ * hashCode
for a double
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final double element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float value) {
+ iTotal = iTotal * iConstant + Float.floatToIntBits(value);
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final float element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final int element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
.
+ * hashCode
+ * @return this
+ */
+ // NOTE: This method uses >> and not >>> as Effective Java and
+ // Long.hashCode do. Ideally we should switch to >>> at
+ // some stage. There are backwards compat issues, so
+ // that will have to wait for the time being. cf LANG-342.
+ public HashCodeBuilder append(final long value) {
+ iTotal = iTotal * iConstant + ((int) (value ^ (value >> 32)));
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final long[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final long element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an Object
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object object) {
+ if (object == null) {
+ iTotal = iTotal * iConstant;
+
+ } else {
+ if (object.getClass().isArray()) {
+ // factor out array case in order to keep method small enough
+ // to be inlined
+ appendArray(object);
+ } else {
+ iTotal = iTotal * iConstant + object.hashCode();
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an array.
+ * hashCode
+ */
+ private void appendArray(final Object object) {
+ // 'Switch' on type of array, to dispatch to the correct handler
+ // This handles multi dimensional arrays
+ if (object instanceof long[]) {
+ append((long[]) object);
+ } else if (object instanceof int[]) {
+ append((int[]) object);
+ } else if (object instanceof short[]) {
+ append((short[]) object);
+ } else if (object instanceof char[]) {
+ append((char[]) object);
+ } else if (object instanceof byte[]) {
+ append((byte[]) object);
+ } else if (object instanceof double[]) {
+ append((double[]) object);
+ } else if (object instanceof float[]) {
+ append((float[]) object);
+ } else if (object instanceof boolean[]) {
+ append((boolean[]) object);
+ } else {
+ // Not an array of primitives
+ append((Object[]) object);
+ }
+ }
+
+ /**
+ * hashCode
for an Object
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final Object element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final short element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * super.hashCode()
+ * @return this HashCodeBuilder, used to chain calls.
+ * @since 2.0
+ */
+ public HashCodeBuilder appendSuper(final int superHashCode) {
+ iTotal = iTotal * iConstant + superHashCode;
+ return this;
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
based on the fields appended
+ */
+ public int toHashCode() {
+ return iTotal;
+ }
+
+ /**
+ * Returns the computed hashCode
.
+ *
+ * @return hashCode
based on the fields appended
+ *
+ * @since 3.0
+ */
+ @Override
+ public Integer build() {
+ return Integer.valueOf(toHashCode());
+ }
+
+ /**
+ * hashCode
from toHashCode() is returned due to the likelihood
+ * of bugs in mis-calling toHashCode() and the unlikeliness of it mattering what the hashCode for
+ * HashCodeBuilder itself is.hashCode
based on the fields appended
+ * @since 2.5
+ */
+ @Override
+ public int hashCode() {
+ return toHashCode();
+ }
+
+}
diff --git a/Java/commons-lang-HashCodeBuilder_649/metadata.json b/Java/commons-lang-HashCodeBuilder_649/metadata.json
new file mode 100644
index 000000000..d61efdfa1
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_649/metadata.json
@@ -0,0 +1,21 @@
+{
+ "language": "java",
+ "id": "commons-lang-HashCodeBuilder_649",
+ "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/builder/HashCodeBuilder.java",
+ "line": 661,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder",
+ "repo": "commons-lang",
+ "bug_id": "HashCodeBuilder_649"
+ }
+}
diff --git a/Java/commons-lang-HashCodeBuilder_649/npe.json b/Java/commons-lang-HashCodeBuilder_649/npe.json
new file mode 100644
index 000000000..4ce6a496e
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_649/npe.json
@@ -0,0 +1,7 @@
+{
+ "filepath": "src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java",
+ "line": 661,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder"
+}
\ No newline at end of file
diff --git a/Java/commons-lang-HashCodeBuilder_683/Dockerfile b/Java/commons-lang-HashCodeBuilder_683/Dockerfile
new file mode 100644
index 000000000..7b7fbe349
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_683/Dockerfile
@@ -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
diff --git a/Java/commons-lang-HashCodeBuilder_683/buggy.java b/Java/commons-lang-HashCodeBuilder_683/buggy.java
new file mode 100644
index 000000000..95e37ea02
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_683/buggy.java
@@ -0,0 +1,1004 @@
+/*
+ * 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.builder;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * hashCode
method to be built for any class. It follows the rules laid out in
+ * the book Effective Java by Joshua Bloch. Writing a
+ * good hashCode
method is actually quite difficult. This class aims to simplify the process.
+ * hashCode
method. Derived fields may be
+ * excluded. In general, any field used in the equals
method must be used in the hashCode
+ * method.
+ *
+ * public class Person {
+ * String name;
+ * int age;
+ * boolean smoker;
+ * ...
+ *
+ * public int hashCode() {
+ * // you pick a hard-coded, randomly chosen, non-zero, odd number
+ * // ideally different for each class
+ * return new HashCodeBuilder(17, 37).
+ * append(name).
+ * append(age).
+ * append(smoker).
+ * toHashCode();
+ * }
+ * }
+ *
+ *
+ * hashCode()
can be added using {@link #appendSuper}.
+ * reflectionHashCode
, uses AccessibleObject.setAccessible
+ * to change the visibility of the fields. This will fail under a security manager, unless the appropriate permissions
+ * are set up correctly. It is also slower than testing explicitly.
+ *
+ * public int hashCode() {
+ * return HashCodeBuilder.reflectionHashCode(this);
+ * }
+ *
+ *
+ * reflectionHashCode
methods.true
if the registry contains the given object. Used by the reflection methods to avoid
+ * infinite loops.
+ * true
if the registry contains the given object.
+ * @since 2.3
+ */
+ static boolean isRegistered(final Object value) {
+ final SetClass
.
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, false, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object,
+ final boolean testTransients) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @param reflectUpToClass
+ * the superclass to reflect up to (inclusive), may be null
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ * @since 2.0
+ */
+ public static AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final boolean testTransients) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object,
+ testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * Collection of String field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final CollectionAccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final String... excludeFields) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object, false,
+ null, excludeFields);
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
for a boolean
.
+ * 1
when true, and 0
when false to the hashCode
.
+ * java.lang.Boolean.hashCode
handling, which computes
+ * a hashCode
value of 1231
for java.lang.Boolean
instances
+ * that represent true
or 1237
for java.lang.Boolean
instances
+ * that represent false
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean value) {
+ iTotal = iTotal * iConstant + (value ? 0 : 1);
+ return this;
+ }
+
+ /**
+ * hashCode
for a boolean
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final boolean element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final byte element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
array.
+ * hashCode
+ * @return this
+ */
+/**
+ * hashCode
for a char
array.
+ * hashCode
+ * @return this
+ */
+public org.apache.commons.lang3.builder.HashCodeBuilder append(final char[] array) {
+ {
+ for (final char element : /* NPEX_NULL_EXP */
+ array) {
+ append(element);
+ }
+ }
+ return this;
+}
+
+ /**
+ * hashCode
for a double
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double value) {
+ return append(Double.doubleToLongBits(value));
+ }
+
+ /**
+ * hashCode
for a double
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final double element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float value) {
+ iTotal = iTotal * iConstant + Float.floatToIntBits(value);
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final float element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final int element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
.
+ * hashCode
+ * @return this
+ */
+ // NOTE: This method uses >> and not >>> as Effective Java and
+ // Long.hashCode do. Ideally we should switch to >>> at
+ // some stage. There are backwards compat issues, so
+ // that will have to wait for the time being. cf LANG-342.
+ public HashCodeBuilder append(final long value) {
+ iTotal = iTotal * iConstant + ((int) (value ^ (value >> 32)));
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final long[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final long element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an Object
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object object) {
+ if (object == null) {
+ iTotal = iTotal * iConstant;
+
+ } else {
+ if (object.getClass().isArray()) {
+ // factor out array case in order to keep method small enough
+ // to be inlined
+ appendArray(object);
+ } else {
+ iTotal = iTotal * iConstant + object.hashCode();
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an array.
+ * hashCode
+ */
+ private void appendArray(final Object object) {
+ // 'Switch' on type of array, to dispatch to the correct handler
+ // This handles multi dimensional arrays
+ if (object instanceof long[]) {
+ append((long[]) object);
+ } else if (object instanceof int[]) {
+ append((int[]) object);
+ } else if (object instanceof short[]) {
+ append((short[]) object);
+ } else if (object instanceof char[]) {
+ append((char[]) object);
+ } else if (object instanceof byte[]) {
+ append((byte[]) object);
+ } else if (object instanceof double[]) {
+ append((double[]) object);
+ } else if (object instanceof float[]) {
+ append((float[]) object);
+ } else if (object instanceof boolean[]) {
+ append((boolean[]) object);
+ } else {
+ // Not an array of primitives
+ append((Object[]) object);
+ }
+ }
+
+ /**
+ * hashCode
for an Object
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final Object element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final short element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * super.hashCode()
+ * @return this HashCodeBuilder, used to chain calls.
+ * @since 2.0
+ */
+ public HashCodeBuilder appendSuper(final int superHashCode) {
+ iTotal = iTotal * iConstant + superHashCode;
+ return this;
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
based on the fields appended
+ */
+ public int toHashCode() {
+ return iTotal;
+ }
+
+ /**
+ * Returns the computed hashCode
.
+ *
+ * @return hashCode
based on the fields appended
+ *
+ * @since 3.0
+ */
+ @Override
+ public Integer build() {
+ return Integer.valueOf(toHashCode());
+ }
+
+ /**
+ * hashCode
from toHashCode() is returned due to the likelihood
+ * of bugs in mis-calling toHashCode() and the unlikeliness of it mattering what the hashCode for
+ * HashCodeBuilder itself is.hashCode
based on the fields appended
+ * @since 2.5
+ */
+ @Override
+ public int hashCode() {
+ return toHashCode();
+ }
+
+}
diff --git a/Java/commons-lang-HashCodeBuilder_683/metadata.json b/Java/commons-lang-HashCodeBuilder_683/metadata.json
new file mode 100644
index 000000000..3c32ed27b
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_683/metadata.json
@@ -0,0 +1,21 @@
+{
+ "language": "java",
+ "id": "commons-lang-HashCodeBuilder_683",
+ "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/builder/HashCodeBuilder.java",
+ "line": 694,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder",
+ "repo": "commons-lang",
+ "bug_id": "HashCodeBuilder_683"
+ }
+}
diff --git a/Java/commons-lang-HashCodeBuilder_683/npe.json b/Java/commons-lang-HashCodeBuilder_683/npe.json
new file mode 100644
index 000000000..69c7b4256
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_683/npe.json
@@ -0,0 +1,7 @@
+{
+ "filepath": "src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java",
+ "line": 694,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder"
+}
\ No newline at end of file
diff --git a/Java/commons-lang-HashCodeBuilder_716/Dockerfile b/Java/commons-lang-HashCodeBuilder_716/Dockerfile
new file mode 100644
index 000000000..7b7fbe349
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_716/Dockerfile
@@ -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
diff --git a/Java/commons-lang-HashCodeBuilder_716/buggy.java b/Java/commons-lang-HashCodeBuilder_716/buggy.java
new file mode 100644
index 000000000..207beeae2
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_716/buggy.java
@@ -0,0 +1,1004 @@
+/*
+ * 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.builder;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * hashCode
method to be built for any class. It follows the rules laid out in
+ * the book Effective Java by Joshua Bloch. Writing a
+ * good hashCode
method is actually quite difficult. This class aims to simplify the process.
+ * hashCode
method. Derived fields may be
+ * excluded. In general, any field used in the equals
method must be used in the hashCode
+ * method.
+ *
+ * public class Person {
+ * String name;
+ * int age;
+ * boolean smoker;
+ * ...
+ *
+ * public int hashCode() {
+ * // you pick a hard-coded, randomly chosen, non-zero, odd number
+ * // ideally different for each class
+ * return new HashCodeBuilder(17, 37).
+ * append(name).
+ * append(age).
+ * append(smoker).
+ * toHashCode();
+ * }
+ * }
+ *
+ *
+ * hashCode()
can be added using {@link #appendSuper}.
+ * reflectionHashCode
, uses AccessibleObject.setAccessible
+ * to change the visibility of the fields. This will fail under a security manager, unless the appropriate permissions
+ * are set up correctly. It is also slower than testing explicitly.
+ *
+ * public int hashCode() {
+ * return HashCodeBuilder.reflectionHashCode(this);
+ * }
+ *
+ *
+ * reflectionHashCode
methods.true
if the registry contains the given object. Used by the reflection methods to avoid
+ * infinite loops.
+ * true
if the registry contains the given object.
+ * @since 2.3
+ */
+ static boolean isRegistered(final Object value) {
+ final SetClass
.
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, false, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object,
+ final boolean testTransients) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @param reflectUpToClass
+ * the superclass to reflect up to (inclusive), may be null
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ * @since 2.0
+ */
+ public static AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final boolean testTransients) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object,
+ testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * Collection of String field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final CollectionAccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final String... excludeFields) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object, false,
+ null, excludeFields);
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
for a boolean
.
+ * 1
when true, and 0
when false to the hashCode
.
+ * java.lang.Boolean.hashCode
handling, which computes
+ * a hashCode
value of 1231
for java.lang.Boolean
instances
+ * that represent true
or 1237
for java.lang.Boolean
instances
+ * that represent false
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean value) {
+ iTotal = iTotal * iConstant + (value ? 0 : 1);
+ return this;
+ }
+
+ /**
+ * hashCode
for a boolean
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final boolean element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final byte element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final char element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a double
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double value) {
+ return append(Double.doubleToLongBits(value));
+ }
+
+ /**
+ * hashCode
for a double
array.
+ * hashCode
+ * @return this
+ */
+/**
+ * hashCode
for a double
array.
+ * hashCode
+ * @return this
+ */
+public org.apache.commons.lang3.builder.HashCodeBuilder append(final double[] array) {
+ {
+ for (final double element : /* NPEX_NULL_EXP */
+ array) {
+ append(element);
+ }
+ }
+ return this;
+}
+
+ /**
+ * hashCode
for a float
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float value) {
+ iTotal = iTotal * iConstant + Float.floatToIntBits(value);
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final float element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final int element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
.
+ * hashCode
+ * @return this
+ */
+ // NOTE: This method uses >> and not >>> as Effective Java and
+ // Long.hashCode do. Ideally we should switch to >>> at
+ // some stage. There are backwards compat issues, so
+ // that will have to wait for the time being. cf LANG-342.
+ public HashCodeBuilder append(final long value) {
+ iTotal = iTotal * iConstant + ((int) (value ^ (value >> 32)));
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final long[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final long element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an Object
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object object) {
+ if (object == null) {
+ iTotal = iTotal * iConstant;
+
+ } else {
+ if (object.getClass().isArray()) {
+ // factor out array case in order to keep method small enough
+ // to be inlined
+ appendArray(object);
+ } else {
+ iTotal = iTotal * iConstant + object.hashCode();
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an array.
+ * hashCode
+ */
+ private void appendArray(final Object object) {
+ // 'Switch' on type of array, to dispatch to the correct handler
+ // This handles multi dimensional arrays
+ if (object instanceof long[]) {
+ append((long[]) object);
+ } else if (object instanceof int[]) {
+ append((int[]) object);
+ } else if (object instanceof short[]) {
+ append((short[]) object);
+ } else if (object instanceof char[]) {
+ append((char[]) object);
+ } else if (object instanceof byte[]) {
+ append((byte[]) object);
+ } else if (object instanceof double[]) {
+ append((double[]) object);
+ } else if (object instanceof float[]) {
+ append((float[]) object);
+ } else if (object instanceof boolean[]) {
+ append((boolean[]) object);
+ } else {
+ // Not an array of primitives
+ append((Object[]) object);
+ }
+ }
+
+ /**
+ * hashCode
for an Object
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final Object element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final short element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * super.hashCode()
+ * @return this HashCodeBuilder, used to chain calls.
+ * @since 2.0
+ */
+ public HashCodeBuilder appendSuper(final int superHashCode) {
+ iTotal = iTotal * iConstant + superHashCode;
+ return this;
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
based on the fields appended
+ */
+ public int toHashCode() {
+ return iTotal;
+ }
+
+ /**
+ * Returns the computed hashCode
.
+ *
+ * @return hashCode
based on the fields appended
+ *
+ * @since 3.0
+ */
+ @Override
+ public Integer build() {
+ return Integer.valueOf(toHashCode());
+ }
+
+ /**
+ * hashCode
from toHashCode() is returned due to the likelihood
+ * of bugs in mis-calling toHashCode() and the unlikeliness of it mattering what the hashCode for
+ * HashCodeBuilder itself is.hashCode
based on the fields appended
+ * @since 2.5
+ */
+ @Override
+ public int hashCode() {
+ return toHashCode();
+ }
+
+}
diff --git a/Java/commons-lang-HashCodeBuilder_716/metadata.json b/Java/commons-lang-HashCodeBuilder_716/metadata.json
new file mode 100644
index 000000000..3f9422d9c
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_716/metadata.json
@@ -0,0 +1,21 @@
+{
+ "language": "java",
+ "id": "commons-lang-HashCodeBuilder_716",
+ "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/builder/HashCodeBuilder.java",
+ "line": 727,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder",
+ "repo": "commons-lang",
+ "bug_id": "HashCodeBuilder_716"
+ }
+}
diff --git a/Java/commons-lang-HashCodeBuilder_716/npe.json b/Java/commons-lang-HashCodeBuilder_716/npe.json
new file mode 100644
index 000000000..1a9d6e6a0
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_716/npe.json
@@ -0,0 +1,7 @@
+{
+ "filepath": "src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java",
+ "line": 727,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder"
+}
\ No newline at end of file
diff --git a/Java/commons-lang-HashCodeBuilder_750/Dockerfile b/Java/commons-lang-HashCodeBuilder_750/Dockerfile
new file mode 100644
index 000000000..7b7fbe349
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_750/Dockerfile
@@ -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
diff --git a/Java/commons-lang-HashCodeBuilder_750/buggy.java b/Java/commons-lang-HashCodeBuilder_750/buggy.java
new file mode 100644
index 000000000..1455cff16
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_750/buggy.java
@@ -0,0 +1,1004 @@
+/*
+ * 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.builder;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * hashCode
method to be built for any class. It follows the rules laid out in
+ * the book Effective Java by Joshua Bloch. Writing a
+ * good hashCode
method is actually quite difficult. This class aims to simplify the process.
+ * hashCode
method. Derived fields may be
+ * excluded. In general, any field used in the equals
method must be used in the hashCode
+ * method.
+ *
+ * public class Person {
+ * String name;
+ * int age;
+ * boolean smoker;
+ * ...
+ *
+ * public int hashCode() {
+ * // you pick a hard-coded, randomly chosen, non-zero, odd number
+ * // ideally different for each class
+ * return new HashCodeBuilder(17, 37).
+ * append(name).
+ * append(age).
+ * append(smoker).
+ * toHashCode();
+ * }
+ * }
+ *
+ *
+ * hashCode()
can be added using {@link #appendSuper}.
+ * reflectionHashCode
, uses AccessibleObject.setAccessible
+ * to change the visibility of the fields. This will fail under a security manager, unless the appropriate permissions
+ * are set up correctly. It is also slower than testing explicitly.
+ *
+ * public int hashCode() {
+ * return HashCodeBuilder.reflectionHashCode(this);
+ * }
+ *
+ *
+ * reflectionHashCode
methods.true
if the registry contains the given object. Used by the reflection methods to avoid
+ * infinite loops.
+ * true
if the registry contains the given object.
+ * @since 2.3
+ */
+ static boolean isRegistered(final Object value) {
+ final SetClass
.
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, false, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object,
+ final boolean testTransients) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @param reflectUpToClass
+ * the superclass to reflect up to (inclusive), may be null
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ * @since 2.0
+ */
+ public static AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final boolean testTransients) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object,
+ testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * Collection of String field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final CollectionAccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final String... excludeFields) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object, false,
+ null, excludeFields);
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
for a boolean
.
+ * 1
when true, and 0
when false to the hashCode
.
+ * java.lang.Boolean.hashCode
handling, which computes
+ * a hashCode
value of 1231
for java.lang.Boolean
instances
+ * that represent true
or 1237
for java.lang.Boolean
instances
+ * that represent false
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean value) {
+ iTotal = iTotal * iConstant + (value ? 0 : 1);
+ return this;
+ }
+
+ /**
+ * hashCode
for a boolean
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final boolean element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final byte element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final char element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a double
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double value) {
+ return append(Double.doubleToLongBits(value));
+ }
+
+ /**
+ * hashCode
for a double
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final double element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float value) {
+ iTotal = iTotal * iConstant + Float.floatToIntBits(value);
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
array.
+ * hashCode
+ * @return this
+ */
+/**
+ * hashCode
for a float
array.
+ * hashCode
+ * @return this
+ */
+public org.apache.commons.lang3.builder.HashCodeBuilder append(final float[] array) {
+ {
+ for (final float element : /* NPEX_NULL_EXP */
+ array) {
+ append(element);
+ }
+ }
+ return this;
+}
+
+ /**
+ * hashCode
for an int
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final int element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
.
+ * hashCode
+ * @return this
+ */
+ // NOTE: This method uses >> and not >>> as Effective Java and
+ // Long.hashCode do. Ideally we should switch to >>> at
+ // some stage. There are backwards compat issues, so
+ // that will have to wait for the time being. cf LANG-342.
+ public HashCodeBuilder append(final long value) {
+ iTotal = iTotal * iConstant + ((int) (value ^ (value >> 32)));
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final long[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final long element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an Object
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object object) {
+ if (object == null) {
+ iTotal = iTotal * iConstant;
+
+ } else {
+ if (object.getClass().isArray()) {
+ // factor out array case in order to keep method small enough
+ // to be inlined
+ appendArray(object);
+ } else {
+ iTotal = iTotal * iConstant + object.hashCode();
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an array.
+ * hashCode
+ */
+ private void appendArray(final Object object) {
+ // 'Switch' on type of array, to dispatch to the correct handler
+ // This handles multi dimensional arrays
+ if (object instanceof long[]) {
+ append((long[]) object);
+ } else if (object instanceof int[]) {
+ append((int[]) object);
+ } else if (object instanceof short[]) {
+ append((short[]) object);
+ } else if (object instanceof char[]) {
+ append((char[]) object);
+ } else if (object instanceof byte[]) {
+ append((byte[]) object);
+ } else if (object instanceof double[]) {
+ append((double[]) object);
+ } else if (object instanceof float[]) {
+ append((float[]) object);
+ } else if (object instanceof boolean[]) {
+ append((boolean[]) object);
+ } else {
+ // Not an array of primitives
+ append((Object[]) object);
+ }
+ }
+
+ /**
+ * hashCode
for an Object
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final Object element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final short element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * super.hashCode()
+ * @return this HashCodeBuilder, used to chain calls.
+ * @since 2.0
+ */
+ public HashCodeBuilder appendSuper(final int superHashCode) {
+ iTotal = iTotal * iConstant + superHashCode;
+ return this;
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
based on the fields appended
+ */
+ public int toHashCode() {
+ return iTotal;
+ }
+
+ /**
+ * Returns the computed hashCode
.
+ *
+ * @return hashCode
based on the fields appended
+ *
+ * @since 3.0
+ */
+ @Override
+ public Integer build() {
+ return Integer.valueOf(toHashCode());
+ }
+
+ /**
+ * hashCode
from toHashCode() is returned due to the likelihood
+ * of bugs in mis-calling toHashCode() and the unlikeliness of it mattering what the hashCode for
+ * HashCodeBuilder itself is.hashCode
based on the fields appended
+ * @since 2.5
+ */
+ @Override
+ public int hashCode() {
+ return toHashCode();
+ }
+
+}
diff --git a/Java/commons-lang-HashCodeBuilder_750/metadata.json b/Java/commons-lang-HashCodeBuilder_750/metadata.json
new file mode 100644
index 000000000..e40c259c5
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_750/metadata.json
@@ -0,0 +1,21 @@
+{
+ "language": "java",
+ "id": "commons-lang-HashCodeBuilder_750",
+ "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/builder/HashCodeBuilder.java",
+ "line": 761,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder",
+ "repo": "commons-lang",
+ "bug_id": "HashCodeBuilder_750"
+ }
+}
diff --git a/Java/commons-lang-HashCodeBuilder_750/npe.json b/Java/commons-lang-HashCodeBuilder_750/npe.json
new file mode 100644
index 000000000..e3c524be8
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_750/npe.json
@@ -0,0 +1,7 @@
+{
+ "filepath": "src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java",
+ "line": 761,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder"
+}
\ No newline at end of file
diff --git a/Java/commons-lang-HashCodeBuilder_784/Dockerfile b/Java/commons-lang-HashCodeBuilder_784/Dockerfile
new file mode 100644
index 000000000..7b7fbe349
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_784/Dockerfile
@@ -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
diff --git a/Java/commons-lang-HashCodeBuilder_784/buggy.java b/Java/commons-lang-HashCodeBuilder_784/buggy.java
new file mode 100644
index 000000000..37a24abf3
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_784/buggy.java
@@ -0,0 +1,1004 @@
+/*
+ * 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.builder;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * hashCode
method to be built for any class. It follows the rules laid out in
+ * the book Effective Java by Joshua Bloch. Writing a
+ * good hashCode
method is actually quite difficult. This class aims to simplify the process.
+ * hashCode
method. Derived fields may be
+ * excluded. In general, any field used in the equals
method must be used in the hashCode
+ * method.
+ *
+ * public class Person {
+ * String name;
+ * int age;
+ * boolean smoker;
+ * ...
+ *
+ * public int hashCode() {
+ * // you pick a hard-coded, randomly chosen, non-zero, odd number
+ * // ideally different for each class
+ * return new HashCodeBuilder(17, 37).
+ * append(name).
+ * append(age).
+ * append(smoker).
+ * toHashCode();
+ * }
+ * }
+ *
+ *
+ * hashCode()
can be added using {@link #appendSuper}.
+ * reflectionHashCode
, uses AccessibleObject.setAccessible
+ * to change the visibility of the fields. This will fail under a security manager, unless the appropriate permissions
+ * are set up correctly. It is also slower than testing explicitly.
+ *
+ * public int hashCode() {
+ * return HashCodeBuilder.reflectionHashCode(this);
+ * }
+ *
+ *
+ * reflectionHashCode
methods.true
if the registry contains the given object. Used by the reflection methods to avoid
+ * infinite loops.
+ * true
if the registry contains the given object.
+ * @since 2.3
+ */
+ static boolean isRegistered(final Object value) {
+ final SetClass
.
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, false, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object,
+ final boolean testTransients) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @param reflectUpToClass
+ * the superclass to reflect up to (inclusive), may be null
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ * @since 2.0
+ */
+ public static AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final boolean testTransients) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object,
+ testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * Collection of String field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final CollectionAccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final String... excludeFields) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object, false,
+ null, excludeFields);
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
for a boolean
.
+ * 1
when true, and 0
when false to the hashCode
.
+ * java.lang.Boolean.hashCode
handling, which computes
+ * a hashCode
value of 1231
for java.lang.Boolean
instances
+ * that represent true
or 1237
for java.lang.Boolean
instances
+ * that represent false
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean value) {
+ iTotal = iTotal * iConstant + (value ? 0 : 1);
+ return this;
+ }
+
+ /**
+ * hashCode
for a boolean
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final boolean element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final byte element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final char element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a double
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double value) {
+ return append(Double.doubleToLongBits(value));
+ }
+
+ /**
+ * hashCode
for a double
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final double element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float value) {
+ iTotal = iTotal * iConstant + Float.floatToIntBits(value);
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final float element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
array.
+ * hashCode
+ * @return this
+ */
+/**
+ * hashCode
for an int
array.
+ * hashCode
+ * @return this
+ */
+public org.apache.commons.lang3.builder.HashCodeBuilder append(final int[] array) {
+ {
+ for (final int element : /* NPEX_NULL_EXP */
+ array) {
+ append(element);
+ }
+ }
+ return this;
+}
+
+ /**
+ * hashCode
for a long
.
+ * hashCode
+ * @return this
+ */
+ // NOTE: This method uses >> and not >>> as Effective Java and
+ // Long.hashCode do. Ideally we should switch to >>> at
+ // some stage. There are backwards compat issues, so
+ // that will have to wait for the time being. cf LANG-342.
+ public HashCodeBuilder append(final long value) {
+ iTotal = iTotal * iConstant + ((int) (value ^ (value >> 32)));
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final long[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final long element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an Object
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object object) {
+ if (object == null) {
+ iTotal = iTotal * iConstant;
+
+ } else {
+ if (object.getClass().isArray()) {
+ // factor out array case in order to keep method small enough
+ // to be inlined
+ appendArray(object);
+ } else {
+ iTotal = iTotal * iConstant + object.hashCode();
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an array.
+ * hashCode
+ */
+ private void appendArray(final Object object) {
+ // 'Switch' on type of array, to dispatch to the correct handler
+ // This handles multi dimensional arrays
+ if (object instanceof long[]) {
+ append((long[]) object);
+ } else if (object instanceof int[]) {
+ append((int[]) object);
+ } else if (object instanceof short[]) {
+ append((short[]) object);
+ } else if (object instanceof char[]) {
+ append((char[]) object);
+ } else if (object instanceof byte[]) {
+ append((byte[]) object);
+ } else if (object instanceof double[]) {
+ append((double[]) object);
+ } else if (object instanceof float[]) {
+ append((float[]) object);
+ } else if (object instanceof boolean[]) {
+ append((boolean[]) object);
+ } else {
+ // Not an array of primitives
+ append((Object[]) object);
+ }
+ }
+
+ /**
+ * hashCode
for an Object
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final Object element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final short element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * super.hashCode()
+ * @return this HashCodeBuilder, used to chain calls.
+ * @since 2.0
+ */
+ public HashCodeBuilder appendSuper(final int superHashCode) {
+ iTotal = iTotal * iConstant + superHashCode;
+ return this;
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
based on the fields appended
+ */
+ public int toHashCode() {
+ return iTotal;
+ }
+
+ /**
+ * Returns the computed hashCode
.
+ *
+ * @return hashCode
based on the fields appended
+ *
+ * @since 3.0
+ */
+ @Override
+ public Integer build() {
+ return Integer.valueOf(toHashCode());
+ }
+
+ /**
+ * hashCode
from toHashCode() is returned due to the likelihood
+ * of bugs in mis-calling toHashCode() and the unlikeliness of it mattering what the hashCode for
+ * HashCodeBuilder itself is.hashCode
based on the fields appended
+ * @since 2.5
+ */
+ @Override
+ public int hashCode() {
+ return toHashCode();
+ }
+
+}
diff --git a/Java/commons-lang-HashCodeBuilder_784/metadata.json b/Java/commons-lang-HashCodeBuilder_784/metadata.json
new file mode 100644
index 000000000..531c6c285
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_784/metadata.json
@@ -0,0 +1,21 @@
+{
+ "language": "java",
+ "id": "commons-lang-HashCodeBuilder_784",
+ "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/builder/HashCodeBuilder.java",
+ "line": 795,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder",
+ "repo": "commons-lang",
+ "bug_id": "HashCodeBuilder_784"
+ }
+}
diff --git a/Java/commons-lang-HashCodeBuilder_784/npe.json b/Java/commons-lang-HashCodeBuilder_784/npe.json
new file mode 100644
index 000000000..8b878376b
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_784/npe.json
@@ -0,0 +1,7 @@
+{
+ "filepath": "src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java",
+ "line": 795,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder"
+}
\ No newline at end of file
diff --git a/Java/commons-lang-HashCodeBuilder_822/Dockerfile b/Java/commons-lang-HashCodeBuilder_822/Dockerfile
new file mode 100644
index 000000000..7b7fbe349
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_822/Dockerfile
@@ -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
diff --git a/Java/commons-lang-HashCodeBuilder_822/buggy.java b/Java/commons-lang-HashCodeBuilder_822/buggy.java
new file mode 100644
index 000000000..95f4273fe
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_822/buggy.java
@@ -0,0 +1,1004 @@
+/*
+ * 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.builder;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * hashCode
method to be built for any class. It follows the rules laid out in
+ * the book Effective Java by Joshua Bloch. Writing a
+ * good hashCode
method is actually quite difficult. This class aims to simplify the process.
+ * hashCode
method. Derived fields may be
+ * excluded. In general, any field used in the equals
method must be used in the hashCode
+ * method.
+ *
+ * public class Person {
+ * String name;
+ * int age;
+ * boolean smoker;
+ * ...
+ *
+ * public int hashCode() {
+ * // you pick a hard-coded, randomly chosen, non-zero, odd number
+ * // ideally different for each class
+ * return new HashCodeBuilder(17, 37).
+ * append(name).
+ * append(age).
+ * append(smoker).
+ * toHashCode();
+ * }
+ * }
+ *
+ *
+ * hashCode()
can be added using {@link #appendSuper}.
+ * reflectionHashCode
, uses AccessibleObject.setAccessible
+ * to change the visibility of the fields. This will fail under a security manager, unless the appropriate permissions
+ * are set up correctly. It is also slower than testing explicitly.
+ *
+ * public int hashCode() {
+ * return HashCodeBuilder.reflectionHashCode(this);
+ * }
+ *
+ *
+ * reflectionHashCode
methods.true
if the registry contains the given object. Used by the reflection methods to avoid
+ * infinite loops.
+ * true
if the registry contains the given object.
+ * @since 2.3
+ */
+ static boolean isRegistered(final Object value) {
+ final SetClass
.
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, false, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object,
+ final boolean testTransients) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @param reflectUpToClass
+ * the superclass to reflect up to (inclusive), may be null
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ * @since 2.0
+ */
+ public static AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final boolean testTransients) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object,
+ testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * Collection of String field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final CollectionAccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final String... excludeFields) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object, false,
+ null, excludeFields);
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
for a boolean
.
+ * 1
when true, and 0
when false to the hashCode
.
+ * java.lang.Boolean.hashCode
handling, which computes
+ * a hashCode
value of 1231
for java.lang.Boolean
instances
+ * that represent true
or 1237
for java.lang.Boolean
instances
+ * that represent false
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean value) {
+ iTotal = iTotal * iConstant + (value ? 0 : 1);
+ return this;
+ }
+
+ /**
+ * hashCode
for a boolean
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final boolean element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final byte element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final char element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a double
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double value) {
+ return append(Double.doubleToLongBits(value));
+ }
+
+ /**
+ * hashCode
for a double
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final double element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float value) {
+ iTotal = iTotal * iConstant + Float.floatToIntBits(value);
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final float element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final int element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
.
+ * hashCode
+ * @return this
+ */
+ // NOTE: This method uses >> and not >>> as Effective Java and
+ // Long.hashCode do. Ideally we should switch to >>> at
+ // some stage. There are backwards compat issues, so
+ // that will have to wait for the time being. cf LANG-342.
+ public HashCodeBuilder append(final long value) {
+ iTotal = iTotal * iConstant + ((int) (value ^ (value >> 32)));
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
array.
+ * hashCode
+ * @return this
+ */
+/**
+ * hashCode
for a long
array.
+ * hashCode
+ * @return this
+ */
+public org.apache.commons.lang3.builder.HashCodeBuilder append(final long[] array) {
+ {
+ for (final long element : /* NPEX_NULL_EXP */
+ array) {
+ append(element);
+ }
+ }
+ return this;
+}
+
+ /**
+ * hashCode
for an Object
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object object) {
+ if (object == null) {
+ iTotal = iTotal * iConstant;
+
+ } else {
+ if (object.getClass().isArray()) {
+ // factor out array case in order to keep method small enough
+ // to be inlined
+ appendArray(object);
+ } else {
+ iTotal = iTotal * iConstant + object.hashCode();
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an array.
+ * hashCode
+ */
+ private void appendArray(final Object object) {
+ // 'Switch' on type of array, to dispatch to the correct handler
+ // This handles multi dimensional arrays
+ if (object instanceof long[]) {
+ append((long[]) object);
+ } else if (object instanceof int[]) {
+ append((int[]) object);
+ } else if (object instanceof short[]) {
+ append((short[]) object);
+ } else if (object instanceof char[]) {
+ append((char[]) object);
+ } else if (object instanceof byte[]) {
+ append((byte[]) object);
+ } else if (object instanceof double[]) {
+ append((double[]) object);
+ } else if (object instanceof float[]) {
+ append((float[]) object);
+ } else if (object instanceof boolean[]) {
+ append((boolean[]) object);
+ } else {
+ // Not an array of primitives
+ append((Object[]) object);
+ }
+ }
+
+ /**
+ * hashCode
for an Object
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final Object element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final short element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * super.hashCode()
+ * @return this HashCodeBuilder, used to chain calls.
+ * @since 2.0
+ */
+ public HashCodeBuilder appendSuper(final int superHashCode) {
+ iTotal = iTotal * iConstant + superHashCode;
+ return this;
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
based on the fields appended
+ */
+ public int toHashCode() {
+ return iTotal;
+ }
+
+ /**
+ * Returns the computed hashCode
.
+ *
+ * @return hashCode
based on the fields appended
+ *
+ * @since 3.0
+ */
+ @Override
+ public Integer build() {
+ return Integer.valueOf(toHashCode());
+ }
+
+ /**
+ * hashCode
from toHashCode() is returned due to the likelihood
+ * of bugs in mis-calling toHashCode() and the unlikeliness of it mattering what the hashCode for
+ * HashCodeBuilder itself is.hashCode
based on the fields appended
+ * @since 2.5
+ */
+ @Override
+ public int hashCode() {
+ return toHashCode();
+ }
+
+}
diff --git a/Java/commons-lang-HashCodeBuilder_822/metadata.json b/Java/commons-lang-HashCodeBuilder_822/metadata.json
new file mode 100644
index 000000000..70ebc8b99
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_822/metadata.json
@@ -0,0 +1,21 @@
+{
+ "language": "java",
+ "id": "commons-lang-HashCodeBuilder_822",
+ "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/builder/HashCodeBuilder.java",
+ "line": 833,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder",
+ "repo": "commons-lang",
+ "bug_id": "HashCodeBuilder_822"
+ }
+}
diff --git a/Java/commons-lang-HashCodeBuilder_822/npe.json b/Java/commons-lang-HashCodeBuilder_822/npe.json
new file mode 100644
index 000000000..8fdcddd8f
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_822/npe.json
@@ -0,0 +1,7 @@
+{
+ "filepath": "src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java",
+ "line": 833,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder"
+}
\ No newline at end of file
diff --git a/Java/commons-lang-HashCodeBuilder_842/Dockerfile b/Java/commons-lang-HashCodeBuilder_842/Dockerfile
new file mode 100644
index 000000000..7b7fbe349
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_842/Dockerfile
@@ -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
diff --git a/Java/commons-lang-HashCodeBuilder_842/buggy.java b/Java/commons-lang-HashCodeBuilder_842/buggy.java
new file mode 100644
index 000000000..f04363d48
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_842/buggy.java
@@ -0,0 +1,1003 @@
+/*
+ * 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.builder;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * hashCode
method to be built for any class. It follows the rules laid out in
+ * the book Effective Java by Joshua Bloch. Writing a
+ * good hashCode
method is actually quite difficult. This class aims to simplify the process.
+ * hashCode
method. Derived fields may be
+ * excluded. In general, any field used in the equals
method must be used in the hashCode
+ * method.
+ *
+ * public class Person {
+ * String name;
+ * int age;
+ * boolean smoker;
+ * ...
+ *
+ * public int hashCode() {
+ * // you pick a hard-coded, randomly chosen, non-zero, odd number
+ * // ideally different for each class
+ * return new HashCodeBuilder(17, 37).
+ * append(name).
+ * append(age).
+ * append(smoker).
+ * toHashCode();
+ * }
+ * }
+ *
+ *
+ * hashCode()
can be added using {@link #appendSuper}.
+ * reflectionHashCode
, uses AccessibleObject.setAccessible
+ * to change the visibility of the fields. This will fail under a security manager, unless the appropriate permissions
+ * are set up correctly. It is also slower than testing explicitly.
+ *
+ * public int hashCode() {
+ * return HashCodeBuilder.reflectionHashCode(this);
+ * }
+ *
+ *
+ * reflectionHashCode
methods.true
if the registry contains the given object. Used by the reflection methods to avoid
+ * infinite loops.
+ * true
if the registry contains the given object.
+ * @since 2.3
+ */
+ static boolean isRegistered(final Object value) {
+ final SetClass
.
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, false, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object,
+ final boolean testTransients) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @param reflectUpToClass
+ * the superclass to reflect up to (inclusive), may be null
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ * @since 2.0
+ */
+ public static AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final boolean testTransients) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object,
+ testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * Collection of String field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final CollectionAccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final String... excludeFields) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object, false,
+ null, excludeFields);
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
for a boolean
.
+ * 1
when true, and 0
when false to the hashCode
.
+ * java.lang.Boolean.hashCode
handling, which computes
+ * a hashCode
value of 1231
for java.lang.Boolean
instances
+ * that represent true
or 1237
for java.lang.Boolean
instances
+ * that represent false
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean value) {
+ iTotal = iTotal * iConstant + (value ? 0 : 1);
+ return this;
+ }
+
+ /**
+ * hashCode
for a boolean
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final boolean element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final byte element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final char element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a double
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double value) {
+ return append(Double.doubleToLongBits(value));
+ }
+
+ /**
+ * hashCode
for a double
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final double element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float value) {
+ iTotal = iTotal * iConstant + Float.floatToIntBits(value);
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final float element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final int element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
.
+ * hashCode
+ * @return this
+ */
+ // NOTE: This method uses >> and not >>> as Effective Java and
+ // Long.hashCode do. Ideally we should switch to >>> at
+ // some stage. There are backwards compat issues, so
+ // that will have to wait for the time being. cf LANG-342.
+ public HashCodeBuilder append(final long value) {
+ iTotal = iTotal * iConstant + ((int) (value ^ (value >> 32)));
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final long[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final long element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an Object
.
+ * hashCode
+ * @return this
+ */
+/**
+ * hashCode
for an Object
.
+ * hashCode
+ * @return this
+ */
+public org.apache.commons.lang3.builder.HashCodeBuilder append(final java.lang.Object object) {
+ {
+ if (/* NPEX_NULL_EXP */
+ object.getClass().isArray()) {
+ // factor out array case in order to keep method small enough
+ // to be inlined
+ appendArray(object);
+ } else {
+ iTotal = (iTotal * iConstant) + object.hashCode();
+ }
+ }
+ return this;
+}
+
+ /**
+ * hashCode
for an array.
+ * hashCode
+ */
+ private void appendArray(final Object object) {
+ // 'Switch' on type of array, to dispatch to the correct handler
+ // This handles multi dimensional arrays
+ if (object instanceof long[]) {
+ append((long[]) object);
+ } else if (object instanceof int[]) {
+ append((int[]) object);
+ } else if (object instanceof short[]) {
+ append((short[]) object);
+ } else if (object instanceof char[]) {
+ append((char[]) object);
+ } else if (object instanceof byte[]) {
+ append((byte[]) object);
+ } else if (object instanceof double[]) {
+ append((double[]) object);
+ } else if (object instanceof float[]) {
+ append((float[]) object);
+ } else if (object instanceof boolean[]) {
+ append((boolean[]) object);
+ } else {
+ // Not an array of primitives
+ append((Object[]) object);
+ }
+ }
+
+ /**
+ * hashCode
for an Object
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final Object element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final short element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * super.hashCode()
+ * @return this HashCodeBuilder, used to chain calls.
+ * @since 2.0
+ */
+ public HashCodeBuilder appendSuper(final int superHashCode) {
+ iTotal = iTotal * iConstant + superHashCode;
+ return this;
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
based on the fields appended
+ */
+ public int toHashCode() {
+ return iTotal;
+ }
+
+ /**
+ * Returns the computed hashCode
.
+ *
+ * @return hashCode
based on the fields appended
+ *
+ * @since 3.0
+ */
+ @Override
+ public Integer build() {
+ return Integer.valueOf(toHashCode());
+ }
+
+ /**
+ * hashCode
from toHashCode() is returned due to the likelihood
+ * of bugs in mis-calling toHashCode() and the unlikeliness of it mattering what the hashCode for
+ * HashCodeBuilder itself is.hashCode
based on the fields appended
+ * @since 2.5
+ */
+ @Override
+ public int hashCode() {
+ return toHashCode();
+ }
+
+}
diff --git a/Java/commons-lang-HashCodeBuilder_842/metadata.json b/Java/commons-lang-HashCodeBuilder_842/metadata.json
new file mode 100644
index 000000000..6209cf788
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_842/metadata.json
@@ -0,0 +1,21 @@
+{
+ "language": "java",
+ "id": "commons-lang-HashCodeBuilder_842",
+ "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/builder/HashCodeBuilder.java",
+ "line": 853,
+ "npe_method": "append",
+ "deref_field": "object",
+ "npe_class": "HashCodeBuilder",
+ "repo": "commons-lang",
+ "bug_id": "HashCodeBuilder_842"
+ }
+}
diff --git a/Java/commons-lang-HashCodeBuilder_842/npe.json b/Java/commons-lang-HashCodeBuilder_842/npe.json
new file mode 100644
index 000000000..ec405e4a3
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_842/npe.json
@@ -0,0 +1,7 @@
+{
+ "filepath": "src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java",
+ "line": 853,
+ "npe_method": "append",
+ "deref_field": "object",
+ "npe_class": "HashCodeBuilder"
+}
\ No newline at end of file
diff --git a/Java/commons-lang-HashCodeBuilder_900/Dockerfile b/Java/commons-lang-HashCodeBuilder_900/Dockerfile
new file mode 100644
index 000000000..7b7fbe349
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_900/Dockerfile
@@ -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
diff --git a/Java/commons-lang-HashCodeBuilder_900/buggy.java b/Java/commons-lang-HashCodeBuilder_900/buggy.java
new file mode 100644
index 000000000..8ea8993c2
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_900/buggy.java
@@ -0,0 +1,1004 @@
+/*
+ * 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.builder;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * hashCode
method to be built for any class. It follows the rules laid out in
+ * the book Effective Java by Joshua Bloch. Writing a
+ * good hashCode
method is actually quite difficult. This class aims to simplify the process.
+ * hashCode
method. Derived fields may be
+ * excluded. In general, any field used in the equals
method must be used in the hashCode
+ * method.
+ *
+ * public class Person {
+ * String name;
+ * int age;
+ * boolean smoker;
+ * ...
+ *
+ * public int hashCode() {
+ * // you pick a hard-coded, randomly chosen, non-zero, odd number
+ * // ideally different for each class
+ * return new HashCodeBuilder(17, 37).
+ * append(name).
+ * append(age).
+ * append(smoker).
+ * toHashCode();
+ * }
+ * }
+ *
+ *
+ * hashCode()
can be added using {@link #appendSuper}.
+ * reflectionHashCode
, uses AccessibleObject.setAccessible
+ * to change the visibility of the fields. This will fail under a security manager, unless the appropriate permissions
+ * are set up correctly. It is also slower than testing explicitly.
+ *
+ * public int hashCode() {
+ * return HashCodeBuilder.reflectionHashCode(this);
+ * }
+ *
+ *
+ * reflectionHashCode
methods.true
if the registry contains the given object. Used by the reflection methods to avoid
+ * infinite loops.
+ * true
if the registry contains the given object.
+ * @since 2.3
+ */
+ static boolean isRegistered(final Object value) {
+ final SetClass
.
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, false, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object,
+ final boolean testTransients) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @param reflectUpToClass
+ * the superclass to reflect up to (inclusive), may be null
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ * @since 2.0
+ */
+ public static AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final boolean testTransients) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object,
+ testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * Collection of String field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final CollectionAccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final String... excludeFields) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object, false,
+ null, excludeFields);
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
for a boolean
.
+ * 1
when true, and 0
when false to the hashCode
.
+ * java.lang.Boolean.hashCode
handling, which computes
+ * a hashCode
value of 1231
for java.lang.Boolean
instances
+ * that represent true
or 1237
for java.lang.Boolean
instances
+ * that represent false
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean value) {
+ iTotal = iTotal * iConstant + (value ? 0 : 1);
+ return this;
+ }
+
+ /**
+ * hashCode
for a boolean
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final boolean element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final byte element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final char element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a double
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double value) {
+ return append(Double.doubleToLongBits(value));
+ }
+
+ /**
+ * hashCode
for a double
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final double element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float value) {
+ iTotal = iTotal * iConstant + Float.floatToIntBits(value);
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final float element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final int element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
.
+ * hashCode
+ * @return this
+ */
+ // NOTE: This method uses >> and not >>> as Effective Java and
+ // Long.hashCode do. Ideally we should switch to >>> at
+ // some stage. There are backwards compat issues, so
+ // that will have to wait for the time being. cf LANG-342.
+ public HashCodeBuilder append(final long value) {
+ iTotal = iTotal * iConstant + ((int) (value ^ (value >> 32)));
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final long[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final long element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an Object
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object object) {
+ if (object == null) {
+ iTotal = iTotal * iConstant;
+
+ } else {
+ if (object.getClass().isArray()) {
+ // factor out array case in order to keep method small enough
+ // to be inlined
+ appendArray(object);
+ } else {
+ iTotal = iTotal * iConstant + object.hashCode();
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an array.
+ * hashCode
+ */
+ private void appendArray(final Object object) {
+ // 'Switch' on type of array, to dispatch to the correct handler
+ // This handles multi dimensional arrays
+ if (object instanceof long[]) {
+ append((long[]) object);
+ } else if (object instanceof int[]) {
+ append((int[]) object);
+ } else if (object instanceof short[]) {
+ append((short[]) object);
+ } else if (object instanceof char[]) {
+ append((char[]) object);
+ } else if (object instanceof byte[]) {
+ append((byte[]) object);
+ } else if (object instanceof double[]) {
+ append((double[]) object);
+ } else if (object instanceof float[]) {
+ append((float[]) object);
+ } else if (object instanceof boolean[]) {
+ append((boolean[]) object);
+ } else {
+ // Not an array of primitives
+ append((Object[]) object);
+ }
+ }
+
+ /**
+ * hashCode
for an Object
array.
+ * hashCode
+ * @return this
+ */
+/**
+ * hashCode
for an Object
array.
+ * hashCode
+ * @return this
+ */
+public org.apache.commons.lang3.builder.HashCodeBuilder append(final java.lang.Object[] array) {
+ {
+ for (final java.lang.Object element : /* NPEX_NULL_EXP */
+ array) {
+ append(element);
+ }
+ }
+ return this;
+}
+
+ /**
+ * hashCode
for a short
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final short element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * super.hashCode()
+ * @return this HashCodeBuilder, used to chain calls.
+ * @since 2.0
+ */
+ public HashCodeBuilder appendSuper(final int superHashCode) {
+ iTotal = iTotal * iConstant + superHashCode;
+ return this;
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
based on the fields appended
+ */
+ public int toHashCode() {
+ return iTotal;
+ }
+
+ /**
+ * Returns the computed hashCode
.
+ *
+ * @return hashCode
based on the fields appended
+ *
+ * @since 3.0
+ */
+ @Override
+ public Integer build() {
+ return Integer.valueOf(toHashCode());
+ }
+
+ /**
+ * hashCode
from toHashCode() is returned due to the likelihood
+ * of bugs in mis-calling toHashCode() and the unlikeliness of it mattering what the hashCode for
+ * HashCodeBuilder itself is.hashCode
based on the fields appended
+ * @since 2.5
+ */
+ @Override
+ public int hashCode() {
+ return toHashCode();
+ }
+
+}
diff --git a/Java/commons-lang-HashCodeBuilder_900/metadata.json b/Java/commons-lang-HashCodeBuilder_900/metadata.json
new file mode 100644
index 000000000..9c7a86023
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_900/metadata.json
@@ -0,0 +1,21 @@
+{
+ "language": "java",
+ "id": "commons-lang-HashCodeBuilder_900",
+ "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/builder/HashCodeBuilder.java",
+ "line": 911,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder",
+ "repo": "commons-lang",
+ "bug_id": "HashCodeBuilder_900"
+ }
+}
diff --git a/Java/commons-lang-HashCodeBuilder_900/npe.json b/Java/commons-lang-HashCodeBuilder_900/npe.json
new file mode 100644
index 000000000..46d5d0945
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_900/npe.json
@@ -0,0 +1,7 @@
+{
+ "filepath": "src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java",
+ "line": 911,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder"
+}
\ No newline at end of file
diff --git a/Java/commons-lang-HashCodeBuilder_934/Dockerfile b/Java/commons-lang-HashCodeBuilder_934/Dockerfile
new file mode 100644
index 000000000..7b7fbe349
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_934/Dockerfile
@@ -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
diff --git a/Java/commons-lang-HashCodeBuilder_934/buggy.java b/Java/commons-lang-HashCodeBuilder_934/buggy.java
new file mode 100644
index 000000000..e22334658
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_934/buggy.java
@@ -0,0 +1,1004 @@
+/*
+ * 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.builder;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.Validate;
+
+/**
+ * hashCode
method to be built for any class. It follows the rules laid out in
+ * the book Effective Java by Joshua Bloch. Writing a
+ * good hashCode
method is actually quite difficult. This class aims to simplify the process.
+ * hashCode
method. Derived fields may be
+ * excluded. In general, any field used in the equals
method must be used in the hashCode
+ * method.
+ *
+ * public class Person {
+ * String name;
+ * int age;
+ * boolean smoker;
+ * ...
+ *
+ * public int hashCode() {
+ * // you pick a hard-coded, randomly chosen, non-zero, odd number
+ * // ideally different for each class
+ * return new HashCodeBuilder(17, 37).
+ * append(name).
+ * append(age).
+ * append(smoker).
+ * toHashCode();
+ * }
+ * }
+ *
+ *
+ * hashCode()
can be added using {@link #appendSuper}.
+ * reflectionHashCode
, uses AccessibleObject.setAccessible
+ * to change the visibility of the fields. This will fail under a security manager, unless the appropriate permissions
+ * are set up correctly. It is also slower than testing explicitly.
+ *
+ * public int hashCode() {
+ * return HashCodeBuilder.reflectionHashCode(this);
+ * }
+ *
+ *
+ * reflectionHashCode
methods.true
if the registry contains the given object. Used by the reflection methods to avoid
+ * infinite loops.
+ * true
if the registry contains the given object.
+ * @since 2.3
+ */
+ static boolean isRegistered(final Object value) {
+ final SetClass
.
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, false, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final int initialNonZeroOddNumber, final int multiplierNonZeroOddNumber, final Object object,
+ final boolean testTransients) {
+ return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @param reflectUpToClass
+ * the superclass to reflect up to (inclusive), may be null
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the Object is null
+ * @throws IllegalArgumentException
+ * if the number is zero or even
+ *
+ * @see HashCodeExclude
+ * @since 2.0
+ */
+ public static AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * true
, transient members will be tested, otherwise they
+ * are ignored, as they are likely derived fields, and not part of the value of the Object
.
+ * hashCode
for
+ * @param testTransients
+ * whether to include transient fields
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final boolean testTransients) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object,
+ testTransients, null);
+ }
+
+ /**
+ * AccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * Collection of String field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final CollectionAccessibleObject.setAccessible
to gain access to private fields. This means that it will
+ * throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
+ * also not as efficient as testing explicitly.
+ * Object
.
+ * hashCode
for
+ * @param excludeFields
+ * array of field names to exclude from use in calculation of hash code
+ * @return int hash code
+ * @throws IllegalArgumentException
+ * if the object is null
+ *
+ * @see HashCodeExclude
+ */
+ public static int reflectionHashCode(final Object object, final String... excludeFields) {
+ return reflectionHashCode(DEFAULT_INITIAL_VALUE, DEFAULT_MULTIPLIER_VALUE, object, false,
+ null, excludeFields);
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
for a boolean
.
+ * 1
when true, and 0
when false to the hashCode
.
+ * java.lang.Boolean.hashCode
handling, which computes
+ * a hashCode
value of 1231
for java.lang.Boolean
instances
+ * that represent true
or 1237
for java.lang.Boolean
instances
+ * that represent false
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean value) {
+ iTotal = iTotal * iConstant + (value ? 0 : 1);
+ return this;
+ }
+
+ /**
+ * hashCode
for a boolean
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final boolean[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final boolean element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ // -------------------------------------------------------------------------
+
+ /**
+ * hashCode
for a byte
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final byte[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final byte element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a char
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final char[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final char element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a double
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double value) {
+ return append(Double.doubleToLongBits(value));
+ }
+
+ /**
+ * hashCode
for a double
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final double[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final double element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float value) {
+ iTotal = iTotal * iConstant + Float.floatToIntBits(value);
+ return this;
+ }
+
+ /**
+ * hashCode
for a float
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final float[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final float element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for an int
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final int[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final int element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
.
+ * hashCode
+ * @return this
+ */
+ // NOTE: This method uses >> and not >>> as Effective Java and
+ // Long.hashCode do. Ideally we should switch to >>> at
+ // some stage. There are backwards compat issues, so
+ // that will have to wait for the time being. cf LANG-342.
+ public HashCodeBuilder append(final long value) {
+ iTotal = iTotal * iConstant + ((int) (value ^ (value >> 32)));
+ return this;
+ }
+
+ /**
+ * hashCode
for a long
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final long[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final long element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an Object
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object object) {
+ if (object == null) {
+ iTotal = iTotal * iConstant;
+
+ } else {
+ if (object.getClass().isArray()) {
+ // factor out array case in order to keep method small enough
+ // to be inlined
+ appendArray(object);
+ } else {
+ iTotal = iTotal * iConstant + object.hashCode();
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for an array.
+ * hashCode
+ */
+ private void appendArray(final Object object) {
+ // 'Switch' on type of array, to dispatch to the correct handler
+ // This handles multi dimensional arrays
+ if (object instanceof long[]) {
+ append((long[]) object);
+ } else if (object instanceof int[]) {
+ append((int[]) object);
+ } else if (object instanceof short[]) {
+ append((short[]) object);
+ } else if (object instanceof char[]) {
+ append((char[]) object);
+ } else if (object instanceof byte[]) {
+ append((byte[]) object);
+ } else if (object instanceof double[]) {
+ append((double[]) object);
+ } else if (object instanceof float[]) {
+ append((float[]) object);
+ } else if (object instanceof boolean[]) {
+ append((boolean[]) object);
+ } else {
+ // Not an array of primitives
+ append((Object[]) object);
+ }
+ }
+
+ /**
+ * hashCode
for an Object
array.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final Object[] array) {
+ if (array == null) {
+ iTotal = iTotal * iConstant;
+ } else {
+ for (final Object element : array) {
+ append(element);
+ }
+ }
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
.
+ * hashCode
+ * @return this
+ */
+ public HashCodeBuilder append(final short value) {
+ iTotal = iTotal * iConstant + value;
+ return this;
+ }
+
+ /**
+ * hashCode
for a short
array.
+ * hashCode
+ * @return this
+ */
+/**
+ * hashCode
for a short
array.
+ * hashCode
+ * @return this
+ */
+public org.apache.commons.lang3.builder.HashCodeBuilder append(final short[] array) {
+ {
+ for (final short element : /* NPEX_NULL_EXP */
+ array) {
+ append(element);
+ }
+ }
+ return this;
+}
+
+ /**
+ * super.hashCode()
+ * @return this HashCodeBuilder, used to chain calls.
+ * @since 2.0
+ */
+ public HashCodeBuilder appendSuper(final int superHashCode) {
+ iTotal = iTotal * iConstant + superHashCode;
+ return this;
+ }
+
+ /**
+ * hashCode
.
+ * hashCode
based on the fields appended
+ */
+ public int toHashCode() {
+ return iTotal;
+ }
+
+ /**
+ * Returns the computed hashCode
.
+ *
+ * @return hashCode
based on the fields appended
+ *
+ * @since 3.0
+ */
+ @Override
+ public Integer build() {
+ return Integer.valueOf(toHashCode());
+ }
+
+ /**
+ * hashCode
from toHashCode() is returned due to the likelihood
+ * of bugs in mis-calling toHashCode() and the unlikeliness of it mattering what the hashCode for
+ * HashCodeBuilder itself is.hashCode
based on the fields appended
+ * @since 2.5
+ */
+ @Override
+ public int hashCode() {
+ return toHashCode();
+ }
+
+}
diff --git a/Java/commons-lang-HashCodeBuilder_934/metadata.json b/Java/commons-lang-HashCodeBuilder_934/metadata.json
new file mode 100644
index 000000000..ff0c65a52
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_934/metadata.json
@@ -0,0 +1,21 @@
+{
+ "language": "java",
+ "id": "commons-lang-HashCodeBuilder_934",
+ "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/builder/HashCodeBuilder.java",
+ "line": 945,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder",
+ "repo": "commons-lang",
+ "bug_id": "HashCodeBuilder_934"
+ }
+}
diff --git a/Java/commons-lang-HashCodeBuilder_934/npe.json b/Java/commons-lang-HashCodeBuilder_934/npe.json
new file mode 100644
index 000000000..3c1e2bc30
--- /dev/null
+++ b/Java/commons-lang-HashCodeBuilder_934/npe.json
@@ -0,0 +1,7 @@
+{
+ "filepath": "src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java",
+ "line": 945,
+ "npe_method": "append",
+ "deref_field": "array",
+ "npe_class": "HashCodeBuilder"
+}
\ No newline at end of file