Title: BUG: Code Inspection: Singleton not recognized
Alexey,
Unfortunately we can't support multithread logic in analyzer because it would make any inspections completely useless. Imagine we have:
a = 5;
if (a == 5) {}
According to you we can't complain a == 5 is always true because this thread could be interrupted between these thow lines of code!
Moreover, your code does not help in the situation it seems should help in. Imagine the thread would switch between after condition in line 28 succesfully checked and before assignment in line 29 is executed...
If you'd like to play safe game you should remove condition in line 23 or make the whole method synchronized.

Best regards,
Maxim Shafirov
JetBrains, Inc / IntelliJ Software
http://www.intellij.com
"Develop with pleasure!"
 
 
----- Original Message -----
Sent: Thursday, March 21, 2002 5:39 PM
Subject: [Eap-list] BUG: Code Inspection: Singleton not recognized

21:  public static Singleton getInstance() {
22:    // Check instance existing
23:    if (instance == null) {
24:      // Lock any others (we can't put this before previos if, becose it make week place in code (method invoke for get object - too many invokations hapend))

25:      // We must to be sure that only one instance (only one thread) make instance creation
26:      synchronized (synchronizer) {
27:        // Check that instance isn't already created (theoretically its may happened, fisical - maybe no, but...)
28:        if (instance == null) {
29:          instance = new FileCache();
30:        }
31:      }
32:    }
33:    return instance;
34:  }

So, we see to "if conditions": And this reasonable to Code Analiser to say:
Problem synopsis:
Condition instance == null at line 28 is always true.

But this not right.

Thanks.

PS. The Code Inspection is great idea in IDEA :) Thank you for this gem! :)

Alexey Efimov - Software Engineer
Sputnik Labs
1st Kolobovsky per., 6/3
Moscow, 103051, Russia
Phone: +7 (095) 725 5444
Direct: +7 (501) 401 3217
Fax: +7 (095) 725 5443
E-Mail: mailto:[EMAIL PROTECTED]
http://www.spklabs.com

Reply via email to