Skip to content

BootNotificationRequest::setChargeBoxSerialNumber(null) throws NullPointerException #221

Closed
@bantu

Description

@bantu

I am not sure whether this is the expected behavior, I do not believe it is.

new BootNotificationRequest().setChargeBoxSerialNumber(null);

throws a NullPointerException due to .length() in

    if (!ModelUtil.validate(chargeBoxSerialNumber, STRING_25_CHAR_MAX_LENGTH)) {
      throw new PropertyConstraintException(
          chargeBoxSerialNumber.length(), validationErrorMessage(STRING_25_CHAR_MAX_LENGTH));
    }

being called on a null String.

Note that chargeBoxSerialNumber is optional in BootNotificationRequest.

Here's a test for reproduction:

package eu.chargetime.ocpp.model.core.test;

import eu.chargetime.ocpp.model.core.BootNotificationRequest;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class BootNotificationRequestTest {

  @Rule public ExpectedException thrownException = ExpectedException.none();

  private BootNotificationRequest request;

  @Before
  public void setup() {
    request = new BootNotificationRequest();
  }

  @Test()
  public void validate_setChargeBoxSerialNumber_onNull_doesNotThrowNPE() {
    request.setChargeBoxSerialNumber(null);
  }
}

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