• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Getting Error on Non Number

 
Ranch Hand
Posts: 2259
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try it figure out why I get this error message:

java.lang.NumberFormatException: For input string: ""

On this code:
 
Marshal
Posts: 5654
329
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is GenericPrams.QMS_ALLOWED_CHARS_NUMBERS? A regex expression I assume? What is its value?
 
Tim Cooke
Marshal
Posts: 5654
329
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And to ask my next question ahead of time.... What are you expecting getParameter("overridepercent") to yield?
 
Tim Cooke
Marshal
Posts: 5654
329
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And finally, what Integer value are you expecting to get out of the whole thing?
 
Rancher
Posts: 5035
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the value returned by this expression:  request.getParameter("overridepercent")
Add a print statement before the posted statements to show its value.  Be sure to add delimiters around the value in the print statement so blanks will show:  
 
Steve Dyke
Ranch Hand
Posts: 2259
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Cooke wrote:What is GenericPrams.QMS_ALLOWED_CHARS_NUMBERS? A regex expression I assume? What is its value?



 
Steve Dyke
Ranch Hand
Posts: 2259
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Cooke wrote:And to ask my next question ahead of time.... What are you expecting getParameter("overridepercent") to yield?



Any number or combination of numbers 0-9
 
Steve Dyke
Ranch Hand
Posts: 2259
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Cooke wrote:And finally, what Integer value are you expecting to get out of the whole thing?



A number representing a percent.
 
Steve Dyke
Ranch Hand
Posts: 2259
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think I have posted this in error.
I just realized I made some adjustments to my code base after the error was generated so the line of code the error says it happened in is not what the current line of code is at now.
Sorry.
 
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the interest of readability:

I'm afraid that the original not only is likely not to fit on smaller displays, but also our formatter tend to obscure critical text.

Note that if you use an IDE's automated pretty-printer, some (depending on settings) may put the "." operators at the end of the line, not the beginning, but I find the operator-at-the-beginning more informative to me.

As for general nit-picking, I'm certainly one for complex statements, but this is a bit much. Also, there are two reasons why breaking this up into simpler statements is a good idea (indentation or not).

First, if you have to step through the code with a debugger, debuggers step per-statement so a LOT of details will be more or less invisible in a complex statement.

Secondly, if you break the code into smaller sequences, it's easier to capture the intermediate values in case you want to print them out to a debug log.

And, if you are REALLY paranoid, you can always put assertions into the code, although I've never seen anyone use the Java assert the way it is in C/C++. Partly, I think because Java's assert is overly complex. Instead we prefer unit-test assertion methods.

Last, but not least, as I've mentioned elsewhere, I prefer to document the allowable data values that go into code. We could, based on context, assume that the percentage can be blank or a number from 0 to 100, but maybe you work for a firm that demands 100%. Or gets negative percentages.

The statement also seems to try to sanitize data. I'm not so kind. If they cram in non-numeric characters into a numeric field, I'm going to reject the whole request. Who knows what else they messed up?
 
Marshal
Posts: 8960
646
Mac OS X Spring VI Editor BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:The statement also seems to try to sanitize data. I'm not so kind. If they cram in non-numeric characters into a numeric field, I'm going to reject the whole request. Who knows what else they messed up?


Totally.

@OP
i.e. abc1def4. If possible in your use case, you may can to return 400 Bad Request.

Try this version of formatting (note, I extracted some code to variables and inverted some logic, for better readability(?)):
 
passwords must contain 14 characters, a number, punctuation, a small bird, a bit of cheese and a tiny ad.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic