Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterdietz/952058 to your computer and use it in GitHub Desktop.
Save peterdietz/952058 to your computer and use it in GitHub Desktop.
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