Skip to content

VersionedRecordExtension throws NumberFormatException for Long numbers #5715

@tcerda95

Description

@tcerda95

Describe the bug

VersionedRecordExtension uses Interger.parseInt to convert the attribute annotated with DynamoDbVersionAttribute from a String to a Integer.

This is wrong because you can annotate Longs with DynamoDbVersionAttribute. When such Long has a value that cannot be represented with an Integer, VersionedRecordExtension throws NumberFormatException.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

VersionedRecordExtension should not throw NumberFormatException for numbers that cannot be represent by an Integer such as 134117278857279131.

Current Behavior

When a Long attribute has a non-Integer representable value such as 134117278857279131L and is annotated with @DynamoDbVersionAttribute, then VersionedRecordExtension throws NumberFormatException

Reproduction Steps

@DynamoDbBean
public class Customer {
    private String id;
    private String name;
    private Long version;

    @DynamoDbPartitionKey
    public String getId() { return this.id; }

    public void setId(String id) { this.id = id; }

    public String getName() { return this.name; }

    public void setName(String name) { this.name = name; }

    @DynamoDbVersionAttribute
    public Long getVersion() { return this.version; }

    public void setVersion(Long version) { this.version = version; }
}

Customer customer = new Customer();
customer.setId("1");
customer.setName("CustomerName");
customer.setVersion(134117278857279131L);

// Throws NumberFormatException
customerTable.putItem(customer)

Possible Solution

Use Long.parseLong instead of Integer.parseInt in

Additional Information/Context

No response

AWS Java SDK version used

2.29.17

JDK version used

21.0.4

Operating System and version

MacOs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.dynamodb-enhancedp2This is a standard priority issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions