From f6999420d0d626b716abfc1e2e629a755997953b Mon Sep 17 00:00:00 2001 From: muzarski Date: Thu, 26 Oct 2023 15:27:30 +0200 Subject: [PATCH] mapper-processor: record annotation warning fix Java duplicates the annotation on the record's field to the corresponding getter method as well. This results in generating the warning when using records and exclusive field annotations. This commit fixes the issue, so the compilation warning message is not printed for records. --- .../mapper/processor/entity/DefaultEntityFactory.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mapper-processor/src/main/java/com/datastax/oss/driver/internal/mapper/processor/entity/DefaultEntityFactory.java b/mapper-processor/src/main/java/com/datastax/oss/driver/internal/mapper/processor/entity/DefaultEntityFactory.java index 6e5a9ac6488..179b9841134 100644 --- a/mapper-processor/src/main/java/com/datastax/oss/driver/internal/mapper/processor/entity/DefaultEntityFactory.java +++ b/mapper-processor/src/main/java/com/datastax/oss/driver/internal/mapper/processor/entity/DefaultEntityFactory.java @@ -510,7 +510,10 @@ private Optional getPropertyStrategy(Set typeHier private void reportMultipleAnnotationError( Element element, Class a0, Class a1) { - if (a0 == a1) { + // A hack to prevent displaying warning messages when annotating record's fields. + // See: https://github.com/scylladb/java-driver/issues/246 + boolean isParentRecord = element.getEnclosingElement().getKind().name().equals("RECORD"); + if (a0 == a1 && !isParentRecord) { context .getMessager() .warn( @@ -518,7 +521,7 @@ private void reportMultipleAnnotationError( "@%s should be used either on the field or the getter, but not both. " + "The annotation on this field will be ignored.", a0.getSimpleName()); - } else { + } else if (a0 != a1) { context .getMessager() .error(