diff options
Diffstat (limited to 'luni/src')
4 files changed, 58 insertions, 8 deletions
diff --git a/luni/src/main/java/java/lang/ref/FinalizerReference.java b/luni/src/main/java/java/lang/ref/FinalizerReference.java index 14eaae4..47dc0b4 100644 --- a/luni/src/main/java/java/lang/ref/FinalizerReference.java +++ b/luni/src/main/java/java/lang/ref/FinalizerReference.java @@ -98,7 +98,13 @@ public final class FinalizerReference<T> extends Reference<T> { FinalizerReference<Sentinel> sentinelReference = (FinalizerReference<Sentinel>) r; sentinelReference.referent = null; sentinelReference.zombie = sentinel; - sentinelReference.enqueueInternal(); + // Make a single element list, then enqueue the reference on the daemon unenqueued + // list. This is required instead of enqueuing directly on the finalizer queue + // since there could be recently freed objects in the unqueued list which are not + // yet on the finalizer queue. This could cause the sentinel to run before the + // objects are finalized. b/17381967 + sentinelReference.pendingNext = sentinelReference; + ReferenceQueue.add(sentinelReference); return; } } diff --git a/luni/src/main/java/libcore/reflect/GenericArrayTypeImpl.java b/luni/src/main/java/libcore/reflect/GenericArrayTypeImpl.java index ef22576..5919a19 100644 --- a/luni/src/main/java/libcore/reflect/GenericArrayTypeImpl.java +++ b/luni/src/main/java/libcore/reflect/GenericArrayTypeImpl.java @@ -18,6 +18,7 @@ package libcore.reflect; import java.lang.reflect.GenericArrayType; import java.lang.reflect.Type; +import java.util.Objects; public final class GenericArrayTypeImpl implements GenericArrayType { private final Type componentType; @@ -34,6 +35,20 @@ public final class GenericArrayTypeImpl implements GenericArrayType { } } + @Override + public boolean equals(Object o) { + if (!(o instanceof GenericArrayType)) { + return false; + } + GenericArrayType that = (GenericArrayType) o; + return Objects.equals(getGenericComponentType(), that.getGenericComponentType()); + } + + @Override + public int hashCode() { + return Objects.hashCode(getGenericComponentType()); + } + public String toString() { return componentType.toString() + "[]"; } diff --git a/luni/src/main/java/libcore/reflect/ParameterizedTypeImpl.java b/luni/src/main/java/libcore/reflect/ParameterizedTypeImpl.java index 99dfe8b..2cd5ac3 100644 --- a/luni/src/main/java/libcore/reflect/ParameterizedTypeImpl.java +++ b/luni/src/main/java/libcore/reflect/ParameterizedTypeImpl.java @@ -18,17 +18,22 @@ package libcore.reflect; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; +import java.util.Arrays; +import java.util.Objects; public final class ParameterizedTypeImpl implements ParameterizedType { private final ListOfTypes args; private final ParameterizedTypeImpl ownerType0; // Potentially unresolved. - private Type ownerTypeRes; - private Class rawType; // Already resolved. + private Type ownerTypeRes; // Potentially unresolved. + private Class rawType; // Potentially unresolved. private final String rawTypeName; - private ClassLoader loader; + private final ClassLoader loader; public ParameterizedTypeImpl(ParameterizedTypeImpl ownerType, String rawTypeName, ListOfTypes args, ClassLoader loader) { + if (args == null) { + throw new NullPointerException(); + } this.ownerType0 = ownerType; this.rawTypeName = rawTypeName; this.args = args; @@ -37,7 +42,6 @@ public final class ParameterizedTypeImpl implements ParameterizedType { public Type[] getActualTypeArguments() { - // ASSUMPTION: args is never null!!! return args.getResolvedTypes().clone(); } @@ -76,6 +80,23 @@ public final class ParameterizedTypeImpl implements ParameterizedType { } @Override + public boolean equals(Object o) { + if (!(o instanceof ParameterizedType)) { + return false; + } + ParameterizedType that = (ParameterizedType) o; + return Objects.equals(getRawType(), that.getRawType()) && + Objects.equals(getOwnerType(), that.getOwnerType()) && + Arrays.equals(args.getResolvedTypes(), that.getActualTypeArguments()); + } + + @Override + public int hashCode() { + return 31 * (31 * Objects.hashCode(getRawType()) + Objects.hashCode(getOwnerType())) + + Arrays.hashCode(args.getResolvedTypes()); + } + + @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(rawTypeName); diff --git a/luni/src/test/java/libcore/java/util/CalendarTest.java b/luni/src/test/java/libcore/java/util/CalendarTest.java index b2f6b94..e0e1a35 100644 --- a/luni/src/test/java/libcore/java/util/CalendarTest.java +++ b/luni/src/test/java/libcore/java/util/CalendarTest.java @@ -17,6 +17,7 @@ package libcore.java.util; import java.util.Calendar; +import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import java.util.TimeZone; @@ -245,14 +246,21 @@ public class CalendarTest extends junit.framework.TestCase { // here. We should add a targetSdkVersion based check and throw for each of these // cases. public void test_nullLocale() { - assertEquals( + assertCalendarConfigEquals( Calendar.getInstance(Locale.getDefault()), Calendar.getInstance((Locale) null)); - assertEquals( + assertCalendarConfigEquals( Calendar.getInstance(TimeZone.getDefault(), Locale.getDefault()), Calendar.getInstance(TimeZone.getDefault(), null)); - assertEquals( + assertCalendarConfigEquals( new GregorianCalendar(Locale.getDefault()), new GregorianCalendar((Locale) null)); } + + public void assertCalendarConfigEquals(Calendar a, Calendar b) { + Date d = new Date(); + a.setTime(d); + b.setTime(d); + assertEquals(a, b); + } } |