Merge "Use junit-hostdex instead of core-junit-hostdex/junit4-target-hostdex"
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/HttpCookieTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/HttpCookieTest.java
index 4c8390d..5fedfd7 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/HttpCookieTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/net/HttpCookieTest.java
@@ -5,9 +5,9 @@
* 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
@@ -949,6 +949,19 @@
assertEquals(0, cookie.getVersion());
}
+ // http://b/31039416. Android N+ checks current time in hasExpired.
+ // Repeated invocations of cookie.hasExpired() may return different results
+ // due to time passage.
+ // This was not the case in earlier android versions, where hasExpired
+ // was testing the value of max-age/expires at the time of cookie creation.
+ public void test_hasExpired_checksTime() throws Exception {
+ List<HttpCookie> list = HttpCookie.parse("Set-Cookie:name=test;Max-Age=1");
+ HttpCookie cookie = list.get(0);
+ assertFalse(cookie.hasExpired());
+ Thread.sleep(2000);
+ assertTrue(cookie.hasExpired());
+ }
+
/**
* java.net.HttpCookie#parse(String) on multiple threads
* Regression test for HARMONY-6307
diff --git a/ojluni/src/main/java/java/lang/invoke/Transformers.java b/ojluni/src/main/java/java/lang/invoke/Transformers.java
index d3966ce..f90bb22 100644
--- a/ojluni/src/main/java/java/lang/invoke/Transformers.java
+++ b/ojluni/src/main/java/java/lang/invoke/Transformers.java
@@ -23,6 +23,7 @@
import dalvik.system.EmulatedStackFrame;
import dalvik.system.EmulatedStackFrame.StackFrameReader;
import dalvik.system.EmulatedStackFrame.StackFrameWriter;
+import java.lang.reflect.Array;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import sun.invoke.util.Wrapper;
@@ -739,7 +740,7 @@
private static Object referenceArray(StackFrameReader reader, Class<?>[] ptypes,
Class<?> elementType, int offset, int length) {
- Object[] arityArray = new Object[length];
+ Object arityArray = Array.newInstance(elementType, length);
for (int i = 0; i < length; ++i) {
Class<?> argumentType = ptypes[i + offset];
Object o = null;
@@ -758,7 +759,7 @@
throw new ClassCastException(
o.getClass() + " not assignable to " + elementType);
}
- arityArray[i] = o;
+ Array.set(arityArray, i, o);
}
return arityArray;
}
diff --git a/ojluni/src/main/java/java/net/HttpCookie.java b/ojluni/src/main/java/java/net/HttpCookie.java
index e924f87..8aae078 100644
--- a/ojluni/src/main/java/java/net/HttpCookie.java
+++ b/ojluni/src/main/java/java/net/HttpCookie.java
@@ -108,7 +108,8 @@
public final String header;
//
- // Hold the creation time (in seconds) of the http cookie for later
+ // Android-changed: Fixed units, s/seconds/milliseconds/, in comment below.
+ // Hold the creation time (in milliseconds) of the http cookie for later
// expiration calculation
private final long whenCreated;
@@ -1006,12 +1007,18 @@
// Android-changed: Use HttpDate for date parsing,
// it accepts broader set of date formats.
// cookie.setMaxAge(cookie.expiryDate2DeltaSeconds(attrValue));
+ // Android-changed: Altered max age calculation to avoid setting
+ // it to MAX_AGE_UNSPECIFIED (-1) if "expires" is one second in past.
Date date = HttpDate.parse(attrValue);
+ long maxAgeInSeconds = 0;
if (date != null) {
- cookie.setMaxAge((date.getTime() - System.currentTimeMillis()) / 1000);
- } else {
- cookie.setMaxAge(0);
+ maxAgeInSeconds = (date.getTime() - cookie.whenCreated) / 1000;
+ // If "expires" is in the past, remove the cookie.
+ if (maxAgeInSeconds < 0) {
+ maxAgeInSeconds = 0;
+ }
}
+ cookie.setMaxAge(maxAgeInSeconds);
}
}
});