diff --git a/bindings/java/src/org/sleuthkit/datamodel/OsAccountRealmManager.java b/bindings/java/src/org/sleuthkit/datamodel/OsAccountRealmManager.java
index b5947c21ad823f82edb67498bf0946e4d1af7f8f..959eb1cc8ab130a5b314e89d694bc59f5a0341fd 100644
--- a/bindings/java/src/org/sleuthkit/datamodel/OsAccountRealmManager.java
+++ b/bindings/java/src/org/sleuthkit/datamodel/OsAccountRealmManager.java
@@ -535,9 +535,9 @@ Optional<OsAccountRealm> getAnotherRealmByAddr(OsAccountRealm realm, String real
 			
 		// If the given realm has a host id, then the other realm should have the same host id
 		// If the given realm has no host id,  then the other realm should have no host id
-		String whereHostClause = (realm.getScopeHost().isEmpty()) 
-							? " realms.scope_host_id IS NULL " 
-							: " ( realms.scope_host_id = " + realm.getScopeHost().get().getHostId() + " ) ";
+		String whereHostClause = realm.getScopeHost().isPresent() 
+							? " ( realms.scope_host_id = " + realm.getScopeHost().get().getHostId() + " ) " 
+							: " realms.scope_host_id IS NULL ";
 		String queryString = REALM_QUERY_STRING
 						+ " WHERE LOWER(realms.realm_addr) = LOWER('"+ realmAddr + "') "
 						+ " AND " + whereHostClause
@@ -590,9 +590,9 @@ Optional<OsAccountRealm> getAnotherRealmByName(OsAccountRealm realm, String real
 		
 		// If the given realm has a host id, then the other realm should have the same host id
 		// If the given realm has no host id,  then the other realm should have no host id
-		String whereHostClause = (realm.getScopeHost().isEmpty()) 
-							? " realms.scope_host_id IS NULL " 
-							: " ( realms.scope_host_id = " + realm.getScopeHost().get().getHostId() + " ) ";
+		String whereHostClause = realm.getScopeHost().isPresent()
+							? " ( realms.scope_host_id = " + realm.getScopeHost().get().getHostId() + " ) " 
+							: " realms.scope_host_id IS NULL ";
 		String queryString = REALM_QUERY_STRING
 				+ " WHERE LOWER(realms.realm_name) = LOWER('" + realmName + "')"
 				+ " AND " + whereHostClause