This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 200914 - Find usages returning wrong results
Summary: Find usages returning wrong results
Status: VERIFIED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Refactoring (show other bugs)
Version: 7.0
Hardware: All All
: P2 normal (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-12 15:55 UTC by schkovich
Modified: 2011-10-30 11:55 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
One more screenshot (12.92 KB, image/png)
2011-09-27 16:03 UTC, schkovich
Details
new/old PHP class (336 bytes, application/x-php)
2011-09-27 16:05 UTC, schkovich
Details
Sample project (4.80 KB, application/x-gzip)
2011-09-27 16:27 UTC, schkovich
Details

Note You need to log in before you can comment on or make changes to this bug.
Description schkovich 2011-08-12 15:55:41 UTC
Product Version = NetBeans IDE Dev (Build 201108111304)
Operating System = Linux version 2.6.38-10-generic running on amd64
Java; VM; Vendor = 1.7.0
Runtime = Java HotSpot(TM) 64-Bit Server VM 21.0-b17

I am working on Zend Project. Zend Framework is in global path. When finding usages of a class public method aside of usages of method I am getting usages of  the Zend Framework method having the same name.

Usages of getTerm [11 occurrences]
ActivityEntry.php
return $category->getTerm();
Web
C.php
return $this->_Model->getTerm(new Zend_Date());
T.php
public function getTerm(Zend_Date $date)
SubscriptionEntryTest.php
$this->assertEquals('channel', $category->getTerm());
$this->assertEquals('playlist', $category->getTerm());
$this->assertEquals('favorites', $category->getTerm());
$this->assertEquals('query', $category->getTerm());
YouTubeOnlineTest.php
$subscriptionType = $category->getTerm();
$subscriptionType = $category->getTerm();
$subscriptionType = $category->getTerm();
$subscriptionType = $category->getTerm();
Comment 1 Tomas Mysik 2011-08-15 07:39:40 UTC
Can you attach a sample project we can play with? Also, please provide exacts steps to reproduce. That would help us a lot!

Thanks.
Comment 2 schkovich 2011-08-15 11:07:11 UTC
(In reply to comment #1)
> Can you attach a sample project we can play with? Also, please provide exacts
> steps to reproduce. That would help us a lot!
> 
> Thanks.

Sure. I will do it during the week.
Comment 3 Ondrej Brejla 2011-09-27 08:20:54 UTC
Waiting for sources from reporter, until that -> incomplete.
Comment 4 schkovich 2011-09-27 16:03:14 UTC
Created attachment 111248 [details]
One more screenshot
Comment 5 schkovich 2011-09-27 16:05:05 UTC
Created attachment 111249 [details]
new/old PHP class
Comment 6 schkovich 2011-09-27 16:10:03 UTC
Sorry guys, uploaded attachment are meant to be attached to http://netbeans.org/bugzilla/show_bug.cgi?id=200510
Comment 7 schkovich 2011-09-27 16:27:58 UTC
Created attachment 111252 [details]
Sample project

Steps to reproduce:

* Create new Zend PHP project
* Add ZF/library/Zend to project include path
* Add to the class IndexController method getTerm
* Right click on method getTerm and select Find Usages

Expected result:
Method should be used only once in the class IndexController

Actual result:
Usage of the method IndexController:getTerm is found in ZF/library/Zend/Gdata/YouTube/ActivityEntry.php in class Zend_Gdata_YouTube_ActivityEntry on line 216:
                 return $category->getTerm();
Comment 8 schkovich 2011-09-27 16:28:45 UTC
Product Version: NetBeans IDE Dev (Build 201109260601)
Java: 1.7.0; Java HotSpot(TM) 64-Bit Server VM 21.0-b17
System: Linux version 2.6.38-11-generic running on amd64; UTF-8; en_GB (nb)
Comment 9 schkovich 2011-09-29 11:37:48 UTC
Guys, this is serious problem. I am bumping into this problem again and again.
Comment 10 Petr Pisl 2011-09-29 12:27:06 UTC
I can reproduce this.
Comment 11 Petr Pisl 2011-10-03 12:13:43 UTC
The problem is that sometimes we are not able to recognized the type of caller, who calls the method. In such case, NetBeans suggests to refactor / mark as a usage such call, because there is not sure, whether it's the right type or not. This is exactly the case with Zend framework and getTerm() method.

If you look at the code, where "the usage" of IndexController/getTerm()is find in ActivityEntry:

public function getActivityType()
    {
        $categories = $this->getCategory();
        foreach($categories as $category) {
            if ($category->getScheme() == self::ACTIVITY_CATEGORY_SCHEME) {
                return $category->getTerm();
            }
        }
        return null;
    }

NetBeans are not able to resolve return type of method  $this->getCategory(). If the return type will be clear to NB, then it doesn't happen.

I have to admit that I'm surprised that NetBeans was able to resolved other 24 cases where the method getTerm() is invoked.

So what should be the solution? There will be always cases, where NetBeans doesn't know the type. We can split the find usages in two groups:

1) Usage, where NetBeans can "guess" the type. The word guess is important. Even this "guess" can not be guaranteed. It'a presumption after analyzing the code that doesn't have to match with the state in runtime. 
2) Usage, where NetBeans find just the same name of an identifier/method call, but the type is not clear. 

Probably is not the solution offer just the usages from the first group. 

My suggestion is to make visual difference between the items in Find usages and Refactoring window. For Refactoring preview, also the usages from the first group could be checked by default and from the second group by default unchecked.

What do you think?
Comment 12 Petr Pisl 2011-10-26 15:54:15 UTC
http://hg.netbeans.org/web-main/rev/b29518d18c48

I have committed a partial fix. It fixes the case that is mentioned here, but other cases are not covered. The problem is also that now the refactoring doesn't work correctly with different contexts.
Comment 13 Quality Engineering 2011-10-27 14:08:14 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/b29518d18c48
User: Petr Pisl <ppisl@netbeans.org>
Log: #200914 - Find usages returning wrong results
Comment 14 schkovich 2011-10-30 11:55:00 UTC
Verified using:
Product Version: NetBeans IDE Dev (Build 201110290600)
Java: 1.7.0; Java HotSpot(TM) 64-Bit Server VM 21.0-b17
System: Linux version 2.6.38-12-generic running on amd64; UTF-8; en_US (nb)