Skip to content

Commit b4fa482

Browse files
airajenagalovics
authored andcommitted
FINERACT-2421: Fix potential NullPointerException in CalendarCommandFromApiJsonDeserializer
The extractBooleanNamed method can return null when the JSON value is null or missing. Using primitive boolean causes automatic unboxing which throws NullPointerException. Changes: - CalendarCommandFromApiJsonDeserializer: Use Boolean wrapper instead of primitive boolean for 'repeating' field extraction - CalendarCommandFromApiJsonDeserializer: Use Boolean.TRUE.equals() for null-safe boolean comparison - CalendarCommand: Update field type and constructor parameter from boolean to Boolean to support null values This addresses the FIXME comments on lines 156 and 298 in the original file.
1 parent e294ce8 commit b4fa482

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/command/CalendarCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class CalendarCommand {
3939
@SuppressWarnings("unused")
4040
private final Integer typeId;
4141
@SuppressWarnings("unused")
42-
private final boolean repeating;
42+
private final Boolean repeating;
4343
@SuppressWarnings("unused")
4444
private final Integer remindById;
4545
@SuppressWarnings("unused")
@@ -48,7 +48,7 @@ public class CalendarCommand {
4848
private final Integer secondReminder;
4949

5050
public CalendarCommand(final String title, final String description, final String location, final LocalDate startDate,
51-
final LocalDate endDate, final LocalDate createdDate, final Integer duration, final Integer typeId, final boolean repeating,
51+
final LocalDate endDate, final LocalDate createdDate, final Integer duration, final Integer typeId, final Boolean repeating,
5252
final Integer remindById, final Integer firstReminder, final Integer secondReminder) {
5353
this.title = title;
5454
this.description = description;

fineract-provider/src/main/java/org/apache/fineract/portfolio/calendar/serialization/CalendarCommandFromApiJsonDeserializer.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public CalendarCommand commandFromApiJson(final String json) {
8181
element);
8282
final Integer typeId = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(CalendarSupportedParameters.TYPE_ID.getValue(),
8383
element);
84-
final boolean repeating = this.fromApiJsonHelper.extractBooleanNamed(CalendarSupportedParameters.REPEATING.getValue(), element);
84+
final Boolean repeating = this.fromApiJsonHelper.extractBooleanNamed(CalendarSupportedParameters.REPEATING.getValue(), element);
8585
final Integer remindById = this.fromApiJsonHelper.extractIntegerSansLocaleNamed(CalendarSupportedParameters.REMIND_BY_ID.getValue(),
8686
element);
8787
final Integer firstReminder = this.fromApiJsonHelper
@@ -153,11 +153,10 @@ public void validateForCreate(final String json) {
153153
.inMinMaxRange(CalendarEntityType.getMinValue(), CalendarEntityType.getMaxValue());
154154

155155
if (this.fromApiJsonHelper.parameterExists(CalendarSupportedParameters.REPEATING.getValue(), element)) {
156-
// FIXME - Throws NullPointerException when boolean value is null
157-
final boolean repeating = this.fromApiJsonHelper.extractBooleanNamed(CalendarSupportedParameters.REPEATING.getValue(), element);
156+
final Boolean repeating = this.fromApiJsonHelper.extractBooleanNamed(CalendarSupportedParameters.REPEATING.getValue(), element);
158157
baseDataValidator.reset().parameter(CalendarSupportedParameters.REPEATING.getValue()).value(repeating).notNull();
159158

160-
if (repeating) {
159+
if (Boolean.TRUE.equals(repeating)) {
161160
final Integer frequency = this.fromApiJsonHelper
162161
.extractIntegerSansLocaleNamed(CalendarSupportedParameters.FREQUENCY.getValue(), element);
163162
baseDataValidator.reset().parameter(CalendarSupportedParameters.FREQUENCY.getValue()).value(frequency).notBlank()
@@ -295,11 +294,10 @@ public void validateForUpdate(final String json) {
295294
.inMinMaxRange(CalendarEntityType.getMinValue(), CalendarEntityType.getMaxValue());
296295
}
297296
if (this.fromApiJsonHelper.parameterExists(CalendarSupportedParameters.REPEATING.getValue(), element)) {
298-
// FIXME - Throws NullPointerException when boolean value is null
299-
final boolean repeating = this.fromApiJsonHelper.extractBooleanNamed(CalendarSupportedParameters.REPEATING.getValue(), element);
297+
final Boolean repeating = this.fromApiJsonHelper.extractBooleanNamed(CalendarSupportedParameters.REPEATING.getValue(), element);
300298
baseDataValidator.reset().parameter(CalendarSupportedParameters.REPEATING.getValue()).value(repeating).notNull();
301299

302-
if (repeating) {
300+
if (Boolean.TRUE.equals(repeating)) {
303301
final Integer frequency = this.fromApiJsonHelper
304302
.extractIntegerSansLocaleNamed(CalendarSupportedParameters.FREQUENCY.getValue(), element);
305303
baseDataValidator.reset().parameter(CalendarSupportedParameters.FREQUENCY.getValue()).value(frequency).notBlank()

0 commit comments

Comments
 (0)