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

Defensively create collections in JAXB getters #139

Closed
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
3 changes: 2 additions & 1 deletion changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ <h1>

<p><b>Next Release</b> at some date</p>
<ul>
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/127'>#127</a>] - AAdd endpoint that allows for more than one MUC room to be created with one request</li>
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/137'>#137</a>] - Defensively create collections in JAXB getters</li>
<li>[<a href='https://github.com/igniterealtime/openfire-restAPI-plugin/issues/127'>#127</a>] - Add endpoint that allows for more than one MUC room to be created with one request</li>
</ul>

<p><b>1.8.3</b> July 19, 2022</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

@XmlRootElement(name = "admins")
Expand All @@ -37,6 +38,9 @@ public AdminEntities(List<String> admins) {
@XmlElement(name = "admin")
@JsonProperty(value = "admins")
public List<String> getAdmins() {
if (admins == null) {
admins = new ArrayList<>();
}
return admins;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import javax.annotation.Nonnull;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

@XmlRootElement(name = "clusterNodes")
Expand All @@ -36,6 +37,9 @@ public ClusterNodeEntities(@Nonnull final List<ClusterNodeEntity> clusterNodeEnt
@XmlElement(name = "clusterNode")
@JsonProperty(value = "clusterNodes")
public List<ClusterNodeEntity> getClusterNodeEntities() {
if (clusterNodeEntities == null) {
clusterNodeEntities = new ArrayList<>();
}
return clusterNodeEntities;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
Expand Down Expand Up @@ -56,6 +57,9 @@ public GroupEntities(List<GroupEntity> groups) {
@XmlElement(name = "group")
@JsonProperty(value = "groups")
public List<GroupEntity> getGroups() {
if (groups == null) {
groups = new ArrayList<>();
}
return groups;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -121,6 +122,9 @@ public void setDescription(String description) {
@JsonProperty(value = "admins")
@ArraySchema(schema = @Schema(example = "jane.smith"), arraySchema = @Schema(description = "List of admins of the group"))
public List<String> getAdmins() {
if (admins == null) {
admins = new ArrayList<>();
}
return admins;
}

Expand All @@ -134,6 +138,9 @@ public List<String> getAdmins() {
@JsonProperty(value = "members")
@ArraySchema(schema = @Schema(example = "john.jones"), arraySchema = @Schema(description = "List of members of the group"))
public List<String> getMembers() {
if (members == null) {
members = new ArrayList<>();
}
return members;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
Expand All @@ -37,6 +38,9 @@ public MUCRoomEntities(List<MUCRoomEntity> mucRooms) {
@XmlElement(name = "chatRoom")
@JsonProperty(value = "chatRooms")
public List<MUCRoomEntity> getMucRooms() {
if (mucRooms == null) {
mucRooms = new ArrayList<>();
}
return mucRooms;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
package org.jivesoftware.openfire.plugin.rest.entity;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

Expand Down Expand Up @@ -259,20 +261,29 @@ public void setModerated(boolean moderated) {
@XmlElementWrapper(name = "broadcastPresenceRoles")
@JsonProperty(value = "broadcastPresenceRoles")
public List<String> getBroadcastPresenceRoles() {
if (broadcastPresenceRoles == null) {
broadcastPresenceRoles = new ArrayList<>();
}
return broadcastPresenceRoles;
}

@XmlElementWrapper(name = "owners")
@XmlElement(name = "owner")
@JsonProperty(value = "owners")
public List<String> getOwners() {
if (owners == null) {
owners = new ArrayList<>();
}
return owners;
}

@XmlElementWrapper(name = "ownerGroups")
@XmlElement(name = "ownerGroup")
@JsonProperty(value = "ownerGroups")
public List<String> getOwnerGroups() {
if (ownerGroups == null) {
ownerGroups = new ArrayList<>();
}
return ownerGroups;
}

Expand All @@ -288,13 +299,19 @@ public void setOwnerGroups(List<String> ownerGroups) {
@XmlElement(name = "member")
@JsonProperty(value = "members")
public List<String> getMembers() {
if (members == null) {
members = new ArrayList<>();
}
return members;
}

@XmlElementWrapper(name = "memberGroups")
@XmlElement(name = "memberGroup")
@JsonProperty(value = "memberGroups")
public List<String> getmemberGroups() {
if (memberGroups == null) {
memberGroups = new ArrayList<>();
}
return memberGroups;
}

Expand All @@ -310,13 +327,19 @@ public void setMemberGroups(List<String> memberGroups) {
@XmlElement(name = "outcast")
@JsonProperty(value = "outcasts")
public List<String> getOutcasts() {
if (outcasts == null) {
outcasts = new ArrayList<>();
}
return outcasts;
}

@XmlElementWrapper(name = "outcastGroups")
@XmlElement(name = "outcastGroup")
@JsonProperty(value = "outcastGroups")
public List<String> getoutcastGroups() {
if (outcastGroups == null) {
outcastGroups = new ArrayList<>();
}
return outcastGroups;
}

Expand All @@ -332,13 +355,19 @@ public void setOutcastGroups(List<String> outcastGroups) {
@XmlElement(name = "admin")
@JsonProperty(value = "admins")
public List<String> getAdmins() {
if (admins == null) {
admins = new ArrayList<>();
}
return admins;
}

@XmlElementWrapper(name = "adminGroups")
@XmlElement(name = "adminGroup")
@JsonProperty(value = "adminGroups")
public List<String> getadminGroups() {
if (adminGroups == null) {
adminGroups = new ArrayList<>();
}
return adminGroups;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

@XmlRootElement(name = "messages")
Expand All @@ -33,6 +34,9 @@ public MUCRoomMessageEntities(List<MUCRoomMessageEntity> messages) {

@XmlElement(name = "message")
public List<MUCRoomMessageEntity> getMessages() {
if (messages == null) {
messages = new ArrayList<>();
}
return messages;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

@XmlRootElement(name = "members")
Expand All @@ -37,6 +38,9 @@ public MemberEntities(List<String> members) {
@XmlElement(name = "member")
@JsonProperty(value = "members")
public List<String> getMembers() {
if (members == null) {
members = new ArrayList<>();
}
return members;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

@XmlRootElement(name = "occupants")
Expand All @@ -36,6 +37,9 @@ public OccupantEntities(List<OccupantEntity> occupants) {
@XmlElement(name = "occupant")
@JsonProperty(value = "occupants")
public List<OccupantEntity> getOccupants() {
if (occupants == null) {
occupants = new ArrayList<>();
}
return occupants;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

@XmlRootElement(name = "outcasts")
Expand All @@ -37,6 +38,9 @@ public OutcastEntities(List<String> outcasts) {
@XmlElement(name = "outcast")
@JsonProperty(value = "outcasts")
public List<String> getOutcasts() {
if (outcasts == null) {
outcasts = new ArrayList<>();
}
return outcasts;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.List;

@XmlRootElement(name = "owners")
Expand All @@ -37,6 +38,9 @@ public OwnerEntities(List<String> owners) {
@XmlElement(name = "owner")
@JsonProperty(value = "owners")
public List<String> getOwners() {
if (owners == null) {
owners = new ArrayList<>();
}
return owners;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
Expand All @@ -37,6 +38,9 @@ public ParticipantEntities(List<ParticipantEntity> participants) {
@XmlElement(name = "participant")
@JsonProperty(value = "participants")
public List<ParticipantEntity> getParticipants() {
if (participants == null) {
participants = new ArrayList<>();
}
return participants;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public void addResult(RoomCreationResultEntity resultToAdd) {
@JsonProperty(value = "success")
@Schema(description = "All creation results of type success")
public List<RoomCreationResultEntity> getSuccessResults() {
if (successResults == null) {
successResults = new ArrayList<>();
}
return successResults;
}

Expand All @@ -76,6 +79,9 @@ public List<RoomCreationResultEntity> getSuccessResults() {
@JsonProperty(value = "failure")
@Schema(description = "All creation results of type failure")
public List<RoomCreationResultEntity> getFailureResults() {
if (failureResults == null) {
failureResults = new ArrayList<>();
}
return failureResults;
}

Expand All @@ -84,6 +90,9 @@ public List<RoomCreationResultEntity> getFailureResults() {
@JsonProperty(value = "other")
@Schema(description = "All creation results of a type other than success or failure")
public List<RoomCreationResultEntity> getOtherResults() {
if (otherResults == null) {
otherResults = new ArrayList<>();
}
return otherResults;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.jivesoftware.openfire.plugin.rest.entity;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
Expand Down Expand Up @@ -54,6 +55,9 @@ public RosterEntities(List<RosterItemEntity> roster) {
*/
@XmlElement(name = "rosterItem")
public List<RosterItemEntity> getRoster() {
if (roster == null) {
roster = new ArrayList<>();
}
return roster;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
Expand Down Expand Up @@ -136,6 +137,9 @@ public void setSubscriptionType(int subscriptionType) {
@XmlElementWrapper(name = "groups")
@JsonProperty(value = "groups")
public List<String> getGroups() {
if (groups == null) {
groups = new ArrayList<>();
}
return groups;
}

Expand Down
Loading