Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VersionedRecordExtension throws NumberFormatException for Long numbers #5715

Open
1 task
tcerda95 opened this issue Nov 20, 2024 · 2 comments
Open
1 task
Assignees
Labels
bug This issue is a bug. dynamodb-enhanced p2 This is a standard priority issue

Comments

@tcerda95
Copy link

tcerda95 commented Nov 20, 2024

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

@tcerda95 tcerda95 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 20, 2024
@debora-ito
Copy link
Member

@tcerda95 I see the issue, thank you for the report.

The fix will not be the simple one line change, I tested setting the value to 2147483647 (which is the Integer.MAX_VALUE) and the Enhanced Client will not update to 2147483647 + 1, it actually overflows to -2147483648, indicating that Long is not supported. The VersionAttribute write logic would need to change too, if we decide to support Long.

I'll discuss this case with the team, and will update here what we decide.

@debora-ito debora-ito added needs-review This issue or PR needs review from the team. p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Nov 23, 2024
@debora-ito debora-ito self-assigned this Nov 23, 2024
@debora-ito
Copy link
Member

We are going to fix the support for Long attributes.

@debora-ito debora-ito removed the needs-review This issue or PR needs review from the team. label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. dynamodb-enhanced p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

2 participants