New situation required:
We don't wish to touch the intervening classes, as they are called from different parts of the application for different reasons.
- provide a boolean flag all up/down the chain
- provide a "nicer" boolean flag, for example an enum or a Factory that determines which f should be created
- use a static flag in f2, in class a2 just set the flag appropriately -> completely unthreadsafe.
- use the ThreadLocal storage to store the boolean in a/a2 and read it in f/f2.
- in e -> call up the stacktrace and check for the existence of class a2.
- in e -> throw exception, call up the stacktrace and cehck for the existence of class a2.
However, the underlying problem is of course, that the two classes are too far apart, and there is too much tight coupling between the intervening classes and the rest of the system.
Also, the whole problem might go away with Functional Programming, but I'm not sure about that.
What do the experts say?