Bug 329671 - Regression: arg0,1,2... parameter names are cached
Summary: Regression: arg0,1,2... parameter names are cached
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.7 M4   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-11-08 08:41 EST by Dani Megert CLA
Modified: 2010-12-07 04:32 EST (History)
4 users (show)

See Also:


Attachments
Proposed patch (868 bytes, patch)
2010-11-22 11:32 EST, Jay Arthanareeswaran CLA
no flags Details | Diff
Patch with test (3.78 KB, patch)
2010-11-25 01:08 EST, Jay Arthanareeswaran CLA
no flags Details | Diff
Binary and javadoc for the new test (20.92 KB, application/octet-stream)
2010-11-25 01:13 EST, Jay Arthanareeswaran CLA
no flags Details
Patch with updated test (4.31 KB, patch)
2010-11-25 04:03 EST, Jay Arthanareeswaran CLA
no flags Details | Diff
Patch with updated test (5.17 KB, patch)
2010-11-30 05:22 EST, Jay Arthanareeswaran CLA
daniel_megert: review-
Details | Diff
Proposed fix (1.29 KB, patch)
2010-11-30 08:47 EST, Olivier Thomann CLA
no flags Details | Diff
Same patch with updated test (5.57 KB, patch)
2010-11-30 09:04 EST, Jay Arthanareeswaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2010-11-08 08:41:42 EST
3.7 M2.

Due to a bad fix for bug 316937, the raw parameter names are put into the cache. This means that if the first attempt to read the parameter from e.g. Javadoc over the net times out, I end up with the raw names in the cache and even if the parameters could be fetched later, I get the raw names back.

Test Case:
1. set timeout for fetching parameter names to 5ms
2. JLabel l; l.<code assist>
   ==> proposals show raw names
3. set timeout for fetching parameter names to 5000ms
4. JLabel l; l.<code assist>
   ==> proposals still show raw names
EXPECTED: proposals show the parameter names fetched from Javadoc
Comment 1 Olivier Thomann CLA 2010-11-08 08:50:14 EST
Jay, this must be fixed for M4.
Thanks.
Comment 2 Jay Arthanareeswaran CLA 2010-11-22 11:32:42 EST
Created attachment 183576 [details]
Proposed patch

Though, in the current thread, raw values are used for parameter names, the Javadoc is fetched anyway and cached further in the new thread and will be available next time on. So, no need to cache the raw names at the end of the method.

