I’m trying to use JPF to verify my bytecode generated while runtime with javassist.
The code I’m trying to verify is supplied by the user while my program is running. As I can’t check all OOP models and stuff like that I need a verification process before running his code.
At the moment I simply generate bytecode with javassist from his classes.
My problem now is that I get exceptions sometimes because the user did some inheritance mistakes and stuff and my application shuts down with an exception cause I tried to load and execute his classes.
Therefore I would like to verify that generated bytecode in runtime to avoid such exceptions and to know earlier if the classes supplied from the user are faulty (or contain any problem).
Is this possible with JPF while in runtime?
Any other solutions on this?
Thanks!
There are many points to check:
the bytecode itself according to the class file format
the runtime phases: loading, linking and initializing
From my point of view, a
ClassLoaderdoes all that steps but it generally loads one Class at a time, and only on demand.In your context, I propose you write a
ClassLoaderthat loads in sequence all classes from generated bytecodes and reports each failing class name with caught exceptions. The ClassLoader is instantiated with the reference to the relevant parent ClassLoader and is discarded after the test passed, the generated bytecode is then loaded by the original ClassLoader of your runtime context.Probably this class loading check may be implemented thanks to OSGi but it will require more efforts than a standalone ClassLoader.