Skip to content

Commit

Permalink
Fixed the keySet() return type in getDatabases() for Java 7 runtime s…
Browse files Browse the repository at this point in the history
…upport.
  • Loading branch information
SDIPro committed Jan 25, 2017
1 parent ce26174 commit 7b44e0d
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,17 @@ public ODistributedDatabaseImpl unregisterDatabase(final String iDatabaseName) {
}

@Override
public Set<String> getDatabases() {
final Set<String> result = new HashSet<String>(databases.keySet());
public Set<String> getDatabases() {
// We assign the ConcurrentHashMap (databases) to the Map interface for this reason:
// ConcurrentHashMap.keySet() in Java 8 returns a ConcurrentHashMap.KeySetView.
// ConcurrentHashMap.keySet() in Java 7 returns a Set.
// If this code is compiled with Java 8 yet is run on Java 7, you'll receive a NoSuchMethodError:
// java.util.concurrent.ConcurrentHashMap.keySet()Ljava/util/concurrent/ConcurrentHashMap$KeySetView.
// By assigning the ConcurrentHashMap variable to a Map, the call to keySet() will return a Set
// and not the Java 8 type, KeySetView.
Map<String, ODistributedDatabaseImpl> map = databases;

final Set<String> result = new HashSet<String>(map.keySet());
result.remove(OSystemDatabase.SYSTEM_DB_NAME);
return result;
}
Expand Down

0 comments on commit 7b44e0d

Please sign in to comment.