Fix edge-case in gwt-rpc client deserialization

Extracting the stream version (before actually parsing it)
failed when the version ends up being the only element in a
concatenated array.

Bug: #9536
Bug-Link: https://github.com/gwtproject/gwt/issues/9536
Change-Id: I4faa225e7ef6c990f588277aa287731aa07c22a0
diff --git a/user/super/com/google/gwt/user/translatable/com/google/gwt/user/client/rpc/impl/ClientSerializationStreamReader.java b/user/super/com/google/gwt/user/translatable/com/google/gwt/user/client/rpc/impl/ClientSerializationStreamReader.java
index 246a7da..718b7cf 100644
--- a/user/super/com/google/gwt/user/translatable/com/google/gwt/user/client/rpc/impl/ClientSerializationStreamReader.java
+++ b/user/super/com/google/gwt/user/translatable/com/google/gwt/user/client/rpc/impl/ClientSerializationStreamReader.java
@@ -145,6 +145,10 @@
   private static int readVersion(String encodedString) {
     String versionStr =
         encodedString.substring(encodedString.lastIndexOf(",") + 1, encodedString.lastIndexOf("]"));
+    int pos = versionStr.lastIndexOf("[");
+    if (pos >= 0) {
+        versionStr = versionStr.substring(pos + 1);
+    }
     return Integer.parseInt(versionStr.trim());
   }
 
diff --git a/user/test/com/google/gwt/user/client/rpc/impl/WebModeClientSerializationStreamReaderTest.java b/user/test/com/google/gwt/user/client/rpc/impl/WebModeClientSerializationStreamReaderTest.java
index 7a5877d..bf0f90a 100644
--- a/user/test/com/google/gwt/user/client/rpc/impl/WebModeClientSerializationStreamReaderTest.java
+++ b/user/test/com/google/gwt/user/client/rpc/impl/WebModeClientSerializationStreamReaderTest.java
@@ -74,6 +74,25 @@
     assertTrue(Double.isNaN(reader.readDouble()));
   }
 
+  /**
+   * Tests edge-case where version is moved to single item in concatenated array.
+   *
+   * See https://github.com/gwtproject/gwt/issues/9536
+   */
+  public void testParsingVersion7ArrayConcats() throws SerializationException {
+    ClientSerializationStreamReader reader = new ClientSerializationStreamReader(null);
+
+    String encoded = "[42,[],0].concat([7])";
+
+    assertEquals(7, readVersion(encoded));
+
+    reader.prepareToRead(encoded);
+
+    assertEquals(7, reader.getVersion());
+
+    assertEquals(42, reader.readInt());
+  }
+
   private native int readVersion(String encoded)/*-{
     return @com.google.gwt.user.client.rpc.impl.ClientSerializationStreamReader::readVersion(Ljava/lang/String;)(encoded);
   }-*/;