Fragile Code (1)

//String product_home=System.getProperty("jboss.server.home.dir");
String product_home=System.getProperty("user.home"); //for testing only
String sparator=System.getProperty("file.separator");
StringBuffer f = new StringBuffer();
f.append(product_home).append(sparator).append("conf").append(sparator).append("application.properties");
try {
prop.load(new FileInputStream(f.toString()));
} catch (IOException e) {
//blank catch block
}


What make the code above "fragile" are:
  • Blank catch block: is the greatest sin a java programmer could ever make
  • Provide 2 lines of codes, 1 for production, 1 for testing. One of them have to be commented to make the code "works". Eventually someday you'll forgot to comment it back to the production mode.
  • Getting the properties file's location with a hardcoded path ("jboss.server.home.dir")/conf/applications.properties

0 comments: (+add yours?)