Community
Participate
Working Groups
in my class , if I have the following line private static final SimpleDateFormat formatter = new SimpleDateFormat("DD HH:mm:ss SSSS'm's'"); I am getting a exception in initializer when running the main this line allows me to run my main private static final SimpleDateFormat formatter = new SimpleDateFormat("DD HH:mm:ss SSSS"); I believe the compiler should give me an error about the 'm's' no ?
I guess: private static final SimpleDateFormat formatter = new SimpleDateFormat("DD HH:mm:ss SSSS'm's'"); is all on one line ?
Is this the SimpleDateFormat class for icu or java.text ? It looks like this constructor can potentially throw an exception. So the code should rather be: private static final SimpleDateFormat formatter = newFormatter(); private static SimpleDateFormat newFormatter() { SimpleDateFormat current = null; try { current = new SimpleDateFormat("DDHH:mm:ss SSSS'm's'"); } catch(IllegalArgumentException e) { // handle exception } return current; } It is not up to the compiler to check the validity of the pattern. Closing as INVALID.
Yes one line, so the String is valid 'm's' ? This is an exception at runtime ?
Verified to be invalid.