Reputation: 47
I am using mongo-java-driver-2.12.4
import com.mongodb.MongoClient;
import java.net.UnknownHostException;
class Test{
public static void main(String args[]){
try{
MongoClient mc = new MongoClient("hello",27110);
}catch(UnknownHostException e){
System.out.println("this is unknown");
}
System.out.println("whhaattt");
}
}
Any sane person would say that the output of this code segment should be "this is unknown". It isn't for me for some reason. It is "whhaattt". Why? I am completely stumped.
Edit: So "hello" was resolved on the internal network, but if I put a different value like 1290310923809132 in place of "hello" still no exception is thrown. However the InetAddress.getByName() method does throw an UnknownHostException when ran.
Upvotes: 1
Views: 317
Reputation: 47
So this actually is a bug! I submitted it to the MongoDB bug tracker and they said that they changed it starting in 2.12.x versions; however, they did not remove the "throws UnknownHostException" stub. They added a comment to the javadoc stating that the exception is no longer thrown... which means that you can have an invalid MongoClient object. Removing this exception would break source compatibility--> even though binary compatibility would be ok.
Upvotes: 1