Fix or suppress Hazelcast-related "unchecked" compilation warnings.
* Fix compilation warnings in file HazelcastEventChannel.java
that were related to using the Java generics.
* Suppress "unchecked" compilation warnings in file HazelcastDatagrid.java
There was no obvious solution of solving the problem, hence for the time
being the warnings are suppressed.
* Minor refactoring inside file HazelcastDatagrid.java to allow
using the @SuppressWarnings("unchecked") statement inline.
Change-Id: I89ff9b4306b75ac7798ccf8b31daca3a825dc512
diff --git a/src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java b/src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java
index e204e45..563be33 100755
--- a/src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java
+++ b/src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java
@@ -202,27 +202,28 @@
private <K, V> IEventChannel<K, V> createChannelImpl(
String channelName,
Class<K> typeK, Class<V> typeV) {
- IEventChannel<K, V> castedEventChannel;
IEventChannel<?, ?> genericEventChannel =
eventChannels.get(channelName);
// Add the channel if the first listener
if (genericEventChannel == null) {
- castedEventChannel =
- new HazelcastEventChannel<K, V>(hazelcastInstance,
- channelName, typeK, typeV);
+ IEventChannel<K, V> castedEventChannel =
+ new HazelcastEventChannel<K, V>(hazelcastInstance,
+ channelName, typeK, typeV);
eventChannels.put(channelName, castedEventChannel);
- } else {
- //
- // TODO: Find if we can use Java internal support to check for
- // type mismatch.
- //
- if (!genericEventChannel.verifyKeyValueTypes(typeK, typeV)) {
- throw new ClassCastException("Key-value type mismatch for event channel " + channelName);
- }
- castedEventChannel = (IEventChannel<K, V>) genericEventChannel;
+ return castedEventChannel;
}
+ //
+ // TODO: Find if we can use Java internal support to check for
+ // type mismatch.
+ //
+ if (!genericEventChannel.verifyKeyValueTypes(typeK, typeV)) {
+ throw new ClassCastException("Key-value type mismatch for event channel " + channelName);
+ }
+ @SuppressWarnings("unchecked")
+ IEventChannel<K, V> castedEventChannel =
+ (IEventChannel<K, V>) genericEventChannel;
return castedEventChannel;
}
@@ -276,6 +277,7 @@
// NOTE: Using "ClassCastException" exception below doesn't
// work.
//
+ @SuppressWarnings("unchecked")
IEventChannel<K, V> castedEventChannel =
(IEventChannel<K, V>) genericEventChannel;
castedEventChannel.removeListener(listener);