barty/D4J-Repair huggingface dataset:
File: src/main/java/com/fasterxml/jackson/databind/ser/std/NumberSerializer.java
Issue: Regression in 2.7.0-rc2, for schema/introspection for BigDecimal
(found via Avro module, but surprisingly json schema module has not test to catch it)
Looks like schema type for BigDecimal is not correctly produced, due to an error in refactoring (made to simplify introspection for simple serializers): it is seen as BigInteger (and for Avro, for example, results in long getting written).

Buggy code:
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
{
    if (_isInt) {
        visitIntFormat(visitor, typeHint, JsonParser.NumberType.BIG_INTEGER);
    } else {
        Class<?> h = handledType();
        if (h == BigDecimal.class) {
            visitFloatFormat(visitor, typeHint, JsonParser.NumberType.BIG_INTEGER);
        } else {
            // otherwise bit unclear what to call... but let's try:
            /*JsonNumberFormatVisitor v2 =*/ visitor.expectNumberFormat(typeHint);
        }
    }
}

Fixed code:
public void acceptJsonFormatVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint) throws JsonMappingException
{
    if (_isInt) {
        visitIntFormat(visitor, typeHint, JsonParser.NumberType.BIG_INTEGER);
    } else {
        Class<?> h = handledType();
        if (h == BigDecimal.class) {
            visitFloatFormat(visitor, typeHint, JsonParser.NumberType.BIG_DECIMAL);
        } else {
            // otherwise bit unclear what to call... but let's try:
            /*JsonNumberFormatVisitor v2 =*/ visitor.expectNumberFormat(typeHint);
        }
    }
}
File: src/main/java/com/fasterxml/jackson/databind/util/StdDateFormat.java
Issue: Allow use	of `StdDateFormat.setLenient()`
ObjectMapper uses the StdDateFormat for date serialization. Jackson date parsing is lenient by default, so 2015-01-32 gets parsed as 2015-02-01.  Jackson’s StdDateParser is matching default behavior of DateParser.  

StdDateParser wasn’t really designed for extension to just enable strict date parsing.  If it were, we could just call objectMapper.setDateFormat(new StdDateFormat().setLenient(false)). But StdDateFomrat doesn't support setting lenient to false. And i.e. the reason date like 2015-01-32 gets parsed as 2015-02-01 ad Jackson date parsing is lenient by defualt.

Can StdDateFormat can be enhanced to support to non lenient date parsing?


Buggy code:
private final static DateFormat _cloneFormat(DateFormat df, String format,
            TimeZone tz, Locale loc, Boolean lenient)
    {
        if (!loc.equals(DEFAULT_LOCALE)) {
            df = new SimpleDateFormat(format, loc);
            df.setTimeZone((tz == null) ? DEFAULT_TIMEZONE : tz);
        } else {
            df = (DateFormat) df.clone();
            if (tz != null) {
                df.setTimeZone(tz);
            }
        }
        return df;
    }

Fixed code:
private final static DateFormat _cloneFormat(DateFormat df, String format,
            TimeZone tz, Locale loc, Boolean lenient)
    {
        if (!loc.equals(DEFAULT_LOCALE)) {
            df = new SimpleDateFormat(format, loc);
            df.setTimeZone((tz == null) ? DEFAULT_TIMEZONE : tz);
        } else {
            df = (DateFormat) df.clone();
            if (tz != null) {
                df.setTimeZone(tz);
            }
        }
        if (lenient != null) {
            df.setLenient(lenient.booleanValue());
        }
        return df;
    }
File: src/main/java/com/fasterxml/jackson/databind/deser/std/FromStringDeserializer.java
Issue: Serializing and Deserializing Locale.ROOT
Serializing and Deserializing Locale objects seems to work just fine, until you try on the Root Locale.
It writes it out as an empty string and when it reads it in, the value is null
@Test
    public void testLocaleDeserialization() throws IOException {
        ObjectMapper objectMapper = new ObjectMapper();
        Locale root = Locale.ROOT;
        String json = objectMapper.writeValueAsString(root);
        System.out.printf("Root Locale: '%s'", json);
        Locale actual = objectMapper.readValue(json, Locale.class);
        Assert.assertEquals(root, actual);
    }

Here is the output:
Root Locale: '""'
java.lang.AssertionError:
Expected :
Actual   :null

Buggy code:
protected Object _deserializeFromEmptyString() throws IOException {
    // As per [databind#398], URI requires special handling
    if (_kind == STD_URI) {
        return URI.create("");
    }
    // As per [databind#1123], Locale too
    return super._deserializeFromEmptyString();
}

