Menu

#108 Automatically exclude "shim classes" from instrumentation

some future version
open
nobody
None
5
2014-07-02
2006-08-30
Paul Holser
No

In certain cases, javac creates inner classes that
exist for no reason other than to allow a top-level
class access to constructors of private static nested
classes the encloser declares. For example, compiling
the attached file Boo.java will yield Boo.class,
Boo$Sprintable.class and Boo$1.class. If you run
"javap -verbose" on Boo$Sprintable.class you will see
that rather than having a zero-arg constructor, it has
a one-arg ctor where the first arg is of type Boo$1.
Running "javap -verbose" on Boo$1 will show that it has
no ctors or methods. I haven't seen reference to what
classes like Boo$1 are called except the informal name
"shim classes".

If at all possible, it would be great if EMMA could
detect when a class is such a "shim class" and
automatically exclude it from instrumentation.
Currently, I can use filters to exclude them; but I'd
rather not rely on the name of such classes always
being SomeClass$1; I use anonymous inner classes a lot
and would rather not have to go back and edit my
filters in case a "shim class" gets a new name.

As it stands now, if I do not exclude these classes,
they show up in the coverage reports and mess up my
"class" coverage statistics. The source link to the
"shim class" doesn't do anything; it cannot correlate
the "shim class" to any source location, nor could it.

Discussion

  • Paul Holser

    Paul Holser - 2006-08-30

    Example of a class that produces a "shim class"

     
  • Paul Holser

    Paul Holser - 2006-08-30

    JUnit test to drive execution of Boo.

     

Log in to post a comment.