[JAVA-1625] Document that MongoClient no longer throws UnknownHostException Created: 20/Jan/15 Updated: 26/Jan/16 Resolved: 20/Jan/15 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Documentation |
| Affects Version/s: | 2.12.3 |
| Fix Version/s: | 2.13.0, 3.0.0 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Konrad Slepoy | Assignee: | Jeffrey Yemin |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
This code does not throw an UnknownHostException like older versions. There is no attempt to resolve an ip address of the host using the java library InetAddress.getByName like in 2.11 versions. |
| Comments |
| Comment by Githook User [ 30/Jan/15 ] | |||
|
Author: {u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}Message: Removed errant declaration of UnknownHostException from some Mongo constructors | |||
| Comment by Githook User [ 20/Jan/15 ] | |||
|
Author: {u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}Message: Removed errant declaration of UnknownHostException from some Mongo constructors | |||
| Comment by Githook User [ 20/Jan/15 ] | |||
|
Author: {u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}Message: Updated Javadoc for MongoClient, Mongo, and ServerAddress constructors to indicate that UnknownHostException and MongoException | |||
| Comment by Jeffrey Yemin [ 20/Jan/15 ] | |||
|
Yes, understood, so for 2.13 we will just update the Javadoc to say this:
and make sure it's removed entirely in 3.0. | |||
| Comment by Konrad Slepoy [ 20/Jan/15 ] | |||
|
public MongoClient(String host, | |||
| Comment by Konrad Slepoy [ 20/Jan/15 ] | |||
|
The method signature says that it throws it though. So since the method says throws UnknownHostException we thought that if we pass an invalid host name an exception will be thrown. | |||
| Comment by Jeffrey Yemin [ 20/Jan/15 ] | |||
|
It's a compiler error to catch a checked exception that isn't thrown. | |||
| Comment by Konrad Slepoy [ 20/Jan/15 ] | |||
|
Sounds good to me. I think people might think that they are safe catching an exception that isn't thrown. Then an exception will pop up later and they'll be confused. I'm just a basic software developer though so whatever you think. | |||
| Comment by Jeffrey Yemin [ 20/Jan/15 ] | |||
|
How about a comment on the @throws javadoc for those methods saying that the driver no longer throws them? | |||
| Comment by Konrad Slepoy [ 20/Jan/15 ] | |||
|
Right that makes sense. I guess you can't be perfect there... is there any way to let people know who are using the method so they don't run into the same issue. It is definitely broken. | |||
| Comment by Jeffrey Yemin [ 20/Jan/15 ] | |||
|
I agree it's confusing, but there was a tradeoff involved. Although removing a checked exception from a method signature does not break binary compatibility, it does break source compatibility, and we were loathe to do that in a minor release, which is why we are waiting until 3.0 to do it. | |||
| Comment by Konrad Slepoy [ 20/Jan/15 ] | |||
|
I see, I see. I'm still confused as to why the method still said throws UnknownHostException if there is no exception ever thrown. I don't think that the constructor should indicate that it throws an exception if it doesn't-- it's misleading. | |||
| Comment by Jeffrey Yemin [ 20/Jan/15 ] | |||
|
Hi Konrad, This in an intentional change in behavior, but one that in retrospect we should have documented better. Note that in the 3.0.x branch neither ServerAddress nor MongoClient constructors throw this exception any longer. As a result, if there is a DNS issue with any members of the seed list, the driver won't throw an exception until the application attempts to use the MongoClient to perform an operation against the server, and in some cases you won't even get an exception whereas before you would have. For example, let's say you call the MongoClient constructor like this:
So long as at least one member of the seed list resolves in DNS, the application will be able to connect to the cluster, whereas prior to 2.12 the driver would have thrown an UnknownHostException. If you truly want fail-fast behavior, you'll have to implement it yourself by resolving each seed list member in the application by, for example, calling com.mongodb.ServerAddress#getSocketAddress. |