THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
- Never call methods that can be overridden by a subclass from the constructor.
- If you call any method from the constructor, either declare the whole class final.
- Or make method private, or final, or static.
- Exceptions Handling
- Checked Exceptions
- Handle checked exceptions when possible.
- In case the exception cannot be handled, allow it to propagate to the calling method by declaring "throws".
- If the method's API cannot be changed, wrap the original exception with WebApplicationException. Important! Never wrap unchecked exceptions with WebApplicationException!
- The InvocationTargetException should always be handled. Consider using the following pattern:
Code Block try { } catch (InvocationTargetException e) { Throwable targetException = e.getTargetException(); if (targetException instanceof RuntimeException) { throw (RuntimeException) targetException; } throw new WebApplicationException(targetException); }
- Unchecked Exceptions (Runtime Exceptions)
- Don't catch unchecked exceptions unless you can handle them properly.
- Be aware of "catch (Exception e)" statement, since it also catches unchecked exception. If there are multiple checked exceptions that should be handled in the same way, consider using the following pattern:
Code Block try { } catch (RuntimeException e) { throw e; } catch (Exception e) { // handle exception here }
- Checked Exceptions
Logging
- In general logging is a good idea.
- Use Commons Logging Slf4j.
- For debug messages, call
if (log.isDebugEnabled())
prior to callinglog.debug()
. - The following code is usually bad. There is no need to log exception and re-throw it:
Either log it, or re-throw.Code Block try { } catch (Exception e) { logger.error(e.getMessage(), e); throw new RuntimeException(e); }
Logging Messages
- Messages which are visible to the end user should have their strings externalized and read from a properties file to allow for easier NLS translation.
- Debug messages do not need to be put into a properties file.
Formatting
In a perfect world all people, who contribute code, use the same IDE with the same formatting preferences which, for example, significantly reduces a number of redundant SVN merges.
- An Eclipse code style is attached to this page: wink-eclipse-codestyle.xml Code contributions may use other format styles but please try to use at least the following rules.It should be a good idea to attach a formatter profile for Eclipse that contributors are expected to use.
- Anyway for people, who don't use Eclipse, or want to keep their formatting preferences, let's define some basic rules:
- Do not use Tab. For indentation use only spaces. Indentation size is 4 spaces.
- Maximum line width: 100 characters.
...