The Java Bytecode Generator allows for randomized creation of Java class files.
The generated class files share a common structure as they all consist of a main([Ljava.lang.String;)V
and run()V
method whereby the former one represents the main entry point that must exist for a class file to be executable. The latter one serves as a fixpoint when generating and accessing instance variables or methods and is always invoked at least once from the main
method (this naturally also involves a default constructor call to the containing class). Other than that, all parts of the class file are random.
To be able to enforce certain structures or expressions, put the focus on distinct operations or limit the generation of specific control flow elements, the generation process may be steered via flags that denote the probability of those elements being included.
In order to observe the results of a run and to distinguish specific runs, the generator also repeatedly inserts logging calls that print out the values of randomly picked variables or fields (that are accessible in the current context). Additionally, the main
method in the end generates a hash of - once again - randomly selected values and prints it. This should make each class file unique and enable testers to detect unexpected behaviour or leaks when dealing with those class files.
This release relies on Javassist to actually generate the bytecode.