summaryrefslogtreecommitdiffstats
path: root/luni/src/main/java
diff options
context:
space:
mode:
authorAndreas Gampe <agampe@google.com>2015-04-10 15:36:34 -0700
committerAndreas Gampe <agampe@google.com>2015-04-10 15:36:34 -0700
commit8307aa0a24626f248a670118aad49793300337e8 (patch)
tree6b4d455f691055785a545c30bb75b5a2522cf874 /luni/src/main/java
parent2b4f5b84dbe28fc5eeabb85d1ca3b096e8b8d450 (diff)
downloadlibcore-8307aa0a24626f248a670118aad49793300337e8.zip
libcore-8307aa0a24626f248a670118aad49793300337e8.tar.gz
libcore-8307aa0a24626f248a670118aad49793300337e8.tar.bz2
Libcore: Make Date compile-time initializable
Move CREATION_YEAR to a static inner class. Bug: 19542228 Change-Id: I3db699f8ad661305f5255ee730faeb21c2861dde
Diffstat (limited to 'luni/src/main/java')
-rw-r--r--luni/src/main/java/java/util/Date.java7
1 files changed, 5 insertions, 2 deletions
diff --git a/luni/src/main/java/java/util/Date.java b/luni/src/main/java/java/util/Date.java
index b4de055..d45c971 100644
--- a/luni/src/main/java/java/util/Date.java
+++ b/luni/src/main/java/java/util/Date.java
@@ -47,7 +47,10 @@ public class Date implements Serializable, Cloneable, Comparable<Date> {
private static final long serialVersionUID = 7523967970034938905L;
// Used by parse()
- private static final int CREATION_YEAR = new Date().getYear();
+ // Keep in a static inner class to allow compile-time initialization of Date.
+ private static class CreationYear {
+ private static final int VALUE = new Date().getYear();
+ }
private transient long milliseconds;
@@ -539,7 +542,7 @@ public class Date implements Serializable, Cloneable, Comparable<Date> {
if (second == -1) {
second = 0;
}
- if (year < (CREATION_YEAR - 80)) {
+ if (year < (CreationYear.VALUE - 80)) {
year += 2000;
} else if (year < 100) {
year += 1900;