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

containsIgnoreCase throws NPE #243

Open
larsrc opened this issue Nov 14, 2011 · 3 comments
Open

containsIgnoreCase throws NPE #243

larsrc opened this issue Nov 14, 2011 · 3 comments

Comments

@larsrc
Copy link

larsrc commented Nov 14, 2011

The implementation of containsIgnoreCase at https://github.com/makerbot/ReplicatorG/blob/master/src/replicatorg/app/ui/MainWindow.java#L1255 throws a NullPointerException:

14/11/2011 19:22:36 [0x0-0x5a05a].org.replicatorg.app[2587] Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
14/11/2011 19:22:36 [0x0-0x5a05a].org.replicatorg.app[2587] at java.util.regex.Matcher.getTextLength(Matcher.java:1140)
14/11/2011 19:22:36 [0x0-0x5a05a].org.replicatorg.app[2587] at java.util.regex.Matcher.reset(Matcher.java:291)
14/11/2011 19:22:36 [0x0-0x5a05a].org.replicatorg.app[2587] at java.util.regex.Matcher.(Matcher.java:211)
14/11/2011 19:22:36 [0x0-0x5a05a].org.replicatorg.app[2587] at java.util.regex.Pattern.matcher(Pattern.java:888)
14/11/2011 19:22:36 [0x0-0x5a05a].org.replicatorg.app[2587] at replicatorg.app.ui.MainWindow$MachineMenuListener.containsIgnoreCase(MainWindow.java:1256)
14/11/2011 19:22:36 [0x0-0x5a05a].org.replicatorg.app[2587] at replicatorg.app.ui.MainWindow$MachineMenuListener.actionPerformed(MainWindow.java:1276)

This probably happens when there has been a machine with a null name. It gets stored in the prefs, and all attempts at updating it causes a NPE because of the check at line 1277.

I am also curious to hear why you think making a containsIgnoreCase that compiles a regular expression at every call is quicker than the built-in one.

@FarMcKon
Copy link
Contributor

Excellent catch.

I'm not a java programmer by trade, so I'm not familiar with what you are calling 'the built-in one'. A function built into java String? Coming from python/C/C++ land, I'm use to using Regular Expression modules to do that kind of matching. From what you are saying, I guess String has something built-in to do a similar function? When you are use to using a hammer, all problems look like nails, etc.

I'll hit the docs now to see what I can dig up, but if that 'built in one' is something obscure, drop me a note please.

Thanks for pointing out that bug, and sorry if that's prevented you from saving/storing updates. I'll get that fixed and into our repo as soon as I get a chance, and I'll drop you a note when it's fixed.

@FarMcKon
Copy link
Contributor

Hmm. I see a string function for 'compareIgnoreCase', and 'contains', but not containsIgnoreCase function. Based on that (and a quick google search or two) I'm sticking with the 'http://stackoverflow.com/questions/86780/is-the-contains-method-in-java-lang-string-case-sensitive' solution for now. If you can suggest a better solution, I'd be glad to roll it in, or you can just send a pull request and I'll merge in your solution.

@larsrc
Copy link
Author

larsrc commented Nov 15, 2011

You're right, I was conflating those two methods on String. It's kinda stupid there's not containsIgnoreCase.

Thanks you for the fix, that's a lot easier to read.

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

No branches or pull requests

2 participants