Merge "Fix error index of unparsed timezone name."
diff --git a/luni/src/test/java/libcore/java/text/SimpleDateFormatTest.java b/luni/src/test/java/libcore/java/text/SimpleDateFormatTest.java
index b95f9fe..20fa986 100644
--- a/luni/src/test/java/libcore/java/text/SimpleDateFormatTest.java
+++ b/luni/src/test/java/libcore/java/text/SimpleDateFormatTest.java
@@ -557,4 +557,30 @@
         dateFormat.setTimeZone(UTC);
         assertEquals("UTC", dateFormat.format(new Date(0)));
     }
+
+    // http://b/35134326
+    public void testTimeZoneParsingErrorIndex() {
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy z", Locale.ENGLISH);
+
+        checkTimeZoneParsingErrorIndex(dateFormat);
+    }
+
+    // http://b/35134326
+    public void testTimeZoneParsingErrorIndexWithZoneStrings() {
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy z", Locale.ENGLISH);
+        // Force legacy code path by using zone strings.
+        DateFormatSymbols dfs = dateFormat.getDateFormatSymbols();
+        dfs.setZoneStrings(dfs.getZoneStrings());
+        dateFormat.setDateFormatSymbols(dfs);
+
+        checkTimeZoneParsingErrorIndex(dateFormat);
+    }
+
+    private void checkTimeZoneParsingErrorIndex(SimpleDateFormat dateFormat) {
+        ParsePosition pos = new ParsePosition(0);
+        Date parsed;
+        parsed = dateFormat.parse("2000 foobar", pos);
+        assertNull(parsed);
+        assertEquals("Wrong error index", 5, pos.getErrorIndex());
+    }
 }
diff --git a/ojluni/src/main/java/java/text/SimpleDateFormat.java b/ojluni/src/main/java/java/text/SimpleDateFormat.java
index de2a93e..700d5ca 100644
--- a/ojluni/src/main/java/java/text/SimpleDateFormat.java
+++ b/ojluni/src/main/java/java/text/SimpleDateFormat.java
@@ -1821,7 +1821,7 @@
             }
             if (bestMatch == null) {
                 // No match found, return error.
-                return 0;
+                return -start;
             }
         }
 
@@ -1926,7 +1926,7 @@
             }
             return (start + zoneNames[nameIndex].length());
         }
-        return 0;
+        return -start;
     }
 
     /**