Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 231642

Summary: [ui] [repo] I can add the same repo twice
Product: [Eclipse Project] Equinox Reporter: Susan McCourt <susan>
Component: p2Assignee: John Arthorne <john.arthorne>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: john.arthorne, mober.at+eclipse, pascal, simon_kaegi
Version: 3.4   
Target Milestone: 3.4 RC2   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Fix v01 none

Description Susan McCourt CLA 2008-05-12 15:18:25 EDT
I20080510-2000
I can add these URLs and get two repos:
http://update.eclipse.org/testUpdates
http://update.eclipse.org/testUpdates/

I believe this used to be caught in the repo manager or else the UI.
I seem to remember that the UI caught exact duplicates and the repo manager figured out otherwise (because it does the content.jar, content.xml appending, etc.).  

Where should we fix this?

For a moment I thought I had the "double vision" UI bug (bug 229069) but in fact I had added the same repo twice at one point.  I didn't realize what had happened until I checked the properties of each repo because the repo name showing in the list was the same.
Comment 1 Susan McCourt CLA 2008-05-19 13:46:12 EDT
From bug #232791:
Build ID: I20080516-1333 (3.4rc1)

Install some stuff into Eclipse via links/
Choose Help > Software Updates...

Get attached display. There are several sites listed twice, which only differ
by trailing slash. These sites should be listed once only. For instance:

  http://download.eclipse.org/tools/cdt/releases/ganymede
  http://download.eclipse.org/tools/cdt/releases/ganymede/

Marking this one RC2 so it can be investigated.  I originally thought I had added the repo myself with different URL's, but it's possible that p2 itself is doing this.
Comment 2 Susan McCourt CLA 2008-05-19 13:46:27 EDT
*** Bug 232791 has been marked as a duplicate of this bug. ***
Comment 3 John Arthorne CLA 2008-05-19 22:35:13 EDT
The problem here is that java.net.URL says those two URLs are not equal.  A potential fix is to change our repository key to omit the slash:

private String getKey(URL location) {
	String key = location.toExternalForm().replace('/', '_');
	//remove trailing slash because it is equivalent with or without the slash
	int len = key.length();
	if (len > 0 && key.charAt(len - 1) == '_')
		key = key.substring(0, len - 1);
	return key;
}

This would ensure we don't store multiple repos that differ only in trailing slash, but doesn't mess with the URL that is used in loading the repository.
Comment 4 Martin Oberhuber CLA 2008-05-20 08:28:56 EDT
Note that java.net.URL.equals() and hashCode() should be avoided anyways, because they have very problematic performance characteristics:

http://michaelscharf.blogspot.com/2006/11/javaneturlequals-and-hashcode-make.html
Comment 5 John Arthorne CLA 2008-05-21 16:53:23 EDT
Created attachment 101386 [details]
Fix v01

This fix adds a containment check before adding a repository. This revealed two test failures. These tests were relying on the side-effect of addRepository(URL) blowing away the existing repository in memory. Since we now do the containment check, this no longer happens. This may have been causing repositories to be flushed too often (for example when adding a repository reference or discovery site), that would have been causing excessive re-loading of repository contents.
Comment 6 Pascal Rapicault CLA 2008-05-21 18:59:46 EDT
+1
Comment 7 Simon Kaegi CLA 2008-05-21 19:02:07 EDT
+1
Comment 8 John Arthorne CLA 2008-05-21 19:09:46 EDT
Released.
Comment 9 Pascal Rapicault CLA 2008-05-21 19:13:35 EDT
*** Bug 229069 has been marked as a duplicate of this bug. ***