Return-Path: Delivered-To: apmail-incubator-harmony-dev-archive@www.apache.org Received: (qmail 40707 invoked from network); 7 Mar 2006 11:11:36 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 7 Mar 2006 11:11:36 -0000 Received: (qmail 31488 invoked by uid 500); 7 Mar 2006 11:11:31 -0000 Delivered-To: apmail-incubator-harmony-dev-archive@incubator.apache.org Received: (qmail 31421 invoked by uid 500); 7 Mar 2006 11:11:30 -0000 Mailing-List: contact harmony-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-dev@incubator.apache.org Received: (qmail 31394 invoked by uid 99); 7 Mar 2006 11:11:30 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received: from [192.87.106.226] (HELO ajax) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Mar 2006 03:11:30 -0800 Received: from ajax (localhost.localdomain [127.0.0.1]) by ajax (Postfix) with ESMTP id 3A085D49FA for ; Tue, 7 Mar 2006 11:10:39 +0000 (GMT) Message-ID: <505542728.1141729839194.JavaMail.jira@ajax> Date: Tue, 7 Mar 2006 11:10:39 +0000 (GMT) From: "Tim Ellison (JIRA)" To: harmony-dev@incubator.apache.org Subject: [jira] Closed: (HARMONY-73) java.net.InetAddress.getLocalHost() returns wrong host name for loopback address In-Reply-To: <407193455.1138949583300.JavaMail.jira@ajax.apache.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N [ http://issues.apache.org/jira/browse/HARMONY-73?page=all ] Tim Ellison closed HARMONY-73: ------------------------------ Verified by Svetlana > java.net.InetAddress.getLocalHost() returns wrong host name for loopback address > --------------------------------------------------------------------------------- > > Key: HARMONY-73 > URL: http://issues.apache.org/jira/browse/HARMONY-73 > Project: Harmony > Type: Bug > Components: Classlib > Reporter: Svetlana Samoilenko > Priority: Minor > Attachments: InetAddress.patch > > J2se 1.4.2 and 5.0 specifications for java.net.InetAddress.getLocalHost() read, that if there is a security manager, its checkConnect method is called with the local host name and -1 as its arguments to see if the operation is allowed. > If the operation is not allowed, an InetAddress representing the loopback address is returned as hostname/hostaddress (as followed from toString() specification). > The test listed below shows that the returned loopback address has wrong hostname, "127.0.0.1" instead of "loopback". > Inet_SecurityManager class is called twice and therefore host name is substituted with hostaddress address. > Code to reproduce: > import java.net.*; > public class test2 { > public static void main(String[] args) { > try { > System.setSecurityManager(new Inet_SecurityManager()); > System.out.println("Loopback address = " + InetAddress.getLocalHost()); > } catch (Exception e){ > System.out.println("Unexpected exception = " + e); > }; > } > } > class Inet_SecurityManager extends SecurityManager { > public void checkConnect(String host, int port) { > super.checkConnect(host,port); > throw new SecurityException(); > } > } > 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) > Inet_SecurityManager :host= nswssamoil1 > Inet_SecurityManager :port= -1 > Loopback address = localhost/127.0.0.1 > C:\tmp>C:\harmony\trunk\deploy\jre\bin\java -showversion test2 > (c) Copyright 1991, 2005 The Apache Software Foundation or its licensors, as applicable. > Inet_SecurityManager :host= nswssamoil1 > Inet_SecurityManager :port= -1 > Inet_SecurityManager :host= localhost > Inet_SecurityManager :port= -1 > Loopback address = 127.0.0.1/127.0.0.1 > 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(InetAddress.class); > } > public void test_getLocalHost() { > try{ > System.setSecurityManager(new Inet_SecurityManager()); > String hostname=InetAddress.getLocalHost().getHostName(); > assertEquals("localhost", hostname); > } catch (Exception e){ > fail("Unexpected exception = " + e); > }; > } > } > class Inet_SecurityManager extends SecurityManager { > public void checkConnect(String host, int port) { > super.checkConnect(host,port); > throw new SecurityException(); > } > } -- 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