Make IJ.getClassLoader() consistent

We should not return the class loader that happens to be the current
thread context class loader at the time IJ.getClassLoader() was called,
but rather the context class loader at the time the encapsulated ImageJ
1.x instance was initialized.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Leave preinit() early when the patches were already applied

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
alreadyPatched(): also look at the parent class loaders

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Patch the class loader containing the ImageJ 1.x classes

... not a class loader whose *parent* contains them...

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Add a unit test for the class loader issues

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Move the NoSuchMethodException handler into LegacyHooks

Needed because EssentialLegacyHooks is not intended to be subclassed.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>