danielmcclure / bitcoinj

Automatically exported from code.google.com/p/bitcoinj
Apache License 2.0
0 stars 1 forks source link

null pointer handling in PeerAddress #337

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
PeerAddress.addr and .services can be null.

However, this will lead to NPE in toString(), equals() and hashCode().

Here is one example of a user crash report:

java.lang.NullPointerException
at com.google.bitcoin.core.PeerAddress.hashCode(PeerAddress.java:248)
at java.util.HashMap.put(HashMap.java:390)
at java.util.HashSet.add(HashSet.java:95)
at com.google.bitcoin.core.PeerGroup.connectToAnyPeer(PeerGroup.java:479)
at com.google.bitcoin.core.PeerGroup.startUp(PeerGroup.java:508)
at 
com.google.common.util.concurrent.AbstractIdleService$1$1.run(AbstractIdleServic
e.java:43)
at java.lang.Thread.run(Thread.java:856)

Original issue reported on code.google.com by andreas....@gmail.com on 6 Mar 2013 at 7:56

GoogleCodeExporter commented 9 years ago
Do you know where those bad PeerAddresses come from? I've never seen that 
outside of your app, so I am assuming that when the trusted peer feature is in 
use you don't check whether the name was resolved correctly?

Original comment by hearn@google.com on 7 Mar 2013 at 10:04

GoogleCodeExporter commented 9 years ago
Indeed, all I do in my PeerDiscovery is

peers.add(new InetSocketAddress(trustedPeerHost, 
Constants.NETWORK_PARAMETERS.port));

I would expect this to be handled by bitcoinj, after all its not much different 
to a bad IP.

Anyways, just looking at the class there are constructors that don't set .addr 
and .services so we can't avoid they are null. Thus, toString(), equals() and 
hashCode() should handle this case.

Original comment by andreas....@gmail.com on 7 Mar 2013 at 10:13

GoogleCodeExporter commented 9 years ago
[continuing from 338] ...still I think the null handling should be improved, 
but its probably low prio.

Original comment by andreas....@gmail.com on 7 Mar 2013 at 11:07