Class.forName ? Probably not ...
After subscribing to the OSGi Planet feed I felt like starting to read some old blog posts and stumbled upon a series of posts by BJ Hargave around the issues of the Eclipse ContextFinder caused by the
For the full story please go and read Class.forName caches defined class in the initiating class loader (and folow the links !).
So, these posts caused me to try and look how we behave in Apache Sling ... and of course hoped we would be clean.
Well, hmm, turns out we are not ... I found nine classes using
So we probably have to clean this up. Maybe or maybe not, these uses may be the cause for some strange failures we had over time. I cannot really tell. But I cannot exclude this possibility either.
BTW, this is what I did to find the classes:
Class.forName
methods.For the full story please go and read Class.forName caches defined class in the initiating class loader (and folow the links !).
So, these posts caused me to try and look how we behave in Apache Sling ... and of course hoped we would be clean.
Well, hmm, turns out we are not ... I found nine classes using
Class.forName
. So we probably have to clean this up. Maybe or maybe not, these uses may be the cause for some strange failures we had over time. I cannot really tell. But I cannot exclude this possibility either.
BTW, this is what I did to find the classes:
$ find . -name "*.java" -exec fgrep -l Class.forName {} \;
Kommentare
If there is no 'easy' solution for OSGi that always works, what about supporting rules that define how to load the class (optionally with parameters) as in: Statement.execute("create trigger ... call \"com.acme.MyTrigger?bundle=abc&version=1.1\"") (OSGi) or "create trigger ... call \"com.acme.MyTrigger?service=def\"" (OSGi) or \"com.acme.MyTrigger?loader=context\"" (only use the context class loader) or \"com.acme.MyTrigger?loader=forName\"" (only use Class.forName).
Please forgive me my current non-knowledge about OSGi.
As for the "loader hint": I think this completely defeats the whole idea of OSGi and loose coupling. Thus it creates even more harm.