01: package spoon.vsuite.findbugs.dm;
02:
03: import spoon.processing.AbstractProcessor;
04: import spoon.processing.Property;
05: import spoon.processing.Severity;
06: import spoon.reflect.Factory;
07: import spoon.reflect.code.CtInvocation;
08: import spoon.reflect.reference.CtExecutableReference;
09: import spoon.reflect.reference.CtTypeReference;
10:
11: /**
12: * Dm: Method invokes runFinalizersOnExit, one of the most dangerous methods in
13: * the Java libraries. (DM_RUN_FINALIZERS_ON_EXIT) Never call
14: * System.runFinalizersOnExit or Runtime.runFinalizersOnExit for any reason:
15: * they are among the most dangerous methods in the Java libraries.
16: *
17: * @author Nicolas Petitprez
18: */
19: public class RunFinalizersOnExit extends
20: AbstractProcessor<CtInvocation<?>> {
21: @Property
22: static Severity level = Severity.WARNING;
23:
24: static CtExecutableReference<?> ref;
25:
26: public static CtExecutableReference<?> getRef(Factory factory) {
27: if (ref == null) {
28: ref = factory.Executable().createReference(
29: factory.Type().createReference(System.class),
30: factory.Type().createReference(void.class),
31: "runFinalizersOnExit",
32: new CtTypeReference[] { factory.Type()
33: .createReference(boolean.class) });
34: }
35: return ref;
36: }
37:
38: static CtExecutableReference<?> ref2;
39:
40: public static CtExecutableReference<?> getRef2(Factory factory) {
41: if (ref2 == null) {
42: ref2 = factory.Executable().createReference(
43: factory.Type().createReference(Runtime.class),
44: factory.Type().createReference(void.class),
45: "runFinalizersOnExit",
46: new CtTypeReference[] { factory.Type()
47: .createReference(boolean.class) });
48: }
49: return ref2;
50: }
51:
52: public void process(CtInvocation<?> element) {
53: if (element.getExecutable().equals(getRef(getFactory()))
54: || element.getExecutable()
55: .equals(getRef2(getFactory()))) {
56: getFactory()
57: .getEnvironment()
58: .report(
59: this ,
60: level,
61: element,
62: "Method invokes runFinalizersOnExit, one of the most dangerous methods in the Java libraries.");
63: }
64: }
65:
66: }
|