0

A user of an app I wrote recently discovered a crash caused by an empty string being passed to Float.valueOf(String s). I assumed that since Android Studio warned me about other unchecked exceptions that it would warn me about all of them.

I went to the inspections settings and searched for "exception" but I couldn't find a setting to warn about all exceptions. Is there a way to make Android Studio warn me about all unchecked exceptions or otherwise discover these kind of bugs at compile time rather than runtime?

Ryan1729
  • 940
  • 7
  • 25
  • Unfortunately no, the Java type system is not strong enough to express such constraints. – Margaret Bloom Nov 22 '16 at 09:07
  • And [this question](http://stackoverflow.com/questions/36051508/is-there-any-easy-way-to-see-what-exceptions-a-kotlin-function-throws) suggests that this is a problem with Kotlin too. You'd think the standard lib could be special cased by the IDE at least though. – Ryan1729 Nov 22 '16 at 09:33
  • I don't have an exact answer, but you could have a look at [Annotations](https://developer.android.com/studio/write/annotations.html) and probably [@Size(min=1)](https://developer.android.com/studio/write/annotations.html#value-constraint) could be used to check that a `String` isn't empty. But of course in the case of `Float.valueOf()` you should have a try-catch block around it to catch the `NumberFormatException` and it would cover an empty `String` too. – Markus Kauppinen Nov 22 '16 at 09:55

0 Answers0