Java-Exception when trying to get config with default value
When requesting a configuration option that is set to a 'default' value semantically different from an empty string, i.e. Tor replies with a reply line of the form: "250 keyword", the Java Tor controller throws the following exception:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at java.lang.String.substring(Unknown Source) at net.freehaven.tor.control.TorControlConnection1.getConf(TorControlConnection1.java:325) at net.freehaven.tor.control.TorControlConnection.getConf(TorControlConnection.java:148)
An example for this is requesting the configuration for "DirServer" without having specified such an option in the configuration file. The result from Tor is just "DirServer", not "DirServer=nodeXY...".
The explanation is that the following code (from TorControlConnection1) assumes that every line is formatted as "key=value" which is not the case:
for (Iterator it = lst.iterator(); it.hasNext(); ) { String kv = ((ReplyLine) it.next()).msg; int idx = kv.indexOf('='); result.add(new ConfigEntry(kv.substring(0, idx), kv.substring(idx+1))); }
A possible solution could be to create and add a ConfigEntry only if idx != -1. At least, this works for DirServer.
[Automatically added by flyspray2trac: Operating System: All]