Skip to content

Commit 4a181d2

Browse files
authored
Merge pull request DSpace#11886 from DSpace/backport-11677-to-dspace-9_x
[Port dspace-9_x] Fix NullPointerException in VersionHistoryService.getVersion() method
2 parents 5f013b6 + c65cd9c commit 4a181d2

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

dspace-api/src/main/java/org/dspace/versioning/VersionHistoryServiceImpl.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ public Version getVersion(Context context, VersionHistory versionHistory, Item i
109109
throws SQLException {
110110
Version v = versioningService.getVersion(context, item);
111111
if (v != null) {
112-
;
113-
}
114-
{
115112
if (versionHistory.equals(v.getVersionHistory())) {
116113
return v;
117114
}

dspace-api/src/test/java/org/dspace/content/VersioningTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,23 @@ public void testVersionDelete() throws Exception {
170170
assertThat("Test_version_handle_delete", handleService.resolveToObject(context, handle), nullValue());
171171
context.restoreAuthSystemState();
172172
}
173+
174+
@Test
175+
public void testGetVersionWithNullPointerException() throws Exception {
176+
context.turnOffAuthorisationSystem();
177+
// Create item without version
178+
Community community = communityService.create(null, context);
179+
Collection col = collectionService.create(context, community);
180+
WorkspaceItem is = workspaceItemService.create(context, col, false);
181+
Item itemWithoutVersion = installItemService.installItem(context, is);
182+
VersionHistory versionHistory = versionHistoryService.findByItem(context, originalItem);
183+
try {
184+
Version result = versionHistoryService.getVersion(context, versionHistory, itemWithoutVersion);
185+
assertThat("getVersion should return null for item without version", result, nullValue());
186+
} catch (NullPointerException npe) {
187+
fail("NullPointerException should not be thrown. Method should return null: " + npe.getMessage());
188+
} finally {
189+
context.restoreAuthSystemState();
190+
}
191+
}
173192
}

0 commit comments

Comments
 (0)