Cast InetAddress to Inet4Address or Inet6Address to call the specific static methods
diff --git a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPAddress.java b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPAddress.java
index 4cb0fa5..cee9ad1 100644
--- a/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPAddress.java
+++ b/java_gen/pre-written/src/main/java/org/projectfloodlight/openflow/types/IPAddress.java
@@ -142,9 +142,9 @@
public static IPAddress<?> of(@Nonnull InetAddress address) {
Preconditions.checkNotNull(address, "address must not be null");
if(address instanceof Inet4Address)
- return IPv4Address.of(address);
+ return IPv4Address.of((Inet4Address) address);
else if (address instanceof Inet6Address)
- return IPv6Address.of(address);
+ return IPv6Address.of((Inet6Address) address);
else
return IPAddress.of(address.getHostAddress());
}
diff --git a/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPAddressTest.java b/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPAddressTest.java
index 63c9c8f..2ba4528 100644
--- a/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPAddressTest.java
+++ b/java_gen/pre-written/src/test/java/org/projectfloodlight/openflow/types/IPAddressTest.java
@@ -1,10 +1,12 @@
package org.projectfloodlight.openflow.types;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.net.InetAddress;
import java.net.UnknownHostException;
import org.junit.Test;
@@ -56,6 +58,28 @@
}
}
+ @Test
+ public void testOfString() {
+ IPAddress<?> ip0 = IPAddress.of("1.2.3.4");
+ IPAddress<?> ip1 = IPAddress.of("abcd::1234");
+ assertTrue(ip0 instanceof IPv4Address);
+ assertTrue(ip1 instanceof IPv6Address);
+ assertEquals(ip0, IPv4Address.of("1.2.3.4"));
+ assertEquals(ip1, IPv6Address.of("abcd::1234"));
+ }
+
+ @Test
+ public void testOfInetAddress() throws Exception {
+ InetAddress ia0 = InetAddress.getByName("192.168.1.123");
+ InetAddress ia1 = InetAddress.getByName("fd00::4321");
+ IPAddress<?> ip0 = IPAddress.of(ia0);
+ IPAddress<?> ip1 = IPAddress.of(ia1);
+ assertTrue(ip0 instanceof IPv4Address);
+ assertTrue(ip1 instanceof IPv6Address);
+ assertEquals(ip0, IPv4Address.of(ia0));
+ assertEquals(ip1, IPv6Address.of(ia1));
+ }
+
@SuppressWarnings("deprecation")
@Test
public void testFromInetAddressException() throws UnknownHostException {