From 87c36ebf6734f16f8ec6ff70a15bb769cfdb1ab8 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 29 Mar 2011 23:56:36 +0000 Subject: [PATCH] Improvements in comments. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6553 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/main/java/com/threerings/io/Streamer.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/threerings/io/Streamer.java b/src/main/java/com/threerings/io/Streamer.java index 1f1dc479a..149e8b761 100644 --- a/src/main/java/com/threerings/io/Streamer.java +++ b/src/main/java/com/threerings/io/Streamer.java @@ -459,18 +459,17 @@ public abstract class Streamer // obtain the constructor we'll use to create instances if (!isClosure) { - // local our zero argument constructor - _ctorArgs = ArrayUtil.EMPTY_OBJECT; + // locate our zero argument constructor for (Constructor ctor : _target.getDeclaredConstructors()) { if (ctor.getParameterTypes().length == 0) { _ctor = ctor; break; } } + _ctorArgs = ArrayUtil.EMPTY_OBJECT; } else { - // a closure should have only one constructor, and we're going to pass bogus - // arguments to it (because unstreaming will take care of further initialization) + // a closure should have only one constructor Constructor[] ctors = _target.getDeclaredConstructors(); if (ctors.length > 1) { throw new RuntimeException("Streamable closure classes must have only " + @@ -478,6 +477,9 @@ public abstract class Streamer } _ctor = ctors[0]; _ctor.setAccessible(true); + + // we pass bogus arguments to it (because unstreaming will overwrite our bogus + // values with the real values) Class[] ptypes = _ctor.getParameterTypes(); _ctorArgs = new Object[ptypes.length]; for (int ii = 0; ii < ptypes.length; ii++) { @@ -485,6 +487,8 @@ public abstract class Streamer _ctorArgs[ii] = ZEROS.get(ptypes[ii]); } } + + // make sure we found a constructor if (_ctor == null) { throw new RuntimeException("Unable to find applicable ctor " + "[class=" + _target.getName() + "]");