Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Loskutov2017-03-19 09:29:06 +0000
committerAlexander Kurtakov2017-03-20 07:39:53 +0000
commit92727ceea7a0f71d202aa82786590b976592de8f (patch)
tree6681b70388ba4860f99ef3606bab2467779b7dfb /bundles/org.eclipse.swt/Eclipse SWT Program
parent304cf0c3ab2dd382e1a1752eec1fdc375974e103 (diff)
downloadeclipse.platform.swt-92727ceea7a0f71d202aa82786590b976592de8f.tar.gz
eclipse.platform.swt-92727ceea7a0f71d202aa82786590b976592de8f.tar.xz
eclipse.platform.swt-92727ceea7a0f71d202aa82786590b976592de8f.zip
Bug 67361 - [Program] Identical entries in "Program.getPrograms()"
Fixed test error uncovered by the new compiler warning (see bug 513790). After test fix found fixed the test failure due the wrong implementation of Program.getPrograms() which returned array with some equal Program objects. Adopted Program.equals() and hashCode() where needed. Change-Id: I5f4784e504e37b352c2fcc80488fcd3c9f2051cc Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT Program')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Program/cocoa/org/eclipse/swt/program/Program.java13
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java11
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java20
3 files changed, 16 insertions, 28 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/cocoa/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/cocoa/org/eclipse/swt/program/Program.java
index 374045183f..8e3c6db646 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Program/cocoa/org/eclipse/swt/program/Program.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Program/cocoa/org/eclipse/swt/program/Program.java
@@ -18,8 +18,7 @@ import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
/**
* Instances of this class represent programs and
@@ -182,7 +181,7 @@ static Program getProgram(NSBundle bundle) {
public static Program [] getPrograms () {
NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
try {
- List<Program> vector = new ArrayList<>();
+ LinkedHashSet<Program> programs = new LinkedHashSet<>();
NSWorkspace workspace = NSWorkspace.sharedWorkspace();
NSArray array = new NSArray(OS.NSSearchPathForDirectoriesInDomains(OS.NSAllApplicationsDirectory, OS.NSAllDomainsMask, true));
int count = (int)/*64*/array.count();
@@ -199,13 +198,13 @@ public static Program [] getPrograms () {
NSBundle bundle = NSBundle.bundleWithPath(fullPath);
if (bundle != null) {
Program program = getProgram(bundle);
- if (program != null) vector.add(program);
+ if (program != null) programs.add(program);
}
}
}
}
}
- return vector.toArray(new Program[vector.size()]);
+ return programs.toArray(new Program[programs.size()]);
} finally {
pool.release();
}
@@ -394,7 +393,7 @@ public boolean equals(Object other) {
if (this == other) return true;
if (other instanceof Program) {
final Program program = (Program) other;
- return name.equals(program.name);
+ return name.equals(program.name) && identifier.equals(program.identifier);
}
return false;
}
@@ -411,7 +410,7 @@ public boolean equals(Object other) {
*/
@Override
public int hashCode() {
- return name.hashCode();
+ return name.hashCode() ^ identifier.hashCode();
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java
index e7af641f04..795d063ea6 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java
@@ -312,7 +312,7 @@ static Program[] getPrograms(Display display) {
long /*int*/ applicationList = OS.g_app_info_get_all ();
long /*int*/ list = applicationList;
Program program;
- List<Program> programs = new ArrayList<>();
+ LinkedHashSet<Program> programs = new LinkedHashSet<>();
while (list != 0) {
long /*int*/ application = OS.g_list_data(list);
if (application != 0) {
@@ -325,11 +325,7 @@ static Program[] getPrograms(Display display) {
list = OS.g_list_next(list);
}
if (applicationList != 0) OS.g_list_free(applicationList);
- Program[] programList = new Program[programs.size()];
- for (int index = 0; index < programList.length; index++) {
- programList[index] = programs.get(index);
- }
- return programList;
+ return programs.toArray(new Program[programs.size()]);
}
static boolean isExecutable(String fileName) {
@@ -516,7 +512,8 @@ public boolean equals(Object other) {
if (this == other) return true;
if (!(other instanceof Program)) return false;
Program program = (Program)other;
- return display == program.display && name.equals(program.name) && command.equals(program.command);
+ return display == program.display && name.equals(program.name) && command.equals(program.command)
+ && gioExpectUri == program.gioExpectUri;
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java
index e8b938f228..7684023377 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program/Program.java
@@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.swt.program;
+import java.util.*;
+
import org.eclipse.swt.internal.win32.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
@@ -248,32 +250,22 @@ static Program getProgram (String key, String extension) {
* @return an array of programs
*/
public static Program [] getPrograms () {
- Program [] programs = new Program [1024];
+ LinkedHashSet<Program> programs = new LinkedHashSet<>(1024);
/* Use the character encoding for the default locale */
TCHAR lpName = new TCHAR (0, 1024);
int [] lpcName = new int [] {lpName.length ()};
FILETIME ft = new FILETIME ();
- int dwIndex = 0, count = 0;
+ int dwIndex = 0;
while (OS.RegEnumKeyEx (OS.HKEY_CLASSES_ROOT, dwIndex, lpName, lpcName, null, null, null, ft) != OS.ERROR_NO_MORE_ITEMS) {
String path = lpName.toString (0, lpcName [0]);
lpcName [0] = lpName.length ();
Program program = getProgram (path, null);
if (program != null) {
- if (count == programs.length) {
- Program [] newPrograms = new Program [programs.length + 1024];
- System.arraycopy (programs, 0, newPrograms, 0, programs.length);
- programs = newPrograms;
- }
- programs [count++] = program;
+ programs.add(program);
}
dwIndex++;
}
- if (count != programs.length) {
- Program [] newPrograms = new Program [count];
- System.arraycopy (programs, 0, newPrograms, 0, count);
- programs = newPrograms;
- }
- return programs;
+ return programs.toArray(new Program[programs.size()]);
}
/**

Back to the top