}
public int doCheck(ClassLoader cl, CheckClassInfo info)
{
CtClass clazz = info.getClazz();
ClassFile file = clazz.getClassFile();
ClassPool pool = clazz.getClassPool();
int failed = 0;
// Incorrect major version
int major = file.getMajorVersion();
if (major > 48)
{
if (failed == 0)
System.out.println("==== " + info.getFile());
System.out.println("Wrong major version " + major);
++failed;
}
// Check the super class exists
String superClassName = file.getSuperclass();
try
{
pool.get(superClassName);
}
catch (NotFoundException e)
{
if (failed == 0)
System.out.println("==== " + info.getFile());
System.out.println("SuperClass not found " + superClassName);
++failed;
}
// Check the interfaces exist
String[] intfs = file.getInterfaces();
for (String intf : intfs)
{
try
{
pool.get(intf);
}
catch (NotFoundException e)
{
if (failed == 0)
System.out.println("==== " + info.getFile());
System.out.println("Interface not found " + intf);
++failed;
}
}
// Check the field types
List<FieldInfo> fields = (List<FieldInfo>) file.getFields();
for (FieldInfo field : fields)
{
String name = field.getName();
String typeName = Descriptor.toJavaName(field.getDescriptor());
try
{
CtField ctField = clazz.getField(name);
ctField.getType();
}
catch (NotFoundException e)
{
if (failed == 0)
System.out.println("==== " + info.getFile());
System.out.println("Class not found " + typeName + " for field " + name);
++failed;
}
}
// Check the method types
List<MethodInfo> methods = (List<MethodInfo>) file.getMethods();
for (MethodInfo method : methods)
{
String name = method.getName();
String descriptor = method.getDescriptor();
if (CLINIT.equals(name))
continue;
try
{
if (INIT.equals(name) == false)
{
CtMethod ctMethod = clazz.getMethod(name, descriptor);
ctMethod.getReturnType();
}
}
catch (NotFoundException e)
{
if (failed == 0)
System.out.println("==== " + info.getFile());
System.out.println("Return type not found for method " + name + "." + descriptor);
++failed;
}
if (INIT.equals(name))
{
try
{
CtConstructor ctConstructor = clazz.getConstructor(descriptor);
ctConstructor.getParameterTypes();
}
catch (NotFoundException e)
{
if (failed == 0)
System.out.println("==== " + info.getFile());
System.out.println("Cannot find constructor parameter types " + name + "." + descriptor);
++failed;
}
try
{
CtConstructor ctConstructor = clazz.getConstructor(descriptor);
ctConstructor.getExceptionTypes();
}
catch (NotFoundException e)
{
if (failed == 0)
System.out.println("==== " + info.getFile());
System.out.println("Cannot find constructor exception types " + name + "." + descriptor);
++failed;
}
}
else
{
try
{
CtMethod ctMethod = clazz.getMethod(name, descriptor);
ctMethod.getParameterTypes();
}
catch (NotFoundException e)
{
if (failed == 0)
System.out.println("==== " + info.getFile());
System.out.println("Cannot find method parameter types " + name + "." + descriptor);
++failed;
}
try
{
CtMethod ctMethod = clazz.getMethod(name, descriptor);
ctMethod.getExceptionTypes();
}
catch (NotFoundException e)
{
if (failed == 0)
System.out.println("==== " + info.getFile());
System.out.println("Cannot find method exception types " + name + "." + descriptor);
++failed;
}
}
}
// Now we've checked the signatures of the class, let's look at the references
file.compact();
ConstPool consts = file.getConstPool();
for (int i = 1; i < consts.getSize(); ++i) // Yes start at 1
{
switch (consts.getTag(i))
{
case ConstPool.CONST_Fieldref: