I am reviewing java code and there are so many classes to check, I made a regex to find a method written in java that doesn't close IO stream within finally block.
(?s)(?<=public|private|protected).(?<!finally).*?.close\(\)\;
For some reason this doesn't work and it matches even those methods that has finally block, so below is found too
public testMethod(){
InputStream stream = .....
try{
//do something
} finally {
if(stream != null){
stream.close();
}
}
}
While only below should be matched
public testMethod(){
InputStream stream = .....
//do something
if(stream != null){
stream.close();
}
}
Any pointers ?
(public|private|protected)also