Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fixing NPE when viewing a community on the DSpace REST API
Index: src/main/java/org/dspace/rest/entities/CommunityEntity.java
===================================================================
--- src/main/java/org/dspace/rest/entities/CommunityEntity.java (revision 6356)
+++ src/main/java/org/dspace/rest/entities/CommunityEntity.java (working copy)
@@ -118,7 +118,17 @@
this.subCommunities.add(includeFull ? new CommunityEntity(c, level, uparams) : new CommunityEntityId(c));
}
try {
- this.parent = includeFull ? new CommunityEntity(res.getParentCommunity(), level, uparams) : new CommunityEntityId(res.getParentCommunity());
+ Community parentCommunity = res.getParentCommunity();
+ if(parentCommunity == null) {
+ this.parent = null;
+ } else {
+ if(includeFull) {
+ this.parent = new CommunityEntity(parentCommunity, level, uparams);
+ } else {
+ this.parent = new CommunityEntityId(parentCommunity);
+ }
+ }
+
} catch (NullPointerException ex) {
this.parent = null;
}
@@ -131,7 +141,16 @@
} catch (RecentSubmissionsException ex) {
}
- this.administrators = includeFull ? new GroupEntity(res.getAdministrators(), level, uparams) : new GroupEntityId(res.getAdministrators());
+ Group administrators = res.getAdministrators();
+ if(administrators == null) {
+ this.administrators = null;
+ } else {
+ if(includeFull) {
+ this.administrators = new GroupEntity(res.getAdministrators(), level, uparams);
+ } else {
+ this.administrators = new GroupEntityId(res.getAdministrators());
+ }
+ }
} catch (NumberFormatException ex) {
}
//context.complete(); //<-important
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.