aboutsummaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorkenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2009-08-07 21:02:02 +0000
committerkenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2009-08-07 21:02:02 +0000
commit68996fc874300337ec7349f50d0b1cbb3a6f1bec (patch)
treefd0f9a7b63b00dc0bc2898e6d44913dd95150423 /java
parent445f1023e1159212c65cb6c27c4f0a3121248a79 (diff)
downloadprotobuf-68996fc874300337ec7349f50d0b1cbb3a6f1bec.tar.gz
protobuf-68996fc874300337ec7349f50d0b1cbb3a6f1bec.tar.bz2
protobuf-68996fc874300337ec7349f50d0b1cbb3a6f1bec.zip
Gigantic descriptors shouldn't overflow the Java string literal size limit.
Diffstat (limited to 'java')
-rw-r--r--java/pom.xml1
-rw-r--r--java/src/main/java/com/google/protobuf/Descriptors.java12
-rw-r--r--java/src/test/java/com/google/protobuf/DescriptorsTest.java8
3 files changed, 19 insertions, 2 deletions
diff --git a/java/pom.xml b/java/pom.xml
index 13208104..91874e79 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -112,6 +112,7 @@
<arg value="../src/google/protobuf/unittest_lite.proto" />
<arg value="../src/google/protobuf/unittest_import_lite.proto" />
<arg value="../src/google/protobuf/unittest_lite_imports_nonlite.proto" />
+ <arg value="../src/google/protobuf/unittest_enormous_descriptor.proto" />
</exec>
</tasks>
<testSourceRoot>target/generated-test-sources</testSourceRoot>
diff --git a/java/src/main/java/com/google/protobuf/Descriptors.java b/java/src/main/java/com/google/protobuf/Descriptors.java
index df934bb4..0c162d5d 100644
--- a/java/src/main/java/com/google/protobuf/Descriptors.java
+++ b/java/src/main/java/com/google/protobuf/Descriptors.java
@@ -244,7 +244,8 @@ public final class Descriptors {
* encoded in protocol buffer wire format.
*/
public static void internalBuildGeneratedFileFrom(
- final String descriptorData, final FileDescriptor[] dependencies,
+ final String[] descriptorDataParts,
+ final FileDescriptor[] dependencies,
final InternalDescriptorAssigner descriptorAssigner) {
// Hack: We can't embed a raw byte array inside generated Java code
// (at least, not efficiently), but we can embed Strings. So, the
@@ -255,9 +256,16 @@ public final class Descriptors {
// serialized form. So, if we convert it to bytes in ISO-8859-1, we
// should get the original bytes that we want.
+ // descriptorData may contain multiple strings in order to get around the
+ // Java 64k string literal limit.
+ StringBuilder descriptorData = new StringBuilder();
+ for (String part : descriptorDataParts) {
+ descriptorData.append(part);
+ }
+
final byte[] descriptorBytes;
try {
- descriptorBytes = descriptorData.getBytes("ISO-8859-1");
+ descriptorBytes = descriptorData.toString().getBytes("ISO-8859-1");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(
"Standard encoding ISO-8859-1 not supported by JVM.", e);
diff --git a/java/src/test/java/com/google/protobuf/DescriptorsTest.java b/java/src/test/java/com/google/protobuf/DescriptorsTest.java
index 6fa56267..c5c38b27 100644
--- a/java/src/test/java/com/google/protobuf/DescriptorsTest.java
+++ b/java/src/test/java/com/google/protobuf/DescriptorsTest.java
@@ -397,4 +397,12 @@ public class DescriptorsTest extends TestCase {
assertEquals(values1[i].toString(), values2[i].toString());
}
}
+
+ public void testEnormousDescriptor() throws Exception {
+ // The descriptor for this file is larger than 64k, yet it did not cause
+ // a compiler error due to an over-long string literal.
+ assertTrue(
+ UnittestEnormousDescriptor.getDescriptor()
+ .toProto().getSerializedSize() > 65536);
+ }
}