So basically I just want to debug a couple of simple scripts by trying a new method, I have been successful in the past by hooking the URL.class (using the source from the jdk and recompling), however I realized that how can I print out a string, before it is even a string?
I want to be able to write to file, or print out, any string that goes through the string class, but how can I create a pipe method when I am within the string class itself?
I.e. a char array is being passed into the string, how do I grab that, make it a string and send it to the print out command from within the string class? If I am too vague I will provide some examples.
IMO, it is a really bad idea to tweak the implementations of Java standard classes, even if you are only doing it to try and debug something. The problem is that you can break things really badly.
For instance, @Roflcoptr suggests that you add a
System.out.println(...)to eachStringconstructor. But what would happen if thePrintStream.printlncall tried to construct a String for some reason? And what would happen during JVM bootstrapping if something tried to construct a String … before theSystem.*stream objects were initialized?I’m not saying it won’t work. I’m not saying you can’t make it work. I’m am saying that hackery like this is liable to fail in spectacular and horrible ways.
My advice would be to find another way to debug / diagnose your problem. For example, set a breakpoint on the relevant String constructor.