I use log4j for logging and tend to include the following snipet in
all my classes...
public class MyClass {
// Logging Declarations
private static String _className;
private static Category _cat;
static {
_className = MyClass.class.g etName();
_cat = Category.getIns tance(_classNam e);
}
............
}
this works fine until you start to investigate obfuscation and in
particular RetroGuard; Retroguard correctly changes MyClass to be
some funny name but when the code executes the static initialiser
fails with ClassNotFoundEx ception since MyClass.class.g etName is not
myFunnyName.cla ss.getName
What I really want is a way in a static intialiser to get .class but I
don't have a this so can't do a this.class. Any ideas?
I have a horrible hack... create a funny Constructor and create an
instance using the funny Constructor;the n discard the instance.
e.g.
public class MyClass {
// Logging Declarations
private static String _className;
private static Category _cat;
static {
_className = new MyClass(_cat).c lass.getName();
_cat = Category.getIns tance(_classNam e);
}
private MyClass(Categor y c) {}
............
}
but I don't like it...
So the big question is... How do I get .class in a static context?
Thanks,
Gavin
all my classes...
public class MyClass {
// Logging Declarations
private static String _className;
private static Category _cat;
static {
_className = MyClass.class.g etName();
_cat = Category.getIns tance(_classNam e);
}
............
}
this works fine until you start to investigate obfuscation and in
particular RetroGuard; Retroguard correctly changes MyClass to be
some funny name but when the code executes the static initialiser
fails with ClassNotFoundEx ception since MyClass.class.g etName is not
myFunnyName.cla ss.getName
What I really want is a way in a static intialiser to get .class but I
don't have a this so can't do a this.class. Any ideas?
I have a horrible hack... create a funny Constructor and create an
instance using the funny Constructor;the n discard the instance.
e.g.
public class MyClass {
// Logging Declarations
private static String _className;
private static Category _cat;
static {
_className = new MyClass(_cat).c lass.getName();
_cat = Category.getIns tance(_classNam e);
}
private MyClass(Categor y c) {}
............
}
but I don't like it...
So the big question is... How do I get .class in a static context?
Thanks,
Gavin
Comment