harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From var...@apache.org
Subject svn commit: r650838 - in /harmony/enhanced/drlvm/trunk/vm: tests/kernel/java/lang/reflect/TypesTest.java vmcore/src/kernel_classes/javasrc/org/apache/harmony/lang/reflect/implementation/ParameterizedTypeImpl.java
Date Wed, 23 Apr 2008 11:53:43 GMT
Author: varlax
Date: Wed Apr 23 04:53:41 2008
New Revision: 650838

URL: http://svn.apache.org/viewvc?rev=650838&view=rev
Log:
Fixed HARMONY-5780 [drlvm] NPE in ParameterizedTypeImpl.equals
brushed hashCode()/toString() as well

Added:
    harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/reflect/TypesTest.java   (with
props)
Modified:
    harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/lang/reflect/implementation/ParameterizedTypeImpl.java

Added: harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/reflect/TypesTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/reflect/TypesTest.java?rev=650838&view=auto
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/reflect/TypesTest.java (added)
+++ harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/reflect/TypesTest.java Wed Apr
23 04:53:41 2008
@@ -0,0 +1,51 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package java.lang.reflect;
+
+import junit.framework.TestCase;
+
+public class TypesTest extends TestCase {
+
+    /**
+     * Regression test for HARMONY-5780  
+     */
+    public void testParameterizedTypeImpl() throws Exception {
+        Method get = Container.class.getDeclaredMethod("get");
+        Method set = Container.class.getDeclaredMethod("set", Element.class);
+        Type arg = set.getGenericParameterTypes()[0];
+        Type ret = get.getGenericReturnType();
+        assertTrue("equals", arg.equals(ret));
+        assertEquals("toString", arg.toString(),ret.toString());
+    }
+}
+
+class Element<T> { 
+} 
+
+class Container { 
+
+    protected Element<Container> el; 
+
+    public Element<Container> get() { 
+        return el; 
+    } 
+
+    public void set(Element<Container> value) { 
+        this.el = value; 
+    } 
+} 

Propchange: harmony/enhanced/drlvm/trunk/vm/tests/kernel/java/lang/reflect/TypesTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/lang/reflect/implementation/ParameterizedTypeImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/lang/reflect/implementation/ParameterizedTypeImpl.java?rev=650838&r1=650837&r2=650838&view=diff
==============================================================================
--- harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/lang/reflect/implementation/ParameterizedTypeImpl.java
(original)
+++ harmony/enhanced/drlvm/trunk/vm/vmcore/src/kernel_classes/javasrc/org/apache/harmony/lang/reflect/implementation/ParameterizedTypeImpl.java
Wed Apr 23 04:53:41 2008
@@ -17,16 +17,9 @@
 
 package org.apache.harmony.lang.reflect.implementation;
 
-import java.lang.reflect.GenericArrayType;
 import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.TypeVariable;
-import java.lang.reflect.WildcardType;
 import java.lang.reflect.Type;
 
-/**
- * @author Serguei S. Zapreyev
- * @version $Revision: 1.1.2.2 $
- */
 public final class ParameterizedTypeImpl implements ParameterizedType {
     private final Type[] args;
     private final Type rawType;
@@ -39,8 +32,12 @@
     }
     
     public boolean equals(Object other) {
-        Type[] arr;
-        if (other == null || !(other instanceof ParameterizedType) || args.length != (arr
= ((ParameterizedType)other).getActualTypeArguments()).length) {
+        if (!(other instanceof ParameterizedType)) { 
+            return false;
+        }
+        ParameterizedType otherType = (ParameterizedType)other;
+        Type[] arr = otherType.getActualTypeArguments(); 
+        if (args.length != arr.length) {
             return false;
         }
         for (int i = 0; i < args.length; i++) {
@@ -48,7 +45,10 @@
                 return false;
             }
         }
-        return rawType.equals(((ParameterizedType)other).getRawType()) && typeOwner.equals(((ParameterizedType)other).getOwnerType());
+        return rawType.equals(otherType.getRawType()) 
+        && (typeOwner == otherType.getOwnerType() 
+                || typeOwner != null 
+                && typeOwner.equals(otherType.getOwnerType()));
     }
 
     public Type[] getActualTypeArguments() {
@@ -64,19 +64,22 @@
     }
 
     public int hashCode() {
-        //return super.hashCode();
         int ah = 0; 
         for(int i = 0; i < args.length; i++) {
             ah += args[i].hashCode();
         }
-        return ah ^ rawType.hashCode() ^ typeOwner.hashCode();
+        if (typeOwner != null) {
+            ah ^= typeOwner.hashCode();
+        }
+        return ah ^ rawType.hashCode();
     }
     
     public String toString() {
-        // TODO: this body should be reimplemented effectively.
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         if (typeOwner!=null) {
-            sb.append((typeOwner instanceof Class ? ((Class)typeOwner).getName() : typeOwner.toString())+"."+((Class)getRawType()).getSimpleName());
+            sb.append((typeOwner instanceof Class ? 
+                    ((Class)typeOwner).getName() : typeOwner.toString()));
+            sb.append('.').append(((Class)getRawType()).getSimpleName());
         } else {
             sb.append(((Class)getRawType()).getName());
         }
@@ -88,15 +91,9 @@
                 }
                 if (args[i] instanceof Class) {
                     sb.append(((Class)args[i]).getName());
-                } else if (args[i] instanceof ParameterizedType) {
-                    sb.append(args[i].toString());
-                } else if (args[i] instanceof TypeVariable) {
+                } else {
                     sb.append(args[i].toString());
-                } else if (args[i] instanceof WildcardType) {
-                    sb.append(args[i].toString());
-                } else if (args[i] instanceof GenericArrayType) {
-                    sb.append(args[i].toString());
-                }
+                } 
             }
             sb.append(">");
         }



Mime
View raw message