diff --git a/lib/xdrgen/generators/java.rb b/lib/xdrgen/generators/java.rb index 476c1d754..2fea98f3c 100644 --- a/lib/xdrgen/generators/java.rb +++ b/lib/xdrgen/generators/java.rb @@ -3,6 +3,8 @@ module Xdrgen module Generators + MAX_SIZE = (2 ** 31) - 1 + class Java < Xdrgen::Generators::Base def generate @@ -807,7 +809,7 @@ def decode_type(decl) when AST::Typespecs::Bool ; "stream.readInt() == 1 ? true : false" when AST::Typespecs::String ; - "XdrString.decode(stream, #{decl.size})" + "XdrString.decode(stream, #{decl.size || MAX_SIZE})" when AST::Typespecs::Simple ; "#{name decl.type.resolved_type}.decode(stream)" when AST::Concerns::NestedDefinition ; diff --git a/spec/output/generator_spec_java/struct.x/MyStruct.java b/spec/output/generator_spec_java/struct.x/MyStruct.java index 69cde5e57..e55cf60fb 100644 --- a/spec/output/generator_spec_java/struct.x/MyStruct.java +++ b/spec/output/generator_spec_java/struct.x/MyStruct.java @@ -76,7 +76,7 @@ public static MyStruct decode(XdrDataInputStream stream) throws IOException { int someOpaquesize = 10; decodedMyStruct.someOpaque = new byte[someOpaquesize]; stream.read(decodedMyStruct.someOpaque, 0, someOpaquesize); - decodedMyStruct.someString = XdrString.decode(stream, ); + decodedMyStruct.someString = XdrString.decode(stream, 2147483647); decodedMyStruct.maxString = XdrString.decode(stream, 100); return decodedMyStruct; } diff --git a/spec/output/generator_spec_java/test.x/Str2.java b/spec/output/generator_spec_java/test.x/Str2.java index a3a3a6658..182bf8d62 100644 --- a/spec/output/generator_spec_java/test.x/Str2.java +++ b/spec/output/generator_spec_java/test.x/Str2.java @@ -39,7 +39,7 @@ public void encode(XdrDataOutputStream stream) throws IOException { } public static Str2 decode(XdrDataInputStream stream) throws IOException { Str2 decodedStr2 = new Str2(); - decodedStr2.str2 = XdrString.decode(stream, ); + decodedStr2.str2 = XdrString.decode(stream, 2147483647); return decodedStr2; }