From bd77084927130ddd027c28ed05d31df09061b081 Mon Sep 17 00:00:00 2001 From: Philipp Sigloch Date: Tue, 16 Jul 2024 16:10:36 +0200 Subject: [PATCH 1/2] corrects @Nullable and @Nonnull annotations on created ivos and events --- .../src/main/resources/event/event.vm | 28 +++++++++++++------ .../src/main/resources/ivo/delete.vm | 4 +++ .../src/main/resources/ivo/find.vm | 9 ++++-- .../src/main/resources/ivo/findById.vm | 6 ++++ .../src/main/resources/ivo/findByIdAudited.vm | 5 ++-- .../src/main/resources/ivo/ivo.vm | 28 +++++++++++++------ .../src/main/resources/ivo/modify.vm | 3 ++ 7 files changed, 62 insertions(+), 21 deletions(-) diff --git a/interconnect/interconnect-maven-plugin/src/main/resources/event/event.vm b/interconnect/interconnect-maven-plugin/src/main/resources/event/event.vm index 17dfe4eb..306c36c1 100644 --- a/interconnect/interconnect-maven-plugin/src/main/resources/event/event.vm +++ b/interconnect/interconnect-maven-plugin/src/main/resources/event/event.vm @@ -57,13 +57,9 @@ public class $model.getClazzName() extends $model.getParentClazzName() implement * @return the builder * **/ - #if ( $field.required ) @Nonnull - #else - @Nullable - #end @SuppressWarnings("unchecked") - public E with$tool.upperCaseFirst( $field.name )($field.getTypeAsString(false) p$field.name) { + public E with$tool.upperCaseFirst( $field.name )(#if ( $field.required )@Nonnull#else@Nullable#end $field.getTypeAsString(false) p$field.name) { this.$field.name = p$field.name; return (E) this; } @@ -92,6 +88,7 @@ public class $model.getClazzName() extends $model.getParentClazzName() implement #if ( $model.hasParentClazz() ) @Override #end + @Nonnull public $model.getClazzName() build() { #foreach ( $field in $model.getAllFields() ) #if ( $field.required ) @@ -121,6 +118,11 @@ public class $model.getClazzName() extends $model.getParentClazzName() implement #if ( $field.jsonTransientFlag ) @JsonIgnore #end + #if ( $field.required ) + @Nonnull + #else + @Nullable + #end @Override public $field.getTypeAsString( false ) get$tool.upperCaseFirst( $field.name )() { return this.$field.name; @@ -131,6 +133,11 @@ public class $model.getClazzName() extends $model.getParentClazzName() implement #if ( $field.jsonTransientFlag ) @JsonIgnore #end + #if ( $field.required ) + @Nonnull + #else + @Nullable + #end @Override public $field.getTypeAsString( false ) get$tool.upperCaseFirst( $field.name )() { #if( $field.collectionType == "List" ) @@ -145,6 +152,11 @@ public class $model.getClazzName() extends $model.getParentClazzName() implement #if ( $field.jsonTransientFlag ) @JsonIgnore #end + #if ( $field.required ) + @Nonnull + #else + @Nullable + #end @Override public $field.getTypeAsString( false ) get$tool.upperCaseFirst( $field.name )() { #if( $field.mapType == "Map" ) @@ -158,8 +170,8 @@ public class $model.getClazzName() extends $model.getParentClazzName() implement @SuppressWarnings("unchecked") @Override - public - T createBuilder() { + @Nonnull + public T createBuilder() { ${model.getClazzName()}Builder builder = new ${model.getClazzName()}Builder(); builder.internalFillFromIVO(this); return (T) builder; @@ -176,4 +188,4 @@ public class $model.getClazzName() extends $model.getParentClazzName() implement #parse($addition) #end -} +} \ No newline at end of file diff --git a/interconnect/interconnect-maven-plugin/src/main/resources/ivo/delete.vm b/interconnect/interconnect-maven-plugin/src/main/resources/ivo/delete.vm index d850c931..c97bf063 100644 --- a/interconnect/interconnect-maven-plugin/src/main/resources/ivo/delete.vm +++ b/interconnect/interconnect-maven-plugin/src/main/resources/ivo/delete.vm @@ -154,6 +154,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz /** * @return the entry **/ + @Nonnull public ${clazzName} build() { if (this.ids == null) { throw new IllegalStateException("The attribute ids must not be null!"); @@ -170,6 +171,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz } @Override + @Nonnull public List getIds() { return this.ids.stream().map(iv->iv.getId()).collect(Collectors.toList()); } @@ -180,6 +182,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz } @Override + @Nonnull public List getIdsWithVersion() { return new ArrayList<>(this.ids); } @@ -191,6 +194,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz @SuppressWarnings("unchecked") @Override + @Nonnull public T createBuilder() { ${clazzName}Builder builder = new ${clazzName}Builder(); builder.internalFillFromIVO(this); diff --git a/interconnect/interconnect-maven-plugin/src/main/resources/ivo/find.vm b/interconnect/interconnect-maven-plugin/src/main/resources/ivo/find.vm index d5ad2b77..c1808327 100644 --- a/interconnect/interconnect-maven-plugin/src/main/resources/ivo/find.vm +++ b/interconnect/interconnect-maven-plugin/src/main/resources/ivo/find.vm @@ -56,9 +56,9 @@ public class ${clazzName} extends ${model.getParentClazzName()} implements I${cl * @return the builder $field.filterable * **/ - @Nullable + @Nonnull #if ($field.filterable == 'single') - public E with$tool.upperCaseFirst( $field.name )($field.getTypeAsString(false) p$field.name) { + public E with$tool.upperCaseFirst( $field.name )(@Nullable $field.getTypeAsString(false) p$field.name) { this.$field.name = p$field.name; return (E) this; } @@ -71,7 +71,7 @@ public class ${clazzName} extends ${model.getParentClazzName()} implements I${cl return this.$field.name; } #else - public E with$tool.upperCaseFirst( $field.name )(Set<$field.getTypeAsString(true)> p$field.name) { + public E with$tool.upperCaseFirst( $field.name )(@Nullable Set<$field.getTypeAsString(true)> p$field.name) { this.$field.name = p$field.name; return (E) this; } @@ -95,6 +95,7 @@ public class ${clazzName} extends ${model.getParentClazzName()} implements I${cl /** * @return the entry **/ + @Nonnull public ${clazzName} build() { ${clazzName} result = new ${clazzName}(this); return result; @@ -138,12 +139,14 @@ public class ${clazzName} extends ${model.getParentClazzName()} implements I${cl @SuppressWarnings("unchecked") @Override + @Nonnull public IPageableBuilder createPageableBuilder() { return (IPageableBuilder) createBuilder(); } @SuppressWarnings("unchecked") @Override + @Nonnull public T createBuilder() { ${clazzName}Builder builder = new ${clazzName}Builder(); builder.internalFillFromIVO(this); diff --git a/interconnect/interconnect-maven-plugin/src/main/resources/ivo/findById.vm b/interconnect/interconnect-maven-plugin/src/main/resources/ivo/findById.vm index 75854aa8..372a3c97 100644 --- a/interconnect/interconnect-maven-plugin/src/main/resources/ivo/findById.vm +++ b/interconnect/interconnect-maven-plugin/src/main/resources/ivo/findById.vm @@ -145,6 +145,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz /** * @return the ids **/ + @Nonnull @JsonIgnore public List getIds() { return this.ids.stream().map(iv->iv.getId()).collect(Collectors.toList()); @@ -153,6 +154,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz /** * @return the ids **/ + @Nonnull @JsonIgnore public List getIdsWithVersion() { return new ArrayList<>(this.ids); @@ -165,6 +167,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz /** * @return the entry **/ + @Nonnull public ${clazzName} build() { if (this.ids == null) { throw new IllegalStateException("The attribute ids must not be null!"); @@ -182,6 +185,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz @Override @JsonIgnore + @Nonnull public List getIds() { return this.ids.stream().map(iv->iv.getId()).collect(Collectors.toList()); } @@ -194,6 +198,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz @Override @JsonProperty("ids") + @Nonnull public List getIdsWithVersion() { return new ArrayList<>(this.ids); } @@ -206,6 +211,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz @SuppressWarnings("unchecked") @Override + @Nonnull public T createBuilder() { ${clazzName}Builder builder = new ${clazzName}Builder(); builder.internalFillFromIVO(this); diff --git a/interconnect/interconnect-maven-plugin/src/main/resources/ivo/findByIdAudited.vm b/interconnect/interconnect-maven-plugin/src/main/resources/ivo/findByIdAudited.vm index e7fcac1b..c2e2f235 100644 --- a/interconnect/interconnect-maven-plugin/src/main/resources/ivo/findByIdAudited.vm +++ b/interconnect/interconnect-maven-plugin/src/main/resources/ivo/findByIdAudited.vm @@ -71,8 +71,8 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz * @return the builder $field.filterable * **/ - @Nullable - public E with$tool.upperCaseFirst( $field.name )($field.getTypeAsString(false) p$field.name) { + @Nonnull + public E with$tool.upperCaseFirst( $field.name )(@Nullable $field.getTypeAsString(false) p$field.name) { this.$field.name = p$field.name; return (E) this; } @@ -95,6 +95,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz /** * @return the entry **/ + @Nonnull public ${clazzName} build() { if (this.id == null) { throw new IllegalStateException("The attribute id must not be null!"); diff --git a/interconnect/interconnect-maven-plugin/src/main/resources/ivo/ivo.vm b/interconnect/interconnect-maven-plugin/src/main/resources/ivo/ivo.vm index 8e577908..debeacf3 100644 --- a/interconnect/interconnect-maven-plugin/src/main/resources/ivo/ivo.vm +++ b/interconnect/interconnect-maven-plugin/src/main/resources/ivo/ivo.vm @@ -79,13 +79,9 @@ public class $model.getClazzName() extends $model.getParentClazzName() implement * @return the builder * **/ -#if ( $field.required ) @Nonnull -#else - @Nullable -#end @SuppressWarnings("unchecked") - public E with$tool.upperCaseFirst( $field.name )($field.getTypeAsString(false) p$field.name) { + public E with$tool.upperCaseFirst( $field.name )(#if ( $field.required )@Nonnull#else@Nullable#end $field.getTypeAsString(false) p$field.name) { this.$field.name = p$field.name; return (E) this; } @@ -117,6 +113,7 @@ public class $model.getClazzName() extends $model.getParentClazzName() implement #if ( $model.hasParentClazz() ) @Override #end + @Nonnull public $model.getClazzName() build() { #foreach ( $field in $model.getAllFields() ) #if ( $field.required ) @@ -171,6 +168,11 @@ public class $model.getClazzName() extends $model.getParentClazzName() implement #foreach ( $field in $model.getNoCollectionFields() ) #if ( $field.jsonTransientFlag ) @JsonIgnore +#end +#if ( $field.required ) + @Nonnull +#else + @Nullable #end @Override public $field.getTypeAsString( false ) get$tool.upperCaseFirst( $field.name )() { @@ -181,13 +183,18 @@ public class $model.getClazzName() extends $model.getParentClazzName() implement #foreach ( $field in $model.getCollectionFields() ) #if ( $field.jsonTransientFlag ) @JsonIgnore +#end +#if ( $field.required ) + @Nonnull +#else + @Nullable #end @Override public $field.getTypeAsString( false ) get$tool.upperCaseFirst( $field.name )() { #if( $field.collectionType == "List" ) - return this.$field.name == null ? null : Collections.unmodifiableList(this.$field.name); + return this.$field.name == null ? #if ( $field.required )Collections.emptyList() #else null #end: Collections.unmodifiableList(this.$field.name); #else - return this.$field.name == null ? null : Collections.unmodifiableSet(this.$field.name); + return this.$field.name == null ? #if ( $field.required )Collections.emptySet() #else null #end: Collections.unmodifiableSet(this.$field.name); #end } @@ -195,11 +202,16 @@ public class $model.getClazzName() extends $model.getParentClazzName() implement #foreach ( $field in $model.getMapFields() ) #if ( $field.jsonTransientFlag ) @JsonIgnore +#end +#if ( $field.required ) + @Nonnull +#else + @Nullable #end @Override public $field.getTypeAsString( false ) get$tool.upperCaseFirst( $field.name )() { #if( $field.mapType == "Map" ) - return this.$field.name == null ? null : Collections.unmodifiableMap(this.$field.name); + return this.$field.name == null ? #if ( $field.required ) Collections.emptyMap() #else null #end: Collections.unmodifiableMap(this.$field.name); #else return this.$field.name == null ? null : Multimaps.unmodifiableMultimap(this.$field.name); #end diff --git a/interconnect/interconnect-maven-plugin/src/main/resources/ivo/modify.vm b/interconnect/interconnect-maven-plugin/src/main/resources/ivo/modify.vm index 5bc5becd..99da19fa 100644 --- a/interconnect/interconnect-maven-plugin/src/main/resources/ivo/modify.vm +++ b/interconnect/interconnect-maven-plugin/src/main/resources/ivo/modify.vm @@ -71,6 +71,7 @@ private static final long serialVersionUID = ${model.getSerialVersion()}L; /** * @return the entry **/ + @Nonnull public ${clazzName} build() { if (this.value == null) { throw new IllegalStateException("The attribute value must not be null!"); @@ -89,12 +90,14 @@ private static final long serialVersionUID = ${model.getSerialVersion()}L; this.value = builder.value; } + @Nonnull public ${model.getClazzName()} getValue() { return this.value; } @SuppressWarnings("unchecked") @Override + @Nonnull public T createBuilder() { ${clazzName}Builder builder = new ${clazzName}Builder(); builder.internalFillFromIVO(this); From 2aa1bcdea1093a2b028588d4c71b007e21995e4b Mon Sep 17 00:00:00 2001 From: Philipp Sigloch Date: Tue, 16 Jul 2024 16:16:15 +0200 Subject: [PATCH 2/2] adds changelog entry for annotation correction on ivos and events --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44acf09d..39063166 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ * The old functionality is still available with the mongodb-legacy library * Breaking: Removed Junit 5 Vintage engine and Junit 4 (can be added in projects that need it) * Fixed vulnerabilities: CVE-2023-52428(nimbus-jose-jwt), CVE-2024-29857,CVE-2024-30171,CVE-2024-30172,CVE-2024-34447 (bouncycastle), CVE-2024-28752 (Apache CXF) +* Corrected the use of @Nullable and @Nonnull annotations on created ivos and events, especially on the generated builders # 1.35 * Update dependencies