aws / aws/aws-sdk-java-v2

TableSchema.fromImmutableClass() introspection fails when the item class has fields starting with "is"

Offen
#4,446 6 Kommentare 4 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug dynamodb-enhanced p2
Vorherrschende Sprache
Java
Sterne
2.6k
Forks
1k
Ø Merge
2 T. 9 Std.
Gemergte PRs (30 T.)
51

Beschreibung

### Describe the bug

When an immutable item class has fields that begin with "is" (e.g., "isComplete" or "isIncluded"), `TableSchema.fromImmutableClass()` throws an `ExceptionInInitializerError`. Also in stack traces this appears: `Caused by: java.lang.IllegalArgumentException: A method was found on the immutable class that does not appear to have a matching setter on the builder class. Use the @DynamoDbIgnore annotation on the method if you do not want it to be included in the TableSchema introspection`, despite no methods except getters being present in the item class, and a setter for the field actually being present for the corresponding builder class.

The `TableSchema.fromImmutableClass()` method needs to work for item class fields no matter the composition of their names. Or, the documentation needs to be updated with correct restrictions on field naming based on the behavior of [`ImmutableInstrospector`](https://github.com/aws/aws-sdk-java-v2/blob/584ccb59e770177aeaa4c3b6bda4e24015b8ece9/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/immutable/ImmutableIntrospector.java).

### Expected Behavior

TableSchema.fromImmutableClass(itemClass) should return a proper `DynamoDbTable` when called on an itemClass containing any field name, without restriction.

### Current Behavior

Errors were thrown (see description).

### Reproduction Steps

```
@DynamoDbImmutable(builder = Car.Builder.class)
public final class Car {
private final String licensePlate;
private final boolean isRusty;
private final boolean isImpounded;

private Car(final Builder b) {
this.licensePlate = b.licensePlate;
this.isRusty = b.isRusty;
this.isImpounded = b.isImpounded;
}

public static Builder builder() {
return new Builder();
}

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

public boolean isRusty() {
return this.isRusty;
}

public boolean isImpounded() {
return this.isImpounded;
}

public static final class Builder {
private String licensePlate;
private boolean isRusty;
private boolean isImpounded;

private Builder() {
}

public Builder licensePlate(final String licensePlate) {
this.licensePlate = licensePlate;
return this;
}

public Builder isRusty(final boolean isRusty) {
this.isRusty = isRusty;
return this;
}

public Builder isImpounded(final boolean isImpounded) {
this.isImpounded = isImpounded;
return this;
}

public Car build() {
return new Car(this);
}
}
}
```

Calling `TableSchema.fromImmutableClass(Car.class)` and subsequently calling table operations on the resulting table will result in errors described above.

### Possible Solution

The behavior of the [ImmutableIntrospector](https://github.com/aws/aws-sdk-java-v2/blob/584ccb59e770177aeaa4c3b6bda4e24015b8ece9/services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/immutable/ImmutableIntrospector.java) and how it parses method names is likely at large.

### Additional Information/Context

_No response_

### AWS Java SDK version used

2.20

### JDK version used

openjdk version "17.0.8" 2023-07-18 LTS OpenJDK Runtime Environment Corretto-17.0.8.7.1 (build 17.0.8+7-LTS) OpenJDK 64-Bit Server VM Corretto-17.0.8.7.1 (build 17.0.8+7-LTS, mixed mode, sharing)

### Operating System and version

MacOS, Amazon Linux 2

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginnen Sie damit, das Car-Beispiel mit TableSchema.fromImmutableClass() nachzustellen. Untersuchen Sie anschließend services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/internal/immutable/ImmutableIntrospector.java und wie die Getter-Namen analysiert werden. Als abgeschlossen gilt die Aufgabe, wenn eine immutable Item-Klasse mit Feldern, die mit "is" beginnen, ein gültiges Tabellenschema erzeugt und Tabellenoperationen nicht mehr die gemeldeten Introspektionsfehler auslösen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
databases
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
48/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.