Fixed code:
protected Object _deserializeFromEmptyString() throws IOException {
    // As per [databind#398], URI requires special handling
    if (_kind == STD_URI) {
        return URI.create("");
    }
    // As per [databind#1123], Locale too
    if (_kind == STD_LOCALE) {
        return Locale.ROOT;
    }
    return super._deserializeFromEmptyString();
}
File: src/main/java/com/fasterxml/jackson/databind/deser/impl/ObjectIdValueProperty.java
Issue: Problem with Object id handling, explicit `null` token
According to #742, it shouldn't throw an exception if the value of the property is null


Buggy code:
@Override
    public Object deserializeSetAndReturn(JsonParser p,
    		DeserializationContext ctxt, Object instance) throws IOException
    {
        Object id = _valueDeserializer.deserialize(p, ctxt);
        /* 02-Apr-2015, tatu: Actually, as per [databind#742], let it be;
         *  missing or null id is needed for some cases, such as cases where id
         *  will be generated externally, at a later point, and is not available
         *  quite yet. Typical use case is with DB inserts.
         */
        // note: no null checks (unlike usually); deserializer should fail if one found
        if (id == null) {
            return null;
        }
        ReadableObjectId roid = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver);
        roid.bindItem(instance);
        // also: may need to set a property value as well
        SettableBeanProperty idProp = _objectIdReader.idProperty;
        if (idProp != null) {
            return idProp.setAndReturn(instance, id);
        }
        return instance;
    }

Fixed code:
@Override
    public Object deserializeSetAndReturn(JsonParser p,
    		DeserializationContext ctxt, Object instance) throws IOException
    {
        /* 02-Apr-2015, tatu: Actually, as per [databind#742], let it be;
         *  missing or null id is needed for some cases, such as cases where id
         *  will be generated externally, at a later point, and is not available
         *  quite yet. Typical use case is with DB inserts.
         */
        // note: no null checks (unlike usually); deserializer should fail if one found
        if (p.hasToken(JsonToken.VALUE_NULL)) {
            return null;
        }
        Object id = _valueDeserializer.deserialize(p, ctxt);
        ReadableObjectId roid = ctxt.findObjectId(id, _objectIdReader.generator, _objectIdReader.resolver);
        roid.bindItem(instance);
        // also: may need to set a property value as well
        SettableBeanProperty idProp = _objectIdReader.idProperty;
        if (idProp != null) {
            return idProp.setAndReturn(instance, id);
        }
        return instance;
    }
