• Post Reply Bookmark Topic Watch Topic
  • New Topic

utility class not throwing exception  RSS feed

 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a personal DateUtils class with several methods that I use on a regular basis. I recently added this method:

It's used in a DAO like so:

Due to a lack of coffee, I forgot to upload the new DateUtils.class file to the server. When this DAO hit that line, it did not throw an error. In fact, it restarted the application! All I saw in the log was "context restarting". After lots of debugging statements and a couple cups of coffee, I figured out my dumb mistake and now all is well, but this would have been a lot easier to diagnose if the log had contained an error.

Why was there no "method not found" message or something similar? Can I change my code to make sure I get an exception when something like this happens?
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know, but there is something odd about 1 + formattedDate. How do you get centuries from that?
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It was a Y2K fix for our AS400. All 6 character dates (yyMMdd) had a century indicator added, 0 for 20th century and 1 for 21st. Since I know yesterday was this century, I just prepend a 1 to it to match the format expected by DB2.

It seems odd, I know. Just as odd as the fact that all the date fields in our database are actually strings. The programmers never use the DATE or DATETIME data types.
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know why the application context would restart, unless of course something within your application or the thing that runs your application does it. However, do note that "no method found" is an Error http://docs.oracle.com/javase/7/docs/api/java/lang/NoSuchMethodError.html and not an Exception and as such won't be caught in a catch (Exception) block but will be caught in a catch(Throwable) block. Perhaps, there's some piece of code which is catching it and restarting the context?
 
Campbell Ritchie
Marshal
Posts: 56525
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mean 0 for 21st century, surely? That fix seems very confusing to me.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope. All the recent dates in the AS400 look like '1140515'. I wasn't here for Y2K, so I won't even try to defend it, I've just learned to deal with it.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jaikiran Pai wrote:However, do note that "no method found" is an Error http://docs.oracle.com/javase/7/docs/api/java/lang/NoSuchMethodError.html and not an Exception and as such won't be caught in a catch (Exception) block but will be caught in a catch(Throwable) block. Perhaps, there's some piece of code which is catching it and restarting the context?


Good point. I searched for "throwable" and found 359 matches. I'm looking through them now. There is a SessionManager with an overridden finalize method that looks suspicious. This DAO is being run from a context listener, and I don't know how sessions work when using a listener.

I'm going to do a little experimenting by adding a catch(Throwable) block and then commenting out that method.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!