I will see if I can add a regression test.
Comment 3 Jay Arthanareeswaran CLA 2010-11-24 01:00:31 EST
(In reply to comment #2)
> I will see if I can add a regression test.

Since it's a timing issue, I don't know how reliable a test can be. I guess I will let this patch go in as is.
Comment 4 Dani Megert CLA 2010-11-24 03:17:28 EST
(In reply to comment #3)
> (In reply to comment #2)
> > I will see if I can add a regression test.
> 
> Since it's a timing issue, I don't know how reliable a test can be. I guess I
> will let this patch go in as is.
A test should be easy to write: just craft it along the lines outlined in comment 0.
Comment 5 Jay Arthanareeswaran CLA 2010-11-25 01:08:07 EST
Created attachment 183820 [details]
Patch with test

Same patch with test.
Had to introduce a time delay in the test so that the previous attempt to load the Javadoc gets enough time, even though the code complete would have returned raw parameter names.
Comment 6 Jay Arthanareeswaran CLA 2010-11-25 01:13:22 EST
Created attachment 183821 [details]
Binary and javadoc for the new test

This archive contains the JAR with classes and a zip with the Javadocs that are required for the new test.
Both the JAR and javadoc zip go inside "/org.eclipse.jdt.core.tests.model/workspace/Completion"
Comment 7 Dani Megert CLA 2010-11-25 01:52:19 EST
> Had to introduce a time delay in the test so that the previous attempt to load
> the Javadoc gets enough time, even though the code complete would have 
> returned raw parameter names.
Couldn't you use/set the preference like I did in comment 0?
Comment 8 Jay Arthanareeswaran CLA 2010-11-25 02:08:13 EST
(In reply to comment #7)
> Couldn't you use/set the preference like I did in comment 0?

There's a problem there. When we do it manually, there is enough delay between successive attempts and by the time we make the second attempt, the Javadoc has already been loaded. However, in the test, the second attempt is too quick that it fetches BinaryType.EMPTY_JAVADOC for Javadoc in BinaryMethod (line no 205) and hence condition if (javadocContents == null) is not satisfied. And I didn't want to touch a working code and it won't matter in the IDE.

Actually, since the Javadoc contents are cached, setting the delay preference to a higher value doesn't mean much.
Comment 9 Dani Megert CLA 2010-11-25 02:11:47 EST
(In reply to comment #8)
> (In reply to comment #7)
> > Couldn't you use/set the preference like I did in comment 0?
> 
> There's a problem there. When we do it manually, there is enough delay between
> successive attempts and by the time we make the second attempt, the Javadoc has
> already been loaded.
Agreed.

> Actually, since the Javadoc contents are cached, setting the delay preference
> to a higher value doesn't mean much.
Well, actually the test should show that if the first attempt didn't fetch the parameters, a second attempt with a higher timeout would do the trick.
Comment 10 Jay Arthanareeswaran CLA 2010-11-25 04:03:20 EST
Created attachment 183835 [details]
Patch with updated test

I guess the test now looks closer to the bug description. But it required a perProjectInfo cache flush (not the BinaryMethod cache)
Comment 11 Olivier Thomann CLA 2010-11-26 13:08:14 EST
The fix looks good, but the regression test fails consistently on my machine at least inside the IDE.
The first test:
assertResults("foo[METHOD_REF]{foo(), Lbug.X;, (Ljava.lang.Object;)V, foo, (arg0), 35}", requestor.getResults());

always returns an empty string.

So this test should not be released.

I don't see how a reliable test can be added for this. It will always be dependent of the time needed to retrieve the parameter names.

I tried to reproduce the problem in comment 0, and it always works (with or without the fix).

Daniel, you should try to reproduce the problem with the fix. If it works fine, then the fix should be released.
Comment 12 Dani Megert CLA 2010-11-29 03:48:56 EST
> I tried to reproduce the problem in comment 0, and it always works (with or
> without the fix).
That sounds strange. Are you sure you removed the source before trying this?
Comment 13 Olivier Thomann CLA 2010-11-29 09:58:14 EST
(In reply to comment #12)
> That sounds strange. Are you sure you removed the source before trying this?
You are right. Removing the source attachment reproduces the problem.
The fix works fine.

Only the regression test looks unreliable.

So we should fix this for M4 and work on the regression test. This test needs to be reliable otherwise it will fail randomly during Eclipse builds.

Jay, please make sure that the fix is released for M4.
Thanks.
Comment 14 Jay Arthanareeswaran CLA 2010-11-30 05:22:25 EST
Created attachment 184103 [details]
Patch with updated test

I have changed following things in this test. 

1. Instead of using content assist, the test directly calls/tests IMethod.getParameterNames(). So, one less factor to affect the test.
2. I have introduced a time delay that looks for the cached javadoc contents before flushing it. This eliminated the chance of the cache being populated by the previous attempt after the flush. The delay at most is 5000ms and if the javadoc content is not read by then, the test is likely to fail.
3. Moved the test to AttachedJavadocTests.

Despite the new changes, the test can still fail if the javadoc 'read' is successful in 1ms or doesn't complete within 5000ms. Hypothetically, i.e. And we won't be able to fix those cases, simply because of the way the code has been written in BinaryMethod. But I guess we don't want to change the fix itself, do we?
Comment 15 Dani Megert CLA 2010-11-30 07:26:08 EST
Comment on attachment 184103 [details]
Patch with updated test

The fix is not good: it misses the case when the timeout is set to 0 ms.
Comment 16 Dani Megert CLA 2010-11-30 07:28:35 EST
> Despite the new changes, the test can still fail if the javadoc 'read' is
> successful in 1ms 
That part can be avoided by setting it to 0 (once the patch is correct ;-).

> we won't be able to fix those cases, simply because of the way the code has
> been written in BinaryMethod. But I guess we don't want to change the fix
> itself, do we?
Correct, we shouldn't tweak the production code for that.
Comment 17 Olivier Thomann CLA 2010-11-30 08:47:13 EST
Created attachment 184122 [details]
Proposed fix

This is just the patch for BinaryMethod not to cache the parameter names when the timeout value is 0.
In this case we simply return the raw names, but we don't cache the value so that if the timeout is changed, the parameter names will be recomputed.

Daniel, do you agree with this change?
Comment 18 Jay Arthanareeswaran CLA 2010-11-30 09:04:42 EST
Created attachment 184129 [details]
Same patch with updated test

Same patch that Olivier posted plus the test to use '0' as the timeout.

Now the test doesn't test the scenario where a very low but non-zero timeout was used. But that was not reliable, anyway. I am still worried about the possibility of the test failing when the javadoc file reading takes longer than 5 secs.
Comment 19 Olivier Thomann CLA 2010-11-30 09:20:15 EST
+1. This time the test passed.
Jay, please release.
Comment 20 Jay Arthanareeswaran CLA 2010-11-30 10:44:34 EST
Released in HEAD for 3.7 M4.
Comment 21 Dani Megert CLA 2010-11-30 11:30:17 EST
>Daniel, do you agree with this change?
Yep.
Comment 22 Srikanth Sankaran CLA 2010-12-07 04:32:29 EST
Verified for 3.7M4 using build id I20101205-2000