File: src/main/java/com/fasterxml/jackson/databind/type/ReferenceType.java
Issue: Incorrect signature for generic type via `JavaType.getGenericSignature
(see FasterXML/jackson-modules-base#8 for background)
It looks like generic signature generation is missing one closing > character to produce:
()Ljava/util/concurrent/atomic/AtomicReference<Ljava/lang/String;;

instead of expected
()Ljava/util/concurrent/atomic/AtomicReference<Ljava/lang/String;>;

that is, closing '>' is missing.

Buggy code:
public StringBuilder getGenericSignature(StringBuilder sb)
{
    _classSignature(_class, sb, false);
    sb.append('<');
    sb = _referencedType.getGenericSignature(sb);
    sb.append(';');
    return sb;
}

Fixed code:
public StringBuilder getGenericSignature(StringBuilder sb)
{
    _classSignature(_class, sb, false);
    sb.append('<');
    sb = _referencedType.getGenericSignature(sb);
    sb.append(">;");
    return sb;
}
File: src/main/java/com/fasterxml/jackson/databind/ser/impl/WritableObjectId.java
Issue: JsonIdentityInfo incorrectly serializing forward references
I wrote this small test program to demonstrate the issue:
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.fasterxml.jackson.databind.ObjectMapper;

public class ObjectIdTest {

    public static class Foo {

        @JsonIdentityReference(alwaysAsId = true)
        public Bar bar1;

        @JsonIdentityReference()
        public Bar bar2;
    }

    @JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class)
    public static class Bar {

    }

    public static void main(String[] args) throws Exception {
        ObjectMapper mapper = new ObjectMapper();

        // create structure to serialize
        Foo mo = new Foo();
        mo.bar1 = new Bar();
        mo.bar2 = mo.bar1;

        // serialize it
        System.out.println(mapper.writeValueAsString(mo));
    }

}
When executing this test program in the latest version (2.7.4), the output will be {"bar1":1,"bar2":{"@id":2}} - the second field will be written with a new id even though both fields reference the same object. Because of this, writing forward references is essentially impossible.
The issue seems to be the fact that BeanSerializerBase will always call WritableObjectId.generateId if the referenced object has not been written in plain format yet (https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/ser/std/BeanSerializerBase.java#L600). This will also happen if an id has been generated before.
It might also be smarter to only generate a new id in WritableObjectId.generateId if that hasn't happened before; as that method doesn't have a javadoc I can't tell how it is supposed to work.

Buggy code:
public Object generateId(Object forPojo) {
    // 04-Jun-2016, tatu: As per [databind#1255], need to consider possibility of
    //    id being generated for "alwaysAsId", but not being written as POJO; regardless,
    //    need to use existing id if there is one:
        id = generator.generateId(forPojo);
    return id;
}

Fixed code:
public Object generateId(Object forPojo) {
    // 04-Jun-2016, tatu: As per [databind#1255], need to consider possibility of
    //    id being generated for "alwaysAsId", but not being written as POJO; regardless,
    //    need to use existing id if there is one:
    if (id == null) {
        id = generator.generateId(forPojo);
    }
    return id;
}
File: src/main/java/com/fasterxml/jackson/databind/ser/std/StdKeySerializers.java
Issue: EnumMap keys not using enum's `@JsonProperty` values unlike Enum values
Based on these issues:
https://github.com/FasterXML/jackson-databind/issues/677
https://github.com/FasterXML/jackson-databind/issues/1148
https://github.com/FasterXML/jackson-annotations/issues/96

I implemented @JsonProperty for my enum constants and they show up nicely when they are property values. But I also have an EnumMap which uses the enum, and it's generated JSON uses the original enum names for the keys and not the JsonProperty values.

Using 2.8.1 (in spring boot 4.3.2)

Thanks!


Buggy code:
@SuppressWarnings("unchecked")
    public static JsonSerializer<Object> getFallbackKeySerializer(SerializationConfig config,
            Class<?> rawKeyType)
    {
        if (rawKeyType != null) {
            // 29-Sep-2015, tatu: Odd case here, of `Enum`, which we may get for `EnumMap`; not sure
            //   if that is a bug or feature. Regardless, it seems to require dynamic handling
            //   (compared to getting actual fully typed Enum).
            //  Note that this might even work from the earlier point, but let's play it safe for now
            // 11-Aug-2016, tatu: Turns out we get this if `EnumMap` is the root value because
            //    then there is no static type
            if (rawKeyType == Enum.class) {
                return new Dynamic();
            }
            if (rawKeyType.isEnum()) {
                return new Default(Default.TYPE_ENUM, rawKeyType);
            }
        }
        return DEFAULT_KEY_SERIALIZER;
    }

Fixed code:
@SuppressWarnings("unchecked")
    public static JsonSerializer<Object> getFallbackKeySerializer(SerializationConfig config,
            Class<?> rawKeyType)
    {
        if (rawKeyType != null) {
            // 29-Sep-2015, tatu: Odd case here, of `Enum`, which we may get for `EnumMap`; not sure
            //   if that is a bug or feature. Regardless, it seems to require dynamic handling
            //   (compared to getting actual fully typed Enum).
            //  Note that this might even work from the earlier point, but let's play it safe for now
            // 11-Aug-2016, tatu: Turns out we get this if `EnumMap` is the root value because
            //    then there is no static type
            if (rawKeyType == Enum.class) {
                return new Dynamic();
            }
            if (rawKeyType.isEnum()) {
                return EnumKeySerializer.construct(rawKeyType,
                        EnumValues.constructFromName(config, (Class<Enum<?>>) rawKeyType));
            }
        }
        return DEFAULT_KEY_SERIALIZER;
    }
File: src/main/java/com/fasterxml/jackson/databind/ObjectReader.java
Issue: ObjectReader.readValues() ignores offset and length when reading an array
ObjectReader.readValues ignores offset and length when reading an array. If _dataFormatReaders it will always use the full array:
https://github.com/FasterXML/jackson-databind/blob/2.7/src/main/java/com/fasterxml/jackson/databind/ObjectReader.java#L1435

Buggy code:
public <T> MappingIterator<T> readValues(byte[] src, int offset, int length)
    throws IOException, JsonProcessingException
{
    if (_dataFormatReaders != null) {
        return _detectBindAndReadValues(_dataFormatReaders.findFormat(src, offset, length), false);
    }
    return _bindAndReadValues(_considerFilter(_parserFactory.createParser(src), 
            true));
}

Fixed code:
public <T> MappingIterator<T> readValues(byte[] src, int offset, int length)
    throws IOException, JsonProcessingException
{
    if (_dataFormatReaders != null) {
        return _detectBindAndReadValues(_dataFormatReaders.findFormat(src, offset, length), false);
    }
    return _bindAndReadValues(_considerFilter(_parserFactory.createParser(src, offset, length),
            true));
}
File: src/main/java/com/fasterxml/jackson/databind/util/TokenBuffer.java
Issue: Possibly wrong TokenBuffer delegate deserialization using @JsonCreator
class Value {
@JsonCreator
public static Value from(TokenBuffer buffer) {
...
}
Given JSON string is  { "a":1, "b":null }, it is expected that while deserializing using delegate buffer,
current token will be start object {, and rest of the tokens will be available in buffer:
[START_OBJECT, FIELD_NAME, VALUE_NUMBER_INT, FIELD_NAME, VALUE_NULL, END_OBJECT]

But, buffers ends up being started with field name and then contains single attribute value
[FIELD_NAME, VALUE_NUMBER_INT]

It's due to how TokenBuffer#copyCurrentStructure works when we have current token as a FIELD_NAME, rather than START_OBJECT, because it's forced to move to next token BeanDeserializer.java:120
Hope this helps to nail it down. Is it an intended behavior, or it's regression/bug?

Buggy code:
public TokenBuffer deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
        copyCurrentStructure(jp);
    /* 28-Oct-2014, tatu: As per #592, need to support a special case of starting from
     *    FIELD_NAME, which is taken to mean that we are missing START_OBJECT, but need
     *    to assume one did exist.
     */
    return this;
}

Fixed code:
public TokenBuffer deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException
{
    if (jp.getCurrentTokenId() != JsonToken.FIELD_NAME.id()) {
        copyCurrentStructure(jp);
        return this;
    }
    /* 28-Oct-2014, tatu: As per #592, need to support a special case of starting from
     *    FIELD_NAME, which is taken to mean that we are missing START_OBJECT, but need
     *    to assume one did exist.
     */
    JsonToken t;
    writeStartObject();
    do {
        copyCurrentStructure(jp);
    } while ((t = jp.nextToken()) == JsonToken.FIELD_NAME);
    if (t != JsonToken.END_OBJECT) {
        throw ctxt.mappingException("Expected END_OBJECT after copying contents of a JsonParser into TokenBuffer, got "+t);
    }
    writeEndObject();
    return this;
}
File: src/main/java/com/fasterxml/jackson/databind/deser/impl/BeanPropertyMap.java
Issue: ACCEPT_CASE_INSENSITIVE_PROPERTIES fails with @JsonUnwrapped
(note: moved from FasterXML/jackson-dataformat-csv#133)
When trying to deserialize type like:
public class Person {
  @JsonUnwrapped(prefix = "businessAddress.")
  public Address businessAddress;
}

public class Address {
  public String street;
  public String addon;
  public String zip = "";
  public String town;    
  public String country;
}
with case-insensitive mapper (mapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES);) I get exception:
java.util.NoSuchElementException: No entry 'businessAddress' found, can't remove
	at com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap.remove(BeanPropertyMap.java:447)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.resolve(BeanDeserializerBase.java:534)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:293)
   ...

Buggy code:
public void remove(SettableBeanProperty propToRm)
{
    ArrayList<SettableBeanProperty> props = new ArrayList<SettableBeanProperty>(_size);
    String key = getPropertyName(propToRm);
    boolean found = false;

    for (int i = 1, end = _hashArea.length; i < end; i += 2) {
        SettableBeanProperty prop = (SettableBeanProperty) _hashArea[i];
        if (prop == null) {
            continue;
        }
        if (!found) {
            // 09-Jan-2017, tatu: Important: must check name slot and NOT property name,
            //   as only former is lower-case in case-insensitive case
            found = key.equals(prop.getName());
            if (found) {
                // need to leave a hole here
                _propsInOrder[_findFromOrdered(prop)] = null;
                continue;
            }
        }
        props.add(prop);
    }
    if (!found) {
        throw new NoSuchElementException("No entry '"+propToRm.getName()+"' found, can't remove");
    }
    init(props);
}

Fixed code:
public void remove(SettableBeanProperty propToRm)
{
    ArrayList<SettableBeanProperty> props = new ArrayList<SettableBeanProperty>(_size);
    String key = getPropertyName(propToRm);
    boolean found = false;

    for (int i = 1, end = _hashArea.length; i < end; i += 2) {
        SettableBeanProperty prop = (SettableBeanProperty) _hashArea[i];
        if (prop == null) {
            continue;
        }
        if (!found) {
            // 09-Jan-2017, tatu: Important: must check name slot and NOT property name,
            //   as only former is lower-case in case-insensitive case
            found = key.equals(_hashArea[i-1]);
            if (found) {
                // need to leave a hole here
                _propsInOrder[_findFromOrdered(prop)] = null;
                continue;
            }
        }
        props.add(prop);
    }
    if (!found) {
        throw new NoSuchElementException("No entry '"+propToRm.getName()+"' found, can't remove");
    }
    init(props);
}
File: src/main/java/com/fasterxml/jackson/databind/jsontype/impl/AsPropertyTypeDeserializer.java
Issue: AsPropertyTypeDeserializer ignores DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT
The AsPropertyTypeDeserializer  implementation does not respect the DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT feature. When deserializing an empty String it throws DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT instead of creating a null Object.

Buggy code:
protected Object _deserializeTypedUsingDefaultImpl(JsonParser p, DeserializationContext ctxt,
        TokenBuffer tb) throws IOException
{
    // As per [JACKSON-614], may have default implementation to use
    JsonDeserializer<Object> deser = _findDefaultImplDeserializer(ctxt);
    if (deser != null) {
        if (tb != null) {
            tb.writeEndObject();
            p = tb.asParser(p);
            // must move to point to the first token:
            p.nextToken();
        }
        return deser.deserialize(p, ctxt);
    }
    // or, perhaps we just bumped into a "natural" value (boolean/int/double/String)?
    Object result = TypeDeserializer.deserializeIfNatural(p, ctxt, _baseType);
    if (result != null) {
        return result;
    }
    // or, something for which "as-property" won't work, changed into "wrapper-array" type:
    if (p.getCurrentToken() == JsonToken.START_ARRAY) {
        return super.deserializeTypedFromAny(p, ctxt);
    }
    ctxt.reportWrongTokenException(p, JsonToken.FIELD_NAME,
            "missing property '"+_typePropertyName+"' that is to contain type id  (for class "+baseTypeName()+")");
    return null;
}

Fixed code:
protected Object _deserializeTypedUsingDefaultImpl(JsonParser p, DeserializationContext ctxt,
        TokenBuffer tb) throws IOException
{
    // As per [JACKSON-614], may have default implementation to use
    JsonDeserializer<Object> deser = _findDefaultImplDeserializer(ctxt);
    if (deser != null) {
        if (tb != null) {
            tb.writeEndObject();
            p = tb.asParser(p);
            // must move to point to the first token:
            p.nextToken();
        }
        return deser.deserialize(p, ctxt);
    }
    // or, perhaps we just bumped into a "natural" value (boolean/int/double/String)?
    Object result = TypeDeserializer.deserializeIfNatural(p, ctxt, _baseType);
    if (result != null) {
        return result;
    }
    // or, something for which "as-property" won't work, changed into "wrapper-array" type:
    if (p.getCurrentToken() == JsonToken.START_ARRAY) {
        return super.deserializeTypedFromAny(p, ctxt);
    } else if (p.getCurrentToken() == JsonToken.VALUE_STRING) {
        if (ctxt.isEnabled(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT)) {
            String str = p.getText().trim();
            if (str.isEmpty()) {
                return null;
            }
        }
    }
    ctxt.reportWrongTokenException(p, JsonToken.FIELD_NAME,
            "missing property '"+_typePropertyName+"' that is to contain type id  (for class "+baseTypeName()+")");
    return null;
}
File: src/main/java/com/fasterxml/jackson/databind/type/ReferenceType.java
Issue: Canonical string for reference type is built incorrectly
Canonical string for reference type is built incorrectly.
E.g.:
new ReferenceType(new TypeFactory(new LRUMap<Object, JavaType>(0, 10000)).constructType(Object.class), new PlaceholderForType(0)).toCanonical()
yields:
java.lang.Object<$1
while the expected value is:
java.lang.Object<$1>

Buggy code:
protected String buildCanonicalName()
{
    StringBuilder sb = new StringBuilder();
    sb.append(_class.getName());
    sb.append('<');
    sb.append(_referencedType.toCanonical());
    return sb.toString();
}

Fixed code:
protected String buildCanonicalName()
{
    StringBuilder sb = new StringBuilder();
    sb.append(_class.getName());
    sb.append('<');
    sb.append(_referencedType.toCanonical());
    sb.append('>');
    return sb.toString();
}