Java – how to delete system. Java from the code base out. println
We have a huge (old Java) code base in which many files (about 5K) have system out. println. We plan to delete it for cleaning / demonstration How can we write a script to replace them without introducing any problems in the code? Scripts cannot delete them blindly because the following can be a problem:
if () some.code... else System.out.println(...); DB.close();
I'm thinking of using ';' Replace them This will take care of the above situation Do you see any other problems? Any other suggestions?
Solution
Have you considered this stupid thing:
System.out.println(" Print " + object.changeState() );
I don't think this is happening, but println may perform a method that actually performs some of the operations the system depends on, and may introduce subtle errors (believe me or not, but I've seen this)
The recorder may be replaced and disabled
Or create an empty object using null object mode:
public final class DevNull { public final static PrintStream out = new PrintStream(new OutputStream() { public void close() {} public void flush() {} public void write(byte[] b) {} public void write(byte[] b,int off,int len) {} public void write(int b) {} } ); }
And replace
System.out.println();
with
DevNull.out.println();