这是indexloc提供的服务,不要输入任何密码
Skip to content

NullPointerException safeguard for runConditions on multi-cardinality typeAliases #1024

@manel-martos

Description

@manel-martos

Background

The runConditions method in TypeValidators currently accesses multi-cardinality typeAliases directly without checking for null. This results in a potential NullPointerException when invoking size() method on a null list.

Example Issue

final List<? extends FieldWithMetaString> businessCenter = o.getBusinessCenter();
for (int i = 0; i < businessCenter.size(); i++) {
    // ...
}

If getBusinessCenter() returns null, the above code will throw a NullPointerException when size() is called. This scenario is common in multi-cardinality typeAliases with condition properties.

Proposed Solution
Introduce a null safety wrapper using Optional.ofNullable(...).orElse(...) to default to an empty list when the property is null.

final List<? extends FieldWithMetaString> businessCenter = Optional
    .ofNullable(o.getBusinessCenter())
    .orElse(new ArrayList<>());
for (int i = 0; i < businessCenter.size(); i++) {
    // ...
}

PR: #1029

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions