Skip to content

Adds cityOrNull & countryOrNull methods for cases when the IP is unkn…#147

Closed
LukeButters wants to merge 7 commits intomaxmind:masterfrom
LukeButters:master
Closed

Adds cityOrNull & countryOrNull methods for cases when the IP is unkn…#147
LukeButters wants to merge 7 commits intomaxmind:masterfrom
LukeButters:master

Conversation

@LukeButters
Copy link
Copy Markdown
Contributor

@LukeButters LukeButters commented Oct 4, 2019

…own. #28

Throwing exceptions is expensive and should generally be reserved for
exceptional circumstances. This change adds to the DatabaseReader support
for returning null instead of an exception when the IP address is not found.

This shows an example of the xOrNull solution to avoid the expensive exception. I wasn't sure if you wanted this on an interface, perhaps it should be in the the DatabaseProvider interface.

I did not return Optional as I assume that support for java7 is wanted.

…own. maxmind#28

Throwing exceptions is expensive and should generally be reserved for
exceptional circumstances. This change adds to the DatabaseReader support
for returning null instead of an exception when the IP address is not found.
}

/**
* Same as {@link #city(InetAddress)} but returns null when the IP is no in our database.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Same as {@link #city(InetAddress)} but returns null when the IP is no in our database.
* Same as {@link #city(InetAddress)} but returns null when the IP is not in our database.

@coveralls
Copy link
Copy Markdown

coveralls commented Oct 4, 2019

Coverage Status

Coverage decreased (-0.9%) to 82.164% when pulling 4dfca84 on LukeButters:master into 74bb901 on maxmind:master.

@oschwald
Copy link
Copy Markdown
Member

oschwald commented Oct 7, 2019

We are at a point where I think we can drop Java 7 support. As such, I'd prefer using Optional. We would also want to have a similar method for all database types.

@LukeButters
Copy link
Copy Markdown
Contributor Author

LukeButters commented Oct 7, 2019

@oschwald
I can change the methods to return Optional, what would you like the method names to be?
I assume that you want to keep the existing methods like city or country which throw the exception and have other methods which return Optional.
Do you want these methods on the DatabaseProvider interface?

@oschwald
Copy link
Copy Markdown
Member

oschwald commented Oct 8, 2019

Yes, we would like maintain backwards compatibility. I am not about the method names. In C#, these sort of alternate methods are common and they use the Try prefix. However, I am having a hard time thinking of similar examples in Java.

Luke Butters added 2 commits October 9, 2019 11:38
@LukeButters
Copy link
Copy Markdown
Contributor Author

OK added some changes, now all of those methods provided by DatabaseProvider have tryX versions which return an optional. I also added those methods to the interface. We also keep the old methods.

@LukeButters
Copy link
Copy Markdown
Contributor Author

jkd7 and jdk-ea seem to fail, The first one is expected I don't know what the second one is @oschwald

@oschwald
Copy link
Copy Markdown
Member

openjdk-ea is the Early Access version of 14. I glanced at it and it seems to be some minor javadoc issue unrelated to your changes. We explicitly allow failures on that build given that it is an early access version. For openjdk7, I think we can just remove these lines:

GeoIP2-java/.travis.yml

Lines 15 to 16 in 6477ec2

- jdk: openjdk7
dist: trusty

@LukeButters
Copy link
Copy Markdown
Contributor Author

OK I removed those lines.

@oschwald
Copy link
Copy Markdown
Member

This was merged manually. Thanks!

@oschwald oschwald closed this Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants