Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 3254 protobuf null pointer exceptions #3353

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ public void updateTokenProperty(

@Override
public void updateTokenProperty(Token token, Token.Update update) {
updateTokenProperty(token, update);
updateTokenProperty(token, update, new TokenPropertyValueDto[] {});
}

@Override
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/net/rptools/maptool/model/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ public Campaign() {
gmMacroButtonProperties = new ArrayList<MacroButtonProperties>();
}

private Object readResolve() {
if (exportSettings == null) {
exportSettings = new HashMap<>();
}

return this;
}

private void checkCampaignPropertyConversion() {
if (campaignProperties == null) {
campaignProperties = new CampaignProperties();
Expand Down
12 changes: 11 additions & 1 deletion src/main/java/net/rptools/maptool/model/LookupTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@ public LookupEntry(int min, int max, String value, MD5Key imageId) {
this.imageId = imageId;
}

private Object readResolve() {
if (picked == null) {
picked = false;
}

return this;
}

public MD5Key getImageId() {
return imageId;
}
Expand Down Expand Up @@ -525,7 +533,9 @@ public LookupTableDto toDto() {
var dto = LookupTableDto.newBuilder();
dto.addAllEntries(entryList.stream().map(e -> e.toDto()).collect(Collectors.toList()));
dto.setName(name);
dto.setDefaultRoll(defaultRoll);
if (defaultRoll != null) {
dto.setDefaultRoll(defaultRoll);
}
if (tableImage != null) {
dto.setTableImage(StringValue.of(tableImage.toString()));
}
Expand Down
43 changes: 37 additions & 6 deletions src/main/java/net/rptools/maptool/model/Token.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public enum Update {
private Area vbl;

private String name;
private final Set<String> ownerList = new HashSet<>();
private Set<String> ownerList = new HashSet<>();

private int ownerType;

Expand Down Expand Up @@ -323,7 +323,7 @@ public String toString() {
private MD5Key charsheetImage;
private MD5Key portraitImage;

private final List<AttachedLightSource> lightSourceList = new ArrayList<>();
private List<AttachedLightSource> lightSourceList = new ArrayList<>();
private String sightType;
private boolean hasSight;
private Boolean hasImageTable = false;
Expand Down Expand Up @@ -353,12 +353,12 @@ public String toString() {
// help XStream move the data around.
private Map<String, Object> propertyMap; // 1.3b77 and earlier

private final CaseInsensitiveHashMap<Object> propertyMapCI = new CaseInsensitiveHashMap<>();
private CaseInsensitiveHashMap<Object> propertyMapCI = new CaseInsensitiveHashMap<>();

private Map<String, String> macroMap;
private final Map<Integer, MacroButtonProperties> macroPropertiesMap = new HashMap<>();
private Map<Integer, MacroButtonProperties> macroPropertiesMap = new HashMap<>();

private final Map<String, String> speechMap = new HashMap<>();
private Map<String, String> speechMap = new HashMap<>();

private HeroLabData heroLabData;

Expand Down Expand Up @@ -2378,6 +2378,9 @@ protected Object readResolve() {
// a pre-1.3b78 token that actually has the CaseInsensitiveHashMap<?>.
// Newer tokens will use propertyMapCI so we only need to make corrections
// if the old field has data in it.
if (propertyMapCI == null) {
propertyMapCI = new CaseInsensitiveHashMap<>();
}
if (propertyMap != null) {
propertyMapCI.putAll(propertyMap);
propertyMap.clear(); // It'll never be written out, but we should free the memory.
Expand All @@ -2402,6 +2405,34 @@ protected Object readResolve() {
}
}

if (ownerList == null) {
ownerList = new HashSet<>();
}
if (lightSourceList == null) {
lightSourceList = new ArrayList<>();
}
if (macroPropertiesMap == null) {
macroPropertiesMap = new HashMap<>();
}
if (speechMap == null) {
speechMap = new HashMap<>();
}
if (isFlippedIso == null) {
isFlippedIso = false;
}
if (hasImageTable == null) {
hasImageTable = false;
}
if (tokenShape == null) {
tokenShape = TokenShape.SQUARE.toString();
}
if (tokenType == null) {
tokenType = Type.NPC.toString();
}
if (speechName == null) {
speechName = "";
}

return this;
}

Expand Down Expand Up @@ -2840,7 +2871,7 @@ public TokenDto toDto() {
dto.setVisibleOnlyToOwner(visibleOnlyToOwner);
dto.setVblColorSensitivity(vblColorSensitivity);
dto.setAlwaysVisibleTolerance(alwaysVisibleTolerance);
dto.setIsAlwaysVisible(isVisible);
dto.setIsAlwaysVisible(isAlwaysVisible);
if (vbl != null) {
dto.setVbl(Mapper.map(vbl));
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/net/rptools/maptool/model/Zone.java
Original file line number Diff line number Diff line change
Expand Up @@ -2266,8 +2266,12 @@ public ZoneDto toDto() {
dto.addAllLabels(labels.values().stream().map(l -> l.toDto()).collect(Collectors.toList()));
dto.addAllTokens(tokenMap.values().stream().map(t -> t.toDto()).collect(Collectors.toList()));
exposedAreaMeta.forEach(
(id, area) ->
dto.putExposedAreaMeta(id.toString(), Mapper.map(area.getExposedAreaHistory())));
(id, area) -> {
if (id == null) {
return;
}
dto.putExposedAreaMeta(id.toString(), Mapper.map(area.getExposedAreaHistory()));
});
dto.setInitiative(initiativeList.toDto());
dto.setExposedArea(Mapper.map(exposedArea));
dto.setHasFog(hasFog);
Expand Down