Skip to content

Commit 22160ba

Browse files
committed
Update MarkerLabel.java
Make sure text is not null
1 parent 57310b5 commit 22160ba

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main/java/com/flowingcode/vaadin/addons/googlemaps/MarkerLabel.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import elemental.json.Json;
44
import elemental.json.JsonObject;
55
import lombok.Getter;
6+
import lombok.NonNull;
67
import lombok.Setter;
78

9+
import java.util.Objects;
810
import java.util.Optional;
911

1012
/**
@@ -14,8 +16,9 @@
1416
@Setter
1517
public class MarkerLabel {
1618
/**
17-
* The text to be displayed in the label.
19+
* The text to be displayed in the label. Required field.
1820
*/
21+
@NonNull
1922
private String text;
2023

2124
/**
@@ -56,18 +59,18 @@ be used to change the position nor orientation of the label (e.g. using
5659

5760

5861
public MarkerLabel(String text) {
59-
this.text = text;
62+
this.text = Objects.requireNonNull(text, "Text cannot be null");
6063
}
6164

6265
public MarkerLabel(String text, String color, String fontSize) {
63-
this.text = text;
66+
this.text = Objects.requireNonNull(text, "Text cannot be null");
6467
this.color = color;
6568
this.fontSize = fontSize;
6669
}
6770

6871
protected JsonObject getJson() {
6972
JsonObject js = Json.createObject();
70-
Optional.ofNullable(getText()).ifPresent(value -> js.put("text", value));
73+
Optional.of(getText()).ifPresent(value -> js.put("text", value));
7174
Optional.ofNullable(getColor()).ifPresent(value -> js.put("color", value));
7275
Optional.ofNullable(getFontFamily()).ifPresent(value -> js.put("fontFamily", value));
7376
Optional.ofNullable(getFontSize()).ifPresent(value -> js.put("fontSize", value));

0 commit comments

Comments
 (0)