Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

False alarms on inner class?: msg#00013

java.findbugs.general

Subject: False alarms on inner class?

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>
Google Custom Search

Recently Viewed:
solaris.opensol...    editors.vim/200...    web.turbogears....    jakarta.ant.dev...    mathematics.max...    text.unicode.ge...    lang.ruby.core/...    xfce.announce/2...    network.centeri...    php.cvs.pear/20...    user-groups.lin...    kde.devel.quant...    file-systems.ar...    redhat.fedora.t...    apple.fink.auto...    gnome.orbit.gen...    qplus.devel/200...    culture.transpo...    video.dri.user/...    operators.nanog...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive 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

Navigation