[ http://issues.apache.org/jira/browse/HARMONY-61?page=all ]
Tim Ellison updated HARMONY-61: ------------------------------- Estimated Complexity: Novice > java.net.InetAddress.getByAddress(null) throws NPE insread of > UnknownHostException > ---------------------------------------------------------------------------------- > > Key: HARMONY-61 > URL: http://issues.apache.org/jira/browse/HARMONY-61 > Project: Harmony > Type: Bug > Components: Classlib > Reporter: Svetlana Samoilenko > > According to j2se 1.4.2 specification for > java.net.InetAddress.getByAddress(byte[] addr) the method must throw > UnknownHostException if IP address is of illegal length. IPv4 address byte > array must be 4 bytes long and IPv6 byte array must be 16 bytes long. There > is no mention about NPE at all. Mentions about NPE in case of null argument > were not found in java.net package specification. > The test listed below shows that getByAddress (null) throws NPE. BEA throws > UnknownHostException. > Code to reproduce: > import java.net.*; > public class test2 { > public static void main (String[] args) { > > try { > InetAddress.getByAddress (null); > } catch (UnknownHostException e) { > System.out.println("***OK. Expected UnknownHostException. " + e); > } > } > } > Steps to Reproduce: > 1. Build Harmony (check-out on 2006-01-30) j2se subset as described in > README.txt. > 2. Compile test2.java using BEA 1.4 javac > > javac -d . test2.java > 3. Run java using compatible VM (J9) > > java -showversion test2 > Output: > C:\tmp>C:\jrockit-j2sdk1.4.2_04\bin\java.exe -showversion test2 > java version "1.4.2_04" > Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05) > BEA WebLogic JRockit(TM) 1.4.2_04 JVM (build > ari-31788-20040616-1132-win-ia32, Native Threads, GC strategy: parallel) > ***OK. UnknownHostException=:java.net.UnknownHostException: addr is of > illegal length > C:\tmp>C:\harmony\trunk\deploy\jre\bin\java -showversion test2 > (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as > applicable. > java.lang.NullPointerException > at java.net.InetAddress.getByAddress(InetAddress.java:735) > at java.net.InetAddress.getByAddress(InetAddress.java:713) > at test2.main(test2.java:7) > Suggested junit test case: > ------------------------ InetAddressTest.java > ------------------------------------------------- > import java.net.*; > import junit.framework.*; > public class InetAddressTest extends TestCase { > public static void main(String[] args) { > junit.textui.TestRunner.run(InetAddressTest.class); > } > public void test_getByAddress() { > try { > InetAddress.getByAddress (null); > fail("Assert 0: UnknownHostException must be thrown"); > } catch (UnknownHostException e) { > } > } > } -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira