Skip to content

Commit

Permalink
Merge pull request #163 from taimos/ivo_correct_annotations
Browse files Browse the repository at this point in the history
corrects @nullable and @nonnull annotations on created ivos and events
  • Loading branch information
YukiInu authored Jul 22, 2024
2 parents c8e90fe + 2aa1bcd commit 05aca20
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 21 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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;
Expand All @@ -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" )
Expand All @@ -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" )
Expand All @@ -158,8 +170,8 @@ public class $model.getClazzName() extends $model.getParentClazzName() implement

@SuppressWarnings("unchecked")
@Override
public
<T extends IEventBuilder> T createBuilder() {
@Nonnull
public <T extends IEventBuilder> T createBuilder() {
${model.getClazzName()}Builder builder = new ${model.getClazzName()}Builder();
builder.internalFillFromIVO(this);
return (T) builder;
Expand All @@ -176,4 +188,4 @@ public class $model.getClazzName() extends $model.getParentClazzName() implement
#parse($addition)
#end

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand All @@ -170,6 +171,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz
}

@Override
@Nonnull
public List<String> getIds() {
return this.ids.stream().map(iv->iv.getId()).collect(Collectors.toList());
}
Expand All @@ -180,6 +182,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz
}

@Override
@Nonnull
public List<IdWithVersion> getIdsWithVersion() {
return new ArrayList<>(this.ids);
}
Expand All @@ -191,6 +194,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz

@SuppressWarnings("unchecked")
@Override
@Nonnull
public <T extends IVOBuilder> T createBuilder() {
${clazzName}Builder builder = new ${clazzName}Builder();
builder.internalFillFromIVO(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down Expand Up @@ -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 extends IVOBuilder> T createBuilder() {
${clazzName}Builder builder = new ${clazzName}Builder();
builder.internalFillFromIVO(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz
/**
* @return the ids
**/
@Nonnull
@JsonIgnore
public List<String> getIds() {
return this.ids.stream().map(iv->iv.getId()).collect(Collectors.toList());
Expand All @@ -153,6 +154,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz
/**
* @return the ids
**/
@Nonnull
@JsonIgnore
public List<IdWithVersion> getIdsWithVersion() {
return new ArrayList<>(this.ids);
Expand All @@ -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!");
Expand All @@ -182,6 +185,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz

@Override
@JsonIgnore
@Nonnull
public List<String> getIds() {
return this.ids.stream().map(iv->iv.getId()).collect(Collectors.toList());
}
Expand All @@ -194,6 +198,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz

@Override
@JsonProperty("ids")
@Nonnull
public List<IdWithVersion> getIdsWithVersion() {
return new ArrayList<>(this.ids);
}
Expand All @@ -206,6 +211,7 @@ public class ${clazzName} extends $model.getParentClazzName() implements I${claz

@SuppressWarnings("unchecked")
@Override
@Nonnull
public <T extends IVOBuilder> T createBuilder() {
${clazzName}Builder builder = new ${clazzName}Builder();
builder.internalFillFromIVO(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )() {
Expand All @@ -181,25 +183,35 @@ 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
}

#end
#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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand All @@ -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 extends IVOBuilder> T createBuilder() {
${clazzName}Builder builder = new ${clazzName}Builder();
builder.internalFillFromIVO(this);
Expand Down

0 comments on commit 05aca20

Please sign in to comment.