|
|
Choosing A Webhost: |
False alarms on inner class?: msg#00013java.findbugs.general
This is a multipart message in MIME format. For the following class, findbugs generates two warnings: --------------------------- import java.util.*; public final class Foo { private final static Comparator COMPARATOR = new Comparator() { public int compare(Object o1, Object o2) { int result = o1.hashCode() - o2.hashCode(); assert(result > 0); return result; } }; TreeMap getMap() { return new TreeMap(COMPARATOR); } } ----------------------- The first warnings is: H C UMAC: Uncallable method Foo$1.<static initializer>() defined in anonymous class At Foo.java:[line 6] If I'm not missing something, this is a plainly false alarm: the static initializer is not only callable, but will be called if the anonymous class is ever used. Perhaps the rule used to generate this warning should make an exception of the static initializer method? The second warning is: M D IC: Initialization circularity between Foo and Foo$1 At Foo.java:[lines 3-14] Again if I'm not missing anything, this warning, too, results from a perfectly innocent code. But I realize this is a much harder case for findbugs to distinguish from a really buggy code. I peeked at the bytecode of the two classes to find out where static initializers call each other. It's obvious why Foo's static initializer needs Foo$1. The opposite direction is less obvious - the reason is the assertion in Foo$1, which inherits the assertion enablement status from Foo. Naturally (it's all compiler-generated) there is no actual bug - the static initializer of Foo$1 contains code that explicitly takes care of the case that Foo is not completely initialized. I realize this is probably a challenge for findbugs to identify this pattern - or is it? Assuming the warning is inevitable, it seems to me a good idea to document it in the bug description page. Also, what's the best way to suppress this warning? I use an exclude rule that matches this type of warning and (the entire) Foo class, but this seems more general than I'd want. Would have been nice if findbugs would offer a way to suppress this warning for a particular pair of classes. Best regards, Yarden Nir-Buchbinder Software Verification and Testing IBM Haifa Research Lab Tel. 972-4-8296010
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | RE: Is it still important that FindBugs run on 1.4 JVMs?, Kothari, Amit |
|---|---|
| Next by Date: | Re: False alarms on inner class?, Bill Pugh |
| Previous by Thread: | Is it still important that FindBugs run on 1.4 JVMs?, Bill Pugh |
| Next by Thread: | Re: False alarms on inner class?, Bill Pugh |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |