19 Sep, 2013, THUFIR wrote in the 1st comment:
Votes: 0
bp                    backstab professor $*
br borrow $*
bs backstab student $*
bw backstab worshipper $*
c confuse $*
–More (22/103)–
ca consider acolyte $*
Exception in thread "Thread-3" java.lang.NullPointerException
at model.TelnetEventProcessor.ifs(TelnetEventProcessor.java:42)
at model.TelnetEventProcessor.parse(TelnetEventProcessor.java:24)
at telnet.TelnetConnection.update(TelnetConnection.java:78)
at java.util.Observable.notifyObservers(Observable.java:159)
at telnet.InputOutput$2.run(InputOutput.java:85)
^Cthufir@dur:~/NetBeansProjects/rainmaker$
thufir@dur:~/NetBeansProjects/rainmaker$



https://github.com/THUFIR/rainmaker/comm...



but isn't that exception caught??

private void ifs() {
log.fine("checking..");
if (string.contains("confusing the hell out of")) {
Pattern pattern = Pattern.compile("[\\w]+(?=\\.)"); //(\w+)\.
Matcher matcher = pattern.matcher(string);
String enemy = null;
GameData data = null;
while (matcher.find()) {
enemy = matcher.group();
}
try {
data = new GameData.Builder().enemy(enemy).build();
} catch (NullPointerException e) {
}
log.fine("new data object\t\t" + data.getEnemy());
setChanged();
notifyObservers(data);

} else if (string.contains("Enter 3-letter city code:")) {
log.fine("found enter city code");
} else {
}
}



I'm not sure what triggers this bug.

It only happens when I look at aliases, so something about "press more" or the content of the aliases themselves..?
19 Sep, 2013, THUFIR wrote in the 2nd comment:
Votes: 0
seems excessive, but at least doesn't crash:


bw                    backstab worshipper $*
c confuse $*
–More (22/103)–
ca consider acolyte $*
Sep 19, 2013 12:27:27 AM model.TelnetEventProcessor parse*
SEVERE: java.lang.NullPointerException

cc consider citizen $*



"fixed" by:

public void parse(String string) {
this.string = string;
try {
ifs();
} catch (NullPointerException npe) {
log.severe(npe.toString());
}
}



but I'm fairly sure that I already try/catch for NPE's, maybe not:

private void ifs() throws NullPointerException {
log.fine("checking..");
if (string.contains("confusing the hell out of")) {
Pattern pattern = Pattern.compile("[\\w]+(?=\\.)"); //(\w+)\.
Matcher matcher = pattern.matcher(string);
String enemy = null;
GameData data = null;
while (matcher.find()) {
enemy = matcher.group();
}
try {
data = new GameData.Builder().enemy(enemy).build();
} catch (NullPointerException e) {
}
log.fine("new data object\t\t" + data.getEnemy());
setChanged();
notifyObservers(data);

} else if (string.contains("Enter 3-letter city code:")) {
log.fine("found enter city code");
} else {
}
}
19 Sep, 2013, THUFIR wrote in the 3rd comment:
Votes: 0
just sloppy, I guess:

try {
data = new GameData.Builder().enemy(enemy).build();
log.fine("new data object\t\t" + data.getEnemy());
setChanged();
notifyObservers(data);
} catch (NullPointerException npe) {
log.severe(npe.toString());
}



I'm still curious why that particular string causes that NPE, however.
19 Sep, 2013, Kaz wrote in the 4th comment:
Votes: 0
If line 12 throws, which you indicate it does, then this line executes:

log.fine("new data object\t\t" + data.getEnemy());


data is null, since it wasn't assigned on line 12 above and it threw an exception before the assignment, then it too throws a NullPointerException.

Your fix appears to work by ensuring the logging statement only runs if the assignment was successful and didn't thrown an exception.
19 Sep, 2013, THUFIR wrote in the 5th comment:
Votes: 0
what was interesting was the it would work fine for combat, but when, in the game, I entered "alias" to get a list of aliases, it would choke, either on a particular alias or on "more", and crash. I never did try and figure out why, just kludged my way through try/catch…

I was in a hurry. I do want to go back and try to trace that string val to see which particular string was the problem, and why, but not at the moment.
0.0/5