diff options
author | Michi Henning <michi@zeroc.com> | 2003-05-23 08:07:40 +0000 |
---|---|---|
committer | Michi Henning <michi@zeroc.com> | 2003-05-23 08:07:40 +0000 |
commit | 5c89803b442f059bd7444b286adb3e0a1c4afeca (patch) | |
tree | e79bae21964782dc9a89df7ae2d0985caa822c26 /java | |
parent | VC70 install improvements (diff) | |
download | ice-5c89803b442f059bd7444b286adb3e0a1c4afeca.tar.bz2 ice-5c89803b442f059bd7444b286adb3e0a1c4afeca.tar.xz ice-5c89803b442f059bd7444b286adb3e0a1c4afeca.zip |
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.
Diffstat (limited to 'java')
-rw-r--r-- | java/demo/Ice/value/Client.java | 46 | ||||
-rw-r--r-- | java/demo/Ice/value/InitialI.java | 6 | ||||
-rw-r--r-- | java/demo/Ice/value/Value.ice | 1 | ||||
-rw-r--r-- | java/src/Ice/ObjectHolder.java | 6 | ||||
-rw-r--r-- | java/src/Ice/ObjectImpl.java | 8 | ||||
-rw-r--r-- | java/src/IceInternal/BasicStream.java | 6 | ||||
-rw-r--r-- | java/src/IceInternal/Patcher.java | 3 |
7 files changed, 53 insertions, 23 deletions
diff --git a/java/demo/Ice/value/Client.java b/java/demo/Ice/value/Client.java index bf1a2711cd2..9058936804f 100644 --- a/java/demo/Ice/value/Client.java +++ b/java/demo/Ice/value/Client.java @@ -61,13 +61,25 @@ public class Client System.out.println(); System.out.println("Ok, this worked. Now let's try to transfer an object for a class"); - System.out.println("with operations, without installing a factory first. This should"); - System.out.println("give us a `no factory' exception."); + System.out.println("with operations as type Ice.Object. Because no factory is installed,"); + System.out.println("the class will be sliced to Ice.Object."); + System.out.println("[press enter]"); + readline(in); + + Ice.Object obj = initial.getPrinterAsObject(); + System.out.println("The type ID of the received object is \"" + obj.ice_id(null) + "\""); + assert(obj.ice_id(null).equals("::Ice::Object")); + + System.out.println(); + System.out.println("Yes, this worked. Now let's try to transfer an object for a class"); + System.out.println("with operations as type Printer, without installing a factory first."); + System.out.println("This should give us a `no factory' exception."); System.out.println("[press enter]"); readline(in); PrinterHolder printer = new PrinterHolder(); PrinterPrxHolder printerProxy = new PrinterPrxHolder(); + boolean gotException = false; try { initial.getPrinter(printer, printerProxy); @@ -75,7 +87,9 @@ public class Client catch(Ice.NoObjectFactoryException ex) { System.out.println("==> " + ex); + gotException = true; } + assert(gotException); System.out.println(); System.out.println("Yep, that's what we expected. Now let's try again, but with"); @@ -102,34 +116,27 @@ public class Client System.out.println(); System.out.println("Now we call the same method, but on the remote object. Watch the"); System.out.println("server's output."); - System.out.println("[press enter]"); + System.out.println("press enter]"); readline(in); printerProxy.value.printBackwards(); System.out.println(); System.out.println("Next, we transfer a derived object from the server as base"); - System.out.println("object. Since we didn't install a factory for the derived"); - System.out.println("class yet, we will get another `no factory' exception."); + System.out.println("object. Since we haven't yet installed a factory for the derived"); + System.out.println("class, the derived class (DerivedPrinter) is sliced"); + System.out.println("to its base class (Printer)."); System.out.println("[press enter]"); readline(in); - Printer derivedAsBase; - try - { - derivedAsBase = initial.getDerivedPrinter(); - assert(false); - } - catch(Ice.NoObjectFactoryException ex) - { - System.out.println("==> " + ex); - } + Printer derivedAsBase = initial.getDerivedPrinter(); + System.out.println("The type ID of the received object is \"" + derivedAsBase.ice_id(null) + "\""); + assert(derivedAsBase.ice_id(null).equals("::Printer")); System.out.println(); System.out.println("Now we install a factory for the derived class, and try again."); - System.out.println("We won't get a `no factory' exception anymore, but since we"); - System.out.println("receive the derived object as base object, we need to do a"); - System.out.println("dynamic_cast<> to get from the base to the derived object."); + System.out.println("Because we receive the derived object as base object,"); + System.out.println("we need to do a class cast to get from the base to the derived object."); System.out.println("[press enter]"); readline(in); @@ -138,7 +145,8 @@ public class Client derivedAsBase = initial.getDerivedPrinter(); DerivedPrinter derived = (DerivedPrinter)derivedAsBase; - System.out.println("==> dynamic_cast<> to derived object succeded"); + System.out.println("==> class cast to derived object succeded"); + System.out.println("The type ID of the received object is \"" + derived.ice_id(null) + "\""); System.out.println(); System.out.println("Let's print the message contained in the derived object, and"); diff --git a/java/demo/Ice/value/InitialI.java b/java/demo/Ice/value/InitialI.java index 2919ec10b64..a7a64a2660d 100644 --- a/java/demo/Ice/value/InitialI.java +++ b/java/demo/Ice/value/InitialI.java @@ -37,6 +37,12 @@ class InitialI extends Initial return _simple; } + public Ice.Object + getPrinterAsObject(Ice.Current current) + { + return _printer; + } + public void getPrinter(PrinterHolder impl, PrinterPrxHolder proxy, Ice.Current current) { diff --git a/java/demo/Ice/value/Value.ice b/java/demo/Ice/value/Value.ice index 3ef695aff55..4a69d6b6a7d 100644 --- a/java/demo/Ice/value/Value.ice +++ b/java/demo/Ice/value/Value.ice @@ -40,6 +40,7 @@ exception DerivedPrinterException class Initial { Simple getSimple(); + Object getPrinterAsObject(); void getPrinter(out Printer impl, out Printer* proxy); Printer getDerivedPrinter(); void throwDerivedPrinter() throws DerivedPrinterException; diff --git a/java/src/Ice/ObjectHolder.java b/java/src/Ice/ObjectHolder.java index 9d1ad91e088..5d88becf0b9 100644 --- a/java/src/Ice/ObjectHolder.java +++ b/java/src/Ice/ObjectHolder.java @@ -34,6 +34,12 @@ public final class ObjectHolder { value = v; } + + public String + type() + { + return Ice.ObjectImpl.ice_staticId(); + } } public Patcher diff --git a/java/src/Ice/ObjectImpl.java b/java/src/Ice/ObjectImpl.java index 551ae4de307..eec827b0217 100644 --- a/java/src/Ice/ObjectImpl.java +++ b/java/src/Ice/ObjectImpl.java @@ -198,7 +198,7 @@ public class ObjectImpl implements Object, java.lang.Cloneable { synchronized(_activeFacetMap) { - __os.writeTypeId("::Ice::Object"); + __os.writeTypeId(ice_staticId()); __os.startWriteSlice(); final int sz = _activeFacetMap.size(); __os.writeSize(sz); @@ -228,6 +228,12 @@ public class ObjectImpl implements Object, java.lang.Cloneable _activeFacetMap.put(__key, v); } + public String + type() + { + return ice_staticId(); + } + private String __key; } diff --git a/java/src/IceInternal/BasicStream.java b/java/src/IceInternal/BasicStream.java index c157d980dae..09e68ff2f9a 100644 --- a/java/src/IceInternal/BasicStream.java +++ b/java/src/IceInternal/BasicStream.java @@ -1116,7 +1116,7 @@ public class BasicStream while(true) { String id = readTypeId(); - if(id.equals("::Ice::Object")) + if(id.equals(Ice.ObjectImpl.ice_staticId())) { v = new Ice.ObjectImpl(); } @@ -1323,7 +1323,9 @@ public class BasicStream } catch(ClassCastException ex) { - throw new Ice.UnmarshalOutOfBoundsException(); + Ice.NoObjectFactoryException nof = new Ice.NoObjectFactoryException(); + nof.type = p.type(); + throw nof; } } diff --git a/java/src/IceInternal/Patcher.java b/java/src/IceInternal/Patcher.java index 11fdbf06adb..b5e30377bd0 100644 --- a/java/src/IceInternal/Patcher.java +++ b/java/src/IceInternal/Patcher.java @@ -17,4 +17,5 @@ package IceInternal; public interface Patcher { void patch(Ice.Object v); -}; + String type(); +} |