Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception in AppContext init throws NPE #654

Closed
treuherz opened this issue May 7, 2019 · 1 comment
Closed

Exception in AppContext init throws NPE #654

treuherz opened this issue May 7, 2019 · 1 comment
Milestone

Comments

@treuherz
Copy link
Contributor

treuherz commented May 7, 2019

When AppContext initialises, it has some exception handling if it's unable to determine a host address.

private static String initialiseInstanceAddress() {
String reaperInstanceAddress;
try {
reaperInstanceAddress = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
LOG.warn("Cannot get instance address", e);
reaperInstanceAddress = DEFAULT_INSTANCE_ADDRESS;
}
return reaperInstanceAddress;
}

I'm getting a NullPointerException on Line 58, which I think is because, above...
public static final String REAPER_INSTANCE_ADDRESS = initialiseInstanceAddress();
private static final String DEFAULT_INSTANCE_ADDRESS = "127.0.0.1";
private static final Logger LOG = LoggerFactory.getLogger(AppContext.class);

the logger isn't initialised till after this function runs.

I may have misunderstood what's going on here, but this seems like a simple oversight in the ordering. Happy to submit a PR to fix if you agree on the cause, but not sure how best to set up a test case.

@adejanovski
Copy link
Contributor

oh wow, that is silly 😅

Totally agree on the cause and happy to take that PR. Not sure how to test this either though...

treuherz added a commit to treuherz/cassandra-reaper that referenced this issue Jun 3, 2019
Previously, `initialiseInstanceAddress()` was called before `LOG` and `DEFAULT_INSTANCE_ADDRESS` were initialised, but relied on both of them, so threw an NPE instead of correctly assigning the default and starting up.

Fixes thelastpickle#654
@michaelsembwever michaelsembwever added this to the 1.4.5 milestone Jun 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants