Version 6, last updated by tpeterka at October 26, 2009 09:47 UTC

Present code problems

Present code – as of 10/2009 – is really not written by Java code conventions and by Java best practices .

In the code are the following offences:

  • Name of packages contains underscore symbol. Eg.:
    cz.zcu.kiv.cosi.bundleTypes._exceptions
  • In a class which extends from Exception it is needles to override method toString(). Better way is the use of e.getMessage() instead of e.toString().
    @Override
        public String toString() {
        return getMessage();
    }
  • Next part of code I saw only in JACC and OBCC but please, don’t use it. (Why? PB)(re: I see problem on 4th and 5th lines. In the fourth line is thows Exception in catch block of IOException. It is strange. But throwed Exception is catched in next line. Why JACC and OBCC developers do this? TP)
    try {
        some code;
    } catch (IOException e) {
        throw new Exception(); 
    } catch (Exception e) {
        some action;
    }
  • Next part of code is in so many classes. I don’t know what it means. If a developer would write something like java.util.UUID.randomUUID() he should use it directly.
    /**
    * TODO: generate serialVersionUID
    */
    // private static final long serialVersionUID = -3237831890770797320L;
    
  • If you should throw exceptions don’t throw Exception but throws some exception extended from Exception or write your own SomethingException which specifies throwable exception.
    public void start(BundleContext context) throws Exception {
            ContextUtils.setBundleContext(context);
            ...
    }
  • Don’t write names of variables like in C language. Don’t type first character of variable as capital latter and do not use underscore symbol. Eg.:
    ServiceRefernce F_ret = null;
    Better way is write it like this:
    ServiceRefernce serviceReference = null;
  • This is terrible! (Why? Long method name? But it makes it completely obvious what it does! PB)(re: Long name is great. The main problem is use of underscore symbol at begin of method name. TP)
    _removeFromProvidingListBasedOnBundle(P_bundle, interfaceProviders);
    Without comment…
  • JCoSiBundleImpl newBundle = new JCoSiBundleImpl();
    This is not good practice. Better way is write it like this:
    JCoSiBundle newBundle = new JCoSiBundleImpl();