aws / aws/aws-sdk-java-v2

Enhanced client bug when dealing with kotlin nullable booleans whose names start with "is"

Open
#5,454 4 comments 0 reactions 0 assignees View on GitHub
bug kotlin p3
Dominant language
Java
Stars
2.6k
Forks
1k
Avg merge
2d 9h
Merged PRs (30d)
51

Description

### Describe the bug

When using a nullable boolean property in kotlin which is prefixed by `is`, the property is ignored by the enhanced client when building the schema, even if you add the `@DynamoDbAttribute` annotation to override the name.

### Expected Behavior

I recognize that I need to override the db field name due to the "is" prefix, but I expect a nullable boolean property to work just as well as a non-nullable rather than being ignored. I have another field in my same bean that works fine:

```
@get:DynamoDbAttribute("isDeleted")
var isDeleted: Boolean = false,
```

This property outputs logs like
some.package.model.SomeModel - Property deleted read method: public final boolean some.package.model.SomeModel.isDeleted() ||main|s.a.a.e.d.beans
some.package.model.SomeModel - Property deleted write method: public final some.package.model.SomeModel.setDeleted(boolean) ||main|s.a.a.e.d.beans

### Current Behavior

With the debug logging turned on, you get a message like this in the log:

some.package.model.SomeModel - Ignoring bean property foo because it has no read (get/is) method. ||main|s.a.a.e.d.beans

Note: If you remove the `?` and instead define the field as
`var isFoo: Boolean = false`
then the property works as expected.

### Reproduction Steps

Here's an example bean that should replicate the issue
```
@DynamoDbBean
data class SomeModel(
@get:DynamoDbPartitionKey
var id: String

@get:DynamoDbAttribute("isFoo")
var isFoo: Boolean? = false
)
```

### Possible Solution

I'm not sure what a fix might be, but I did figure out a workaround by delegating the property as follows, and marking my "real" property with `@DynamoDbIgnore`. Note the property is still nullable, but by getting rid of the "is" prefix the property plays nice with the sdk

```
@get:DynamoDbAttribute("isFoo")
var fooDelegate: Boolean?
get() = isFoo
set(ooo) { this.isFoo = ooo }
```

### Additional Information/Context

Specifically working with `software.amazon.awssdk:dynamodb-enhanced`

Kotlin version in use is 1.9.23

### AWS Java SDK version used

2.26.27 (just updated to latest to make sure it hasn't already been fixed)

### JDK version used

openjdk 17.0.11 2024-04-16 LTS

### Operating System and version

MacOS Sonoma 14.5

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.