summaryrefslogtreecommitdiff
path: root/java
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2009-12-10 13:41:49 -0800
committerMark Spruiell <mes@zeroc.com>2009-12-10 13:41:49 -0800
commit47bc7e93cb03a077c0eef8a2cc871cead1212c00 (patch)
tree477aa3c5c77a5b458abc19b92c3ca12360c996a5 /java
parentSquashed commit of the following: (diff)
downloadice-47bc7e93cb03a077c0eef8a2cc871cead1212c00.tar.bz2
ice-47bc7e93cb03a077c0eef8a2cc871cead1212c00.tar.xz
ice-47bc7e93cb03a077c0eef8a2cc871cead1212c00.zip
bug 4355 - improve parse exception messages
Diffstat (limited to 'java')
-rw-r--r--java/src/Ice/ObjectAdapterI.java2
-rw-r--r--java/src/Ice/Util.java33
-rw-r--r--java/src/IceInternal/DefaultsAndOverrides.java2
-rw-r--r--java/src/IceInternal/EndpointFactoryManager.java2
-rw-r--r--java/src/IceInternal/OpaqueEndpointI.java38
-rw-r--r--java/src/IceInternal/ReferenceFactory.java71
-rw-r--r--java/src/IceInternal/TcpEndpointI.java28
-rw-r--r--java/src/IceInternal/UdpEndpointI.java61
-rw-r--r--java/src/IceSSL/EndpointI.java28
-rw-r--r--java/src/IceUtilInternal/StringUtil.java77
-rw-r--r--java/test/Ice/proxy/AllTests.java28
11 files changed, 234 insertions, 136 deletions
diff --git a/java/src/Ice/ObjectAdapterI.java b/java/src/Ice/ObjectAdapterI.java
index b4bd577a414..c0243872304 100644
--- a/java/src/Ice/ObjectAdapterI.java
+++ b/java/src/Ice/ObjectAdapterI.java
@@ -1211,7 +1211,7 @@ public final class ObjectAdapterI implements ObjectAdapter
if(endp == null)
{
Ice.EndpointParseException e = new Ice.EndpointParseException();
- e.str = s;
+ e.str = "invalid object adapter endpoint `" + s + "'";
throw e;
}
endpoints.add(endp);
diff --git a/java/src/Ice/Util.java b/java/src/Ice/Util.java
index dc4253eb627..04ea0dea312 100644
--- a/java/src/Ice/Util.java
+++ b/java/src/Ice/Util.java
@@ -252,7 +252,7 @@ public final class Util
// Extra unescaped slash found.
//
IdentityParseException ex = new IdentityParseException();
- ex.str = s;
+ ex.str = "unescaped backslash in identity `" + s + "'";
throw ex;
}
}
@@ -261,35 +261,42 @@ public final class Util
if(slash == -1)
{
- StringHolder token = new StringHolder();
- if(!IceUtilInternal.StringUtil.unescapeString(s, 0, s.length(), token))
+ ident.category = "";
+ try
+ {
+ ident.name = IceUtilInternal.StringUtil.unescapeString(s, 0, s.length());
+ }
+ catch(IllegalArgumentException e)
{
IdentityParseException ex = new IdentityParseException();
- ex.str = s;
+ ex.str = "invalid identity name `" + s + "': " + e.getMessage();
throw ex;
}
- ident.category = "";
- ident.name = token.value;
}
else
{
- StringHolder token = new StringHolder();
- if(!IceUtilInternal.StringUtil.unescapeString(s, 0, slash, token))
+ try
+ {
+ ident.category = IceUtilInternal.StringUtil.unescapeString(s, 0, slash);
+ }
+ catch(IllegalArgumentException e)
{
IdentityParseException ex = new IdentityParseException();
- ex.str = s;
+ ex.str = "invalid category in identity `" + s + "': " + e.getMessage();
throw ex;
}
- ident.category = token.value;
if(slash + 1 < s.length())
{
- if(!IceUtilInternal.StringUtil.unescapeString(s, slash + 1, s.length(), token))
+ try
+ {
+ ident.name = IceUtilInternal.StringUtil.unescapeString(s, slash + 1, s.length());
+ }
+ catch(IllegalArgumentException e)
{
IdentityParseException ex = new IdentityParseException();
- ex.str = s;
+ ex.str = "invalid name in identity `" + s + "': " + e.getMessage();
throw ex;
}
- ident.name = token.value;
}
else
{
diff --git a/java/src/IceInternal/DefaultsAndOverrides.java b/java/src/IceInternal/DefaultsAndOverrides.java
index 8946bf6f7b7..ce340c66e1b 100644
--- a/java/src/IceInternal/DefaultsAndOverrides.java
+++ b/java/src/IceInternal/DefaultsAndOverrides.java
@@ -108,7 +108,7 @@ public final class DefaultsAndOverrides
else
{
Ice.EndpointSelectionTypeParseException ex = new Ice.EndpointSelectionTypeParseException();
- ex.str = value;
+ ex.str = "illegal value `" + value + "'; expected `Random' or `Ordered'";
throw ex;
}
diff --git a/java/src/IceInternal/EndpointFactoryManager.java b/java/src/IceInternal/EndpointFactoryManager.java
index de816428863..50b5e8d2ac7 100644
--- a/java/src/IceInternal/EndpointFactoryManager.java
+++ b/java/src/IceInternal/EndpointFactoryManager.java
@@ -51,7 +51,7 @@ public final class EndpointFactoryManager
if(s.length() == 0)
{
Ice.EndpointParseException e = new Ice.EndpointParseException();
- e.str = str;
+ e.str = "value has no non-whitespace characters";
throw e;
}
diff --git a/java/src/IceInternal/OpaqueEndpointI.java b/java/src/IceInternal/OpaqueEndpointI.java
index f4c9a8e1f3a..c85e27fedea 100644
--- a/java/src/IceInternal/OpaqueEndpointI.java
+++ b/java/src/IceInternal/OpaqueEndpointI.java
@@ -30,7 +30,8 @@ final class OpaqueEndpointI extends EndpointI
String option = arr[i++];
if(option.length() != 2 || option.charAt(0) != '-')
{
- throw new Ice.EndpointParseException("opaque " + str);
+ throw new Ice.EndpointParseException("expected an endpoint option but found `" + option +
+ "' in endpoint `opaque " + str + "'");
}
String argument = null;
@@ -45,7 +46,8 @@ final class OpaqueEndpointI extends EndpointI
{
if(argument == null)
{
- throw new Ice.EndpointParseException("opaque " + str);
+ throw new Ice.EndpointParseException("no argument provided for -t option in endpoint `opaque "
+ + str + "'");
}
int t;
@@ -55,16 +57,22 @@ final class OpaqueEndpointI extends EndpointI
}
catch(NumberFormatException ex)
{
- throw new Ice.EndpointParseException("opaque " + str);
+ throw new Ice.EndpointParseException("invalid timeout value `" + argument +
+ "' in endpoint `opaque " + str + "'");
}
if(t < 0 || t > 65535)
{
- throw new Ice.EndpointParseException("opaque " + str);
+ throw new Ice.EndpointParseException("timeout value `" + argument +
+ "' out of range in endpoint `opaque " + str + "'");
}
_type = (short)t;
++topt;
+ if(topt > 1)
+ {
+ throw new Ice.EndpointParseException("multiple -t options in endpoint `opaque " + str + "'");
+ }
break;
}
@@ -72,30 +80,42 @@ final class OpaqueEndpointI extends EndpointI
{
if(argument == null)
{
- throw new Ice.EndpointParseException("opaque " + str);
+ throw new Ice.EndpointParseException("no argument provided for -v option in endpoint `opaque "
+ + str + "'");
}
for(int j = 0; j < argument.length(); ++j)
{
if(!IceUtilInternal.Base64.isBase64(argument.charAt(j)))
{
- throw new Ice.EndpointParseException("opaque " + str);
+ throw new Ice.EndpointParseException("invalid base64 character `" + argument.charAt(j) +
+ "' (ordinal " + ((int)argument.charAt(j)) +
+ ") in endpoint `opaque " + str + "'");
}
}
_rawBytes = IceUtilInternal.Base64.decode(argument);
++vopt;
+ if(vopt > 1)
+ {
+ throw new Ice.EndpointParseException("multiple -v options in endpoint `opaque " + str + "'");
+ }
break;
}
default:
{
- throw new Ice.EndpointParseException("opaque " + str);
+ throw new Ice.EndpointParseException("invalid option `" + option + "' in endpoint `opaque " +
+ str + "'");
}
}
}
- if(topt != 1 || vopt != 1)
+ if(topt != 1)
+ {
+ throw new Ice.EndpointParseException("no -t option in endpoint `opaque " + str + "'");
+ }
+ if(vopt != 1)
{
- throw new Ice.EndpointParseException("opaque " + str);
+ throw new Ice.EndpointParseException("no -v option in endpoint `opaque " + str + "'");
}
calcHashValue();
}
diff --git a/java/src/IceInternal/ReferenceFactory.java b/java/src/IceInternal/ReferenceFactory.java
index 30a236394ec..574c121b1e0 100644
--- a/java/src/IceInternal/ReferenceFactory.java
+++ b/java/src/IceInternal/ReferenceFactory.java
@@ -83,7 +83,7 @@ public final class ReferenceFactory
if(beg == -1)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "no non-whitespace characters found in `" + s + "'";
throw e;
}
@@ -96,7 +96,7 @@ public final class ReferenceFactory
if(end == -1)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "mismatched quotes around identity in `" + s + "'";
throw e;
}
else if(end == 0)
@@ -118,7 +118,7 @@ public final class ReferenceFactory
if(beg == end)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "no identity in `" + s + "'";
throw e;
}
@@ -148,7 +148,7 @@ public final class ReferenceFactory
else if(IceUtilInternal.StringUtil.findFirstNotOf(s, delim, end) != -1)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "invalid characters after identity in `" + s + "'";
throw e;
}
else
@@ -190,7 +190,7 @@ public final class ReferenceFactory
if(option.length() != 2 || option.charAt(0) != '-')
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "expected a proxy option but found `" + option + "' in `" + s + "'";
throw e;
}
@@ -211,7 +211,7 @@ public final class ReferenceFactory
if(end == -1)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "mismatched quotes around value for " + option + " option in `" + s + "'";
throw e;
}
else if(end == 0)
@@ -243,19 +243,21 @@ public final class ReferenceFactory
if(argument == null)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "no argument provided for -f option in `" + s + "'";
throw e;
}
- Ice.StringHolder facetH = new Ice.StringHolder();
- if(!IceUtilInternal.StringUtil.unescapeString(argument, 0, argument.length(), facetH))
+ try
+ {
+ facet = IceUtilInternal.StringUtil.unescapeString(argument, 0, argument.length());
+ }
+ catch(IllegalArgumentException ex)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "invalid facet in `" + s + "': " + ex.getMessage();
throw e;
}
- facet = facetH.value;
break;
}
@@ -264,7 +266,7 @@ public final class ReferenceFactory
if(argument != null)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "unexpected argument `" + argument + "' provided for -t option in `" + s + "'";
throw e;
}
mode = Reference.ModeTwoway;
@@ -276,7 +278,7 @@ public final class ReferenceFactory
if(argument != null)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "unexpected argument `" + argument + "' provided for -o option in `" + s + "'";
throw e;
}
mode = Reference.ModeOneway;
@@ -288,7 +290,7 @@ public final class ReferenceFactory
if(argument != null)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "unexpected argument `" + argument + "' provided for -O option in `" + s + "'";
throw e;
}
mode = Reference.ModeBatchOneway;
@@ -300,7 +302,7 @@ public final class ReferenceFactory
if(argument != null)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "unexpected argument `" + argument + "' provided for -d option in `" + s + "'";
throw e;
}
mode = Reference.ModeDatagram;
@@ -312,7 +314,7 @@ public final class ReferenceFactory
if(argument != null)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "unexpected argument `" + argument + "' provided for -D option in `" + s + "'";
throw e;
}
mode = Reference.ModeBatchDatagram;
@@ -324,7 +326,7 @@ public final class ReferenceFactory
if(argument != null)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "unexpected argument `" + argument + "' provided for -s option in `" + s + "'";
throw e;
}
secure = true;
@@ -334,7 +336,7 @@ public final class ReferenceFactory
default:
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "unknown option `" + option + "' in `" + s + "'";
throw e;
}
}
@@ -412,8 +414,9 @@ public final class ReferenceFactory
}
if(endpoints.size() == 0)
{
+ assert(!unknownEndpoints.isEmpty());
Ice.EndpointParseException e = new Ice.EndpointParseException();
- e.str = unknownEndpoints.get(0);
+ e.str = "invalid endpoint `" + unknownEndpoints.get(0) + "' in `" + s + "'";
throw e;
}
else if(unknownEndpoints.size() != 0 &&
@@ -439,7 +442,7 @@ public final class ReferenceFactory
if(beg == -1)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "missing adapter id in `" + s + "'";
throw e;
}
@@ -448,7 +451,7 @@ public final class ReferenceFactory
if(end == -1)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "mismatched quotes around adapter id in `" + s + "'";
throw e;
}
else if(end == 0)
@@ -470,24 +473,31 @@ public final class ReferenceFactory
if(end != s.length() && IceUtilInternal.StringUtil.findFirstNotOf(s, delim, end) != -1)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "invalid trailing characters after `" + s.substring(0, end + 1) + "' in `" + s + "'";
throw e;
}
-
- Ice.StringHolder token = new Ice.StringHolder();
- if(!IceUtilInternal.StringUtil.unescapeString(adapterstr, 0, adapterstr.length(), token) ||
- token.value.length() == 0)
+
+ try
+ {
+ adapter = IceUtilInternal.StringUtil.unescapeString(adapterstr, 0, adapterstr.length());
+ }
+ catch(IllegalArgumentException ex)
+ {
+ Ice.ProxyParseException e = new Ice.ProxyParseException();
+ e.str = "invalid adapter id in `" + s + "': " + ex.getMessage();
+ throw e;
+ }
+ if(adapter.length() == 0)
{
Ice.ProxyParseException e = new Ice.ProxyParseException();
- e.str = s;
+ e.str = "empty adapter id in `" + s + "'";
throw e;
}
- adapter = token.value;
return create(ident, facet, mode, secure, null, adapter, propertyPrefix);
}
Ice.ProxyParseException ex = new Ice.ProxyParseException();
- ex.str = s;
+ ex.str = "malformed proxy `" + s + "'";
throw ex;
}
@@ -782,7 +792,8 @@ public final class ReferenceFactory
}
else
{
- throw new Ice.EndpointSelectionTypeParseException(type);
+ throw new Ice.EndpointSelectionTypeParseException("illegal value `" + type +
+ "'; expected `Random' or `Ordered'");
}
}
diff --git a/java/src/IceInternal/TcpEndpointI.java b/java/src/IceInternal/TcpEndpointI.java
index 27618d8ccc5..f331068a9e8 100644
--- a/java/src/IceInternal/TcpEndpointI.java
+++ b/java/src/IceInternal/TcpEndpointI.java
@@ -46,7 +46,8 @@ final class TcpEndpointI extends EndpointI
String option = arr[i++];
if(option.length() != 2 || option.charAt(0) != '-')
{
- throw new Ice.EndpointParseException("tcp " + str);
+ throw new Ice.EndpointParseException("expected an endpoint option but found `" + option +
+ "' in endpoint `tcp " + str + "'");
}
String argument = null;
@@ -65,7 +66,8 @@ final class TcpEndpointI extends EndpointI
{
if(argument == null)
{
- throw new Ice.EndpointParseException("tcp " + str);
+ throw new Ice.EndpointParseException("no argument provided for -h option in endpoint `tcp "
+ + str + "'");
}
_host = argument;
@@ -76,7 +78,8 @@ final class TcpEndpointI extends EndpointI
{
if(argument == null)
{
- throw new Ice.EndpointParseException("tcp " + str);
+ throw new Ice.EndpointParseException("no argument provided for -p option in endpoint `tcp "
+ + str + "'");
}
try
@@ -85,12 +88,14 @@ final class TcpEndpointI extends EndpointI
}
catch(NumberFormatException ex)
{
- throw new Ice.EndpointParseException("tcp " + str);
+ throw new Ice.EndpointParseException("invalid port value `" + argument +
+ "' in endpoint `tcp " + str + "'");
}
if(_port < 0 || _port > 65535)
{
- throw new Ice.EndpointParseException("tcp " + str);
+ throw new Ice.EndpointParseException("port value `" + argument +
+ "' out of range in endpoint `tcp " + str + "'");
}
break;
@@ -100,7 +105,8 @@ final class TcpEndpointI extends EndpointI
{
if(argument == null)
{
- throw new Ice.EndpointParseException("tcp " + str);
+ throw new Ice.EndpointParseException("no argument provided for -t option in endpoint `tcp "
+ + str + "'");
}
try
@@ -109,7 +115,8 @@ final class TcpEndpointI extends EndpointI
}
catch(NumberFormatException ex)
{
- throw new Ice.EndpointParseException("tcp " + str);
+ throw new Ice.EndpointParseException("invalid timeout value `" + argument +
+ "' in endpoint `tcp " + str + "'");
}
break;
@@ -119,7 +126,8 @@ final class TcpEndpointI extends EndpointI
{
if(argument != null)
{
- throw new Ice.EndpointParseException("tcp " + str);
+ throw new Ice.EndpointParseException("unexpected argument `" + argument +
+ "' provided for -z option in `tcp " + str + "'");
}
_compress = true;
@@ -128,7 +136,7 @@ final class TcpEndpointI extends EndpointI
default:
{
- throw new Ice.EndpointParseException("tcp " + str);
+ throw new Ice.EndpointParseException("unknown option `" + option + "' in `tcp " + str + "'");
}
}
}
@@ -145,7 +153,7 @@ final class TcpEndpointI extends EndpointI
}
else
{
- throw new Ice.EndpointParseException("tcp " + str);
+ throw new Ice.EndpointParseException("`-h *' not valid for proxy endpoint `tcp " + str + "'");
}
}
diff --git a/java/src/IceInternal/UdpEndpointI.java b/java/src/IceInternal/UdpEndpointI.java
index 880eae25473..153b9f99a96 100644
--- a/java/src/IceInternal/UdpEndpointI.java
+++ b/java/src/IceInternal/UdpEndpointI.java
@@ -57,7 +57,8 @@ final class UdpEndpointI extends EndpointI
String option = arr[i++];
if(option.charAt(0) != '-')
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("expected an endpoint option but found `" + option +
+ "' in endpoint `udp " + str + "'");
}
String argument = null;
@@ -74,13 +75,15 @@ final class UdpEndpointI extends EndpointI
{
if(argument == null)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("no argument provided for -v option in endpoint `udp "
+ + str + "'");
}
int pos = argument.indexOf('.');
if(pos == -1)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("malformed protocol version `" + argument +
+ "' in endpoint `udp " + str + "'");
}
String majStr = argument.substring(0, pos);
@@ -94,12 +97,14 @@ final class UdpEndpointI extends EndpointI
}
catch(NumberFormatException ex)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("invalid protocol version `" + argument +
+ "' in endpoint `udp " + str + "'");
}
if(majVersion < 1 || majVersion > 255 || minVersion < 0 || minVersion > 255)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("range error in protocol version `" + argument +
+ "' in endpoint `udp " + str + "'");
}
if(majVersion != Protocol.protocolMajor)
@@ -119,13 +124,15 @@ final class UdpEndpointI extends EndpointI
{
if(argument == null)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("no argument provided for -e option in endpoint `udp "
+ + str + "'");
}
int pos = argument.indexOf('.');
if(pos == -1)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("malformed encoding version `" + argument +
+ "' in endpoint `udp " + str + "'");
}
String majStr = argument.substring(0, pos);
@@ -139,12 +146,14 @@ final class UdpEndpointI extends EndpointI
}
catch(NumberFormatException ex)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("invalid encoding version `" + argument +
+ "' in endpoint `udp " + str + "'");
}
if(majVersion < 1 || majVersion > 255 || minVersion < 0 || minVersion > 255)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("range error in encoding version `" + argument +
+ "' in endpoint `udp " + str + "'");
}
if(majVersion != Protocol.encodingMajor)
@@ -164,7 +173,8 @@ final class UdpEndpointI extends EndpointI
{
if(argument == null)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("no argument provided for -h option in endpoint `udp "
+ + str + "'");
}
_host = argument;
@@ -173,7 +183,8 @@ final class UdpEndpointI extends EndpointI
{
if(argument == null)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("no argument provided for -p option in endpoint `udp "
+ + str + "'");
}
try
@@ -182,19 +193,22 @@ final class UdpEndpointI extends EndpointI
}
catch(NumberFormatException ex)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("invalid port value `" + argument + "' in endpoint `udp " +
+ str + "'");
}
if(_port < 0 || _port > 65535)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("port value `" + argument +
+ "' out of range in endpoint `udp " + str + "'");
}
}
else if(option.equals("-c"))
{
if(argument != null)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("unexpected argument `" + argument +
+ "' provided for -c option in `udp " + str + "'");
}
_connect = true;
@@ -204,7 +218,8 @@ final class UdpEndpointI extends EndpointI
{
if(argument != null)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("unexpected argument `" + argument +
+ "' provided for -z option in `udp " + str + "'");
}
_compress = true;
@@ -214,7 +229,8 @@ final class UdpEndpointI extends EndpointI
{
if(argument == null)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("no argument provided for --interface option in endpoint `udp "
+ + str + "'");
}
_mcastInterface = argument;
@@ -223,7 +239,8 @@ final class UdpEndpointI extends EndpointI
{
if(argument == null)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("no argument provided for --ttl option in endpoint `udp "
+ + str + "'");
}
try
@@ -232,17 +249,19 @@ final class UdpEndpointI extends EndpointI
}
catch(NumberFormatException ex)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("invalid TTL value `" + argument + "' in endpoint `udp " +
+ str + "'");
}
if(_mcastTtl < 0)
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("TTL value `" + argument +
+ "' out of range in endpoint `udp " + str + "'");
}
}
else
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("unknown option `" + option + "' in `udp " + str + "'");
}
}
@@ -258,7 +277,7 @@ final class UdpEndpointI extends EndpointI
}
else
{
- throw new Ice.EndpointParseException("udp " + str);
+ throw new Ice.EndpointParseException("`-h *' not valid for proxy endpoint `udp " + str + "'");
}
}
diff --git a/java/src/IceSSL/EndpointI.java b/java/src/IceSSL/EndpointI.java
index 9c0282750da..97837176a0c 100644
--- a/java/src/IceSSL/EndpointI.java
+++ b/java/src/IceSSL/EndpointI.java
@@ -46,7 +46,8 @@ final class EndpointI extends IceInternal.EndpointI
String option = arr[i++];
if(option.length() != 2 || option.charAt(0) != '-')
{
- throw new Ice.EndpointParseException("ssl " + str);
+ throw new Ice.EndpointParseException("expected an endpoint option but found `" + option +
+ "' in endpoint `ssl " + str + "'");
}
String argument = null;
@@ -65,7 +66,8 @@ final class EndpointI extends IceInternal.EndpointI
{
if(argument == null)
{
- throw new Ice.EndpointParseException("ssl " + str);
+ throw new Ice.EndpointParseException("no argument provided for -h option in endpoint `ssl "
+ + str + "'");
}
_host = argument;
@@ -76,7 +78,8 @@ final class EndpointI extends IceInternal.EndpointI
{
if(argument == null)
{
- throw new Ice.EndpointParseException("ssl " + str);
+ throw new Ice.EndpointParseException("no argument provided for -p option in endpoint `ssl "
+ + str + "'");
}
try
@@ -85,12 +88,14 @@ final class EndpointI extends IceInternal.EndpointI
}
catch(NumberFormatException ex)
{
- throw new Ice.EndpointParseException("ssl " + str);
+ throw new Ice.EndpointParseException("invalid port value `" + argument +
+ "' in endpoint `ssl " + str + "'");
}
if(_port < 0 || _port > 65535)
{
- throw new Ice.EndpointParseException("ssl " + str);
+ throw new Ice.EndpointParseException("port value `" + argument +
+ "' out of range in endpoint `ssl " + str + "'");
}
break;
@@ -100,7 +105,8 @@ final class EndpointI extends IceInternal.EndpointI
{
if(argument == null)
{
- throw new Ice.EndpointParseException("ssl " + str);
+ throw new Ice.EndpointParseException("no argument provided for -t option in endpoint `ssl "
+ + str + "'");
}
try
@@ -109,7 +115,8 @@ final class EndpointI extends IceInternal.EndpointI
}
catch(NumberFormatException ex)
{
- throw new Ice.EndpointParseException("ssl " + str);
+ throw new Ice.EndpointParseException("invalid timeout value `" + argument +
+ "' in endpoint `ssl " + str + "'");
}
break;
@@ -119,7 +126,8 @@ final class EndpointI extends IceInternal.EndpointI
{
if(argument != null)
{
- throw new Ice.EndpointParseException("ssl " + str);
+ throw new Ice.EndpointParseException("unexpected argument `" + argument +
+ "' provided for -z option in `ssl " + str + "'");
}
_compress = true;
@@ -128,7 +136,7 @@ final class EndpointI extends IceInternal.EndpointI
default:
{
- throw new Ice.EndpointParseException("ssl " + str);
+ throw new Ice.EndpointParseException("unknown option `" + option + "' in `ssl " + str + "'");
}
}
}
@@ -145,7 +153,7 @@ final class EndpointI extends IceInternal.EndpointI
}
else
{
- throw new Ice.EndpointParseException("ssl " + str);
+ throw new Ice.EndpointParseException("`-h *' not valid for proxy endpoint `ssl " + str + "'");
}
}
diff --git a/java/src/IceUtilInternal/StringUtil.java b/java/src/IceUtilInternal/StringUtil.java
index befc624f425..137bb234e06 100644
--- a/java/src/IceUtilInternal/StringUtil.java
+++ b/java/src/IceUtilInternal/StringUtil.java
@@ -199,11 +199,22 @@ public final class StringUtil
}
private static char
- checkChar(char c)
+ checkChar(String s, int pos)
{
+ char c = s.charAt(pos);
if(!(c >= 32 && c <= 126))
{
- throw new IllegalArgumentException("illegal input character");
+ String msg;
+ if(pos > 0)
+ {
+ msg = "character after `" + s.substring(0, pos) + "'";
+ }
+ else
+ {
+ msg = "first character";
+ }
+ msg += " is not a printable ASCII character (ordinal " + (int)c + ")";
+ throw new IllegalArgumentException(msg);
}
return c;
}
@@ -223,13 +234,13 @@ public final class StringUtil
if(s.charAt(start) != '\\')
{
- c = checkChar(s.charAt(start++));
+ c = checkChar(s, start++);
}
else
{
if(start + 1 == end)
{
- throw new IllegalArgumentException("trailing backslash in argument");
+ throw new IllegalArgumentException("trailing backslash");
}
switch(s.charAt(++start))
{
@@ -279,7 +290,7 @@ public final class StringUtil
case '6':
case '7':
{
- int oct = 0;
+ int val = 0;
for(int j = 0; j < 3 && start < end; ++j)
{
int charVal = s.charAt(start++) - '0';
@@ -288,18 +299,19 @@ public final class StringUtil
--start;
break;
}
- oct = oct * 8 + charVal;
+ val = val * 8 + charVal;
}
- if(oct > 255)
+ if(val > 255)
{
- throw new IllegalArgumentException("octal value out of range");
+ String msg = "octal value \\" + Integer.toOctalString(val) + " (" + val + ") is out of range";
+ throw new IllegalArgumentException(msg);
}
- c = (char)oct;
+ c = (char)val;
break;
}
default:
{
- c = checkChar(s.charAt(start++));
+ c = checkChar(s, start++);
break;
}
}
@@ -324,42 +336,33 @@ public final class StringUtil
}
//
- // Remove escape sequences added by escapeString.
+ // Remove escape sequences added by escapeString. Throws IllegalArgumentException
+ // for an invalid input string.
//
- public static boolean
- unescapeString(String s, int start, int end, Ice.StringHolder result)
+ public static String
+ unescapeString(String s, int start, int end)
{
- if(start < 0)
- {
- throw new IllegalArgumentException("start offset must be >= 0");
- }
- if(end > s.length())
- {
- throw new IllegalArgumentException("end offset must <= s.length()");
- }
- if(start > end)
+ assert(start >= 0 && start <= end && end <= s.length());
+
+ StringBuilder sb = new StringBuilder(end - start);
+ decodeString(s, start, end, sb);
+ String decodedString = sb.toString();
+
+ byte[] arr = new byte[decodedString.length()];
+ for(int i = 0; i < arr.length; ++i)
{
- throw new IllegalArgumentException("start offset must <= end offset");
+ arr[i] = (byte)decodedString.charAt(i);
}
try
{
- StringBuilder sb = new StringBuilder(end - start);
- decodeString(s, start, end, sb);
- String decodedString = sb.toString();
-
- byte[] arr = new byte[decodedString.length()];
- for(int i = 0; i < arr.length; ++i)
- {
- arr[i] = (byte)decodedString.charAt(i);
- }
-
- result.value = new String(arr, 0, arr.length, "UTF8");
- return true;
+ return new String(arr, 0, arr.length, "UTF8");
}
- catch(java.lang.Exception ex)
+ catch(java.io.UnsupportedEncodingException ex)
{
- return false;
+ IllegalArgumentException e = new IllegalArgumentException("unsupported encoding");
+ e.initCause(ex);
+ throw e;
}
}
diff --git a/java/test/Ice/proxy/AllTests.java b/java/test/Ice/proxy/AllTests.java
index 39d772b08e9..678a0b9cf52 100644
--- a/java/test/Ice/proxy/AllTests.java
+++ b/java/test/Ice/proxy/AllTests.java
@@ -99,12 +99,34 @@ public class AllTests
test(b1.ice_getIdentity().name.equals("test\1114test"));
b1 = communicator.stringToProxy("test\\b\\f\\n\\r\\t\\'\\\"\\\\test");
- test(b1.ice_getIdentity().name.equals("test\b\f\n\r\t\'\"\\test") && b1.ice_getIdentity().category.length() == 0);
+ test(b1.ice_getIdentity().name.equals("test\b\f\n\r\t\'\"\\test") &&
+ b1.ice_getIdentity().category.length() == 0);
b1 = communicator.stringToProxy("category/test");
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.equals("category") &&
b1.ice_getAdapterId().length() == 0);
-
+
+ b1 = communicator.stringToProxy("");
+ test(b1 == null);
+ b1 = communicator.stringToProxy("\"\"");
+ test(b1 == null);
+ try
+ {
+ b1 = communicator.stringToProxy("\"\" test"); // Invalid trailing characters.
+ test(false);
+ }
+ catch(Ice.ProxyParseException ex)
+ {
+ }
+ try
+ {
+ b1 = communicator.stringToProxy("test:"); // Missing endpoint.
+ test(false);
+ }
+ catch(Ice.EndpointParseException ex)
+ {
+ }
+
b1 = communicator.stringToProxy("test@adapter");
test(b1.ice_getIdentity().name.equals("test") && b1.ice_getIdentity().category.length() == 0 &&
b1.ice_getAdapterId().equals("adapter"));
@@ -637,7 +659,7 @@ public class AllTests
Ice.ObjectPrx p1 = communicator.stringToProxy("test:opaque -t 1 -v CTEyNy4wLjAuMeouAAAQJwAAAA==");
String pstr = communicator.proxyToString(p1);
test(pstr.equals("test -t:tcp -h 127.0.0.1 -p 12010 -t 10000"));
-
+
// Working?
boolean ssl = communicator.getProperties().getProperty("Ice.Default.Protocol").equals("ssl");
if(!ssl)