I’ve been wanting to write a reflection-based Thread Checker for a while already, mainly because I think many people will ask me: “Java provides a reflection API. Why didn’t you use it? It’s so much simpler than rewriting bytecode!”
I originally concurred that it would be easier to write, but I still think it will not perform as well as rewritten bytecode. But the proof is in the pudding, of course, as they say, so I had to write this reflection-based version. I’ve been laboring on this now for most of today, and I did start already a few days back, and it turns out to be pretty hard. It’s not trivial to find out where a method was first introduced. I’ve decided to follow the general outline of what I did with the bytecode-rewriting strategy.
I think I should have the code for the
@PredicateLink-style annotations now, even though it is much more limited than the code I wrote for rewriting class files: Here, the parameters in the predicate method have to have the same order as the members of the annotation, and that order seems to be undefined. Yes. One of my favorite words. I also haven’t tested the reflection-based code for
@PredicateLink-style annotations yet.
The code for
@Combine-style annotations should actually be easier and faster than the rewritten bytecode (or at least faster than the first run, when the rewriting happens; I predict caching of the rewritten class files will again kill reflection on subsequent runs).
I fixed a bug that dealt with determining if class-level annotations should apply to a method. It was rather confusing. If a method was already introduced in an interface, then a class-level annotation on the class that implements that interface should not have any effect, but I did something wrong here.
This has cast some doubt on what I’ve been doing with class-level annotations in general, because when I ask for class-level annotations, I still recur into the superclasses and implemented interfaces, and right now, I don’t think I should be doing that. I’ll examine that closer tonight or tomorrow. (Update: No, what I was doing is right. If a class has an annotation, then all methods introduced in that class or in subclasses get the annotation; therefore, recurring up makes sense.)
Right now, Diana and I are going to the Houston Ballet to see “Nutcracker”. Even though I hate to admit it, I guess the Christmas season actually does begin on the day after Thanksgiving. Why would we watch “Nutcracker” otherwise?