harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Svetlana Samoilenko (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-61) java.net.InetAddress.getByAddress(null) throws NPE insread of UnknownHostException
Date Wed, 01 Feb 2006 05:05:33 GMT
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

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 

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. 
        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) { 

    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:
For more information on JIRA, see:

View raw message