From 5c89803b442f059bd7444b286adb3e0a1c4afeca Mon Sep 17 00:00:00 2001 From: Michi Henning Date: Fri, 23 May 2003 08:07:40 +0000 Subject: Fixed the bug that Benoit found yesterday in both ice and icej. (Zero-length sequence containing class elements caused an crash.) :Ice::Object). Obviously, this would cause an assertion failure or a {{{ClassCastException}}}. The solution is simply to force the down-cast in the generated patch function and to check whether the cast failed: if so, the class was sliced too much and we throw a {{{NoObjectFactoryException}}} as we should. (For Java, the exception is thrown from {{{BasicStream.readObject}}}, after catching a {{{ClassCastException}}}. For C++, the exception is thrown directly from the generated patch function.) :Ice::Object}}} and {{{::Printer}}}. Updated the code generator to correctly initialize the {{{type}}} member of a {{{NoObjectFactoryException}}} with the type ID of the type that wasn't found. (Unfortunately, this involved modifying {{{Parser.h}}}, so you will have to rebuild both ice and icej.) Added code generation for custom sequence types for icej. Generated code compiles and looks OK, but I haven't written tests yet, so there may still be a latent bug in this. --- cpp/src/Slice/JavaUtil.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'cpp/src/Slice/JavaUtil.cpp') diff --git a/cpp/src/Slice/JavaUtil.cpp b/cpp/src/Slice/JavaUtil.cpp index 8986ff98b3c..a5b55146e1f 100644 --- a/cpp/src/Slice/JavaUtil.cpp +++ b/cpp/src/Slice/JavaUtil.cpp @@ -990,10 +990,25 @@ Slice::JavaGenerator::writeSequenceMarshalUnmarshalCode(Output& out, out << nl << "for(int __i" << iter << " = 0; __i" << iter << " < __len" << iter << "; __i" << iter << "++)"; out << sb; - out << nl << origContentS << " __elem;"; + BuiltinPtr builtin = BuiltinPtr::dynamicCast(origContent); + if((builtin && builtin->kind() == Builtin::KindObject) || ClassDeclPtr::dynamicCast(origContent)) + { + out << nl << v << ".add(null);"; + ostringstream patchParams; + patchParams << v << ", __i" << iter; + writeMarshalUnmarshalCode(out, scope, seq->type(), "__elem", false, iter, false, + list(), patchParams.str()); + } + else + { + out << nl << origContentS << " __elem;"; + writeMarshalUnmarshalCode(out, scope, seq->type(), "__elem", false, iter, false); + } iter++; - writeMarshalUnmarshalCode(out, scope, seq->type(), "__elem", false, iter, false); - out << nl << v << ".add(__elem);"; + if((builtin && builtin->kind() != Builtin::KindObject) && !ClassDeclPtr::dynamicCast(origContent)) + { + out << nl << v << ".add(__elem);"; + } out << eb; } } -- cgit v1.2.3