Finding What is Not There in Eclipse

In my current project there is a need to add some parameters to portlet definition files. The first pass through we only updated the ones we knew needed the update. As is often the case, what we knew then and what we know now changed, and it became a better approach to simply add the values to all of the portlet definition files. Rather than sorting through one by one to find which had not been updated, I did a search and found a stackoverflow thread about how to do these searches in Eclipse. The thread included the following example of a regular expression for finding files that do not include a particular value:

(?s)A((?!YourSearchText).)*Z

For those who like pictures, below is how the search box is used with regex to find files missing the string:

EclipseRegExSearchExample

Facebooktwitterredditlinkedinmail
© Scott S. Nelson

Catching the Un-Catchable

I know it is bad practice to catch java.lang.NoClassDefFoundError.  Today, however, I did need a way to deal with it because I have this annoying habit of wanting everything else to work even when some non-critical piece is broken.

This case was a matter of a third-party security jar that would throw up rather than out when it could not find its properties file. No matter how many catches I had wrapped around the call to the method in the jar, the java.lang.NoClassDefFoundError would bubble up as a big render issue in the JSP.  I am only using this jar to get the user display name, so it isn’t like my application is not secure if I don’t have their name to make them feel special.

After several annoying and pointless approaches, I came up with the following (ugly-but-effective) solution:

try //the Security class relies on this property file but pukes if not found, 
    //so we test for it here
{
   FileInputStream in = new FileInputStream("security.properties");
   in.close();
}
catch(Exception e)
{
   System.out.println("security.properties is missing from classpath");
   return personInfo;
}
//...go use the third-party class that depends on the file having proven it is there

This allowed the application to continue running and not falling apart at the header just because one file was missing. It is one thing to have a bug that is minor, another when that bug becomes something that users pick up the phone about.

Facebooktwitterredditlinkedinmail
© Scott S. Nelson