Return-Path: Delivered-To: apmail-incubator-harmony-dev-archive@www.apache.org Received: (qmail 78712 invoked from network); 22 Feb 2006 14:18:13 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 22 Feb 2006 14:18:13 -0000 Received: (qmail 36693 invoked by uid 500); 22 Feb 2006 14:18:00 -0000 Delivered-To: apmail-incubator-harmony-dev-archive@incubator.apache.org Received: (qmail 36616 invoked by uid 500); 22 Feb 2006 14:17:59 -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 36604 invoked by uid 99); 22 Feb 2006 14:17:59 -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.apache.org) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 22 Feb 2006 06:17:59 -0800 Received: from ajax.apache.org (ajax.apache.org [127.0.0.1]) by ajax.apache.org (Postfix) with ESMTP id 24FE3DC for ; Wed, 22 Feb 2006 15:17:38 +0100 (CET) Message-ID: <187969487.1140617858042.JavaMail.jira@ajax.apache.org> Date: Wed, 22 Feb 2006 15:17:38 +0100 (CET) From: "Tim Ellison (JIRA)" To: harmony-dev@incubator.apache.org Subject: [jira] Assigned: (HARMONY-94) java.util.Collections.binarySearch(List, Object, Comparator c) throws NPE when c is null In-Reply-To: <1715364162.1139989559798.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-94?page=all ] Tim Ellison reassigned HARMONY-94: ---------------------------------- Assign To: Tim Ellison > java.util.Collections.binarySearch(List, Object, Comparator c) throws NPE when c is null > ---------------------------------------------------------------------------------------- > > Key: HARMONY-94 > URL: http://issues.apache.org/jira/browse/HARMONY-94 > Project: Harmony > Type: Bug > Components: Classlib > Reporter: Svetlana Samoilenko > Assignee: Tim Ellison > > According to j2se 1.4.2 and 1.5 specification for java.util.Collections.binarySearch(List, Object, Comparator c) method null value of Comparator c indicates, that the elements' natural ordering should be used. > Harmony throws NPE in this case that contradicts specification. > Code to reproduce: > import java.util.*; > public class test2 { > public static void main(String args[]){ > LinkedList lst = new LinkedList(); > lst.add(new Integer(30)); > Collections.sort(lst, null); > int i = Collections.binarySearch(lst, new Integer(2), null); > System.out.println("Index of search key =" + i); > } > } > 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) > Index of search key =-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. > java.lang.NullPointerException > at java.util.Collections.binarySearch(Collections.java:1347) > at test2.main(test2.java:8) > Suggected fix: > Index: trunk/modules/luni/src/main/java/java/util/Collections.java > =================================================================== > --- trunk/modules/luni/src/main/java/java/util/Collections.java (revision 377385) > +++ trunk/modules/luni/src/main/java/java/util/Collections.java (working copy) > @@ -1340,6 +1340,9 @@ > */ > public static int binarySearch(List list, Object object, > Comparator comparator) { > + if ( comparator== null) { > + return Collections.binarySearch(list, object); > + } > if (!(list instanceof RandomAccess)) { > ListIterator it = list.listIterator(); > while (it.hasNext()) { > Suggested junit test case: > ------------------------ CollectionsTest.java ------------------------------------------------- > import junit.framework.*; > import java.util.*; > public class CollectionsTest extends TestCase { > public static void main(String[] args) { > junit.textui.TestRunner.run(CollectionsTest.class); > } > public void test_binarySearch () { > LinkedList lst = new LinkedList(); > lst.add(new Integer(30)); > Collections.sort(lst, null); > assertEquals(-1, Collections.binarySearch(lst, new Integer(2), null)); > } > } -- 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