Skip to content

Commit

Permalink
536385: Marketplace client does not open when Eclipse is renamed
Browse files Browse the repository at this point in the history
Fixed URL conversion with whitespaces

Also guarded the whole data loading with a try-catch. This way we might
lose a bit of cached info, but MPC will open even with a load error.

Bug: 536385
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=536385
  • Loading branch information
creckord committed Jun 28, 2018
1 parent 66bbf9f commit b161856
Showing 1 changed file with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,29 +338,34 @@ public static MarketplaceInfo getInstance() {
* @nooverride This method is not intended to be re-implemented or extended by clients.
*/
public MarketplaceInfo load() {
RegistryFile registryFile = createRegistryFile();
File loadFile = registryFile.load();
if (loadFile != null && loadFile.canRead()) {
synchronized (MarketplaceInfo.class) {
try {
final InputStream in = new BufferedInputStream(new FileInputStream(loadFile));
try {
RegistryFile registryFile = createRegistryFile();
File loadFile = registryFile.load();
if (loadFile != null && loadFile.canRead()) {
synchronized (MarketplaceInfo.class) {
try {
XMLDecoder decoder = new XMLDecoder(in);
Object object = decoder.readObject();
decoder.close();
return (MarketplaceInfo) object;
} finally {
in.close();
final InputStream in = new BufferedInputStream(new FileInputStream(loadFile));
try {
XMLDecoder decoder = new XMLDecoder(in);
Object object = decoder.readObject();
decoder.close();
return (MarketplaceInfo) object;
} finally {
in.close();
}
} catch (Throwable t) {
// ignore, fallback
IStatus status = new Status(IStatus.WARNING, MarketplaceClientUi.BUNDLE_ID,
Messages.MarketplaceInfo_LoadError, t);
MarketplaceClientUi.getLog().log(status);
//try to delete broken file
loadFile.delete();
}
} catch (Throwable t) {
// ignore, fallback
IStatus status = new Status(IStatus.WARNING, MarketplaceClientUi.BUNDLE_ID,
Messages.MarketplaceInfo_LoadError, t);
MarketplaceClientUi.getLog().log(status);
//try to delete broken file
loadFile.delete();
}
}
} catch (Exception ex) {
//Never fail due to this
MarketplaceClientUi.error(ex);
}
return null;
}
Expand Down Expand Up @@ -391,6 +396,7 @@ public void save(File registryFile) {
}
} catch (Throwable t) {
// fail safe
MarketplaceClientUi.error(t)
}
}

Expand Down Expand Up @@ -434,15 +440,16 @@ protected RegistryFile createRegistryFile() {
protected File computeConfigurationAreaRegistryFile() {
Location configurationLocation = Platform.getConfigurationLocation();
URL url = configurationLocation == null ? null : configurationLocation.getURL();
URI uri;
if (url == null) {
return null;
}
try {
url = FileLocator.resolve(url);
} catch (IOException e) {
uri = URLUtil.toURI(url.toExternalForm());
} catch (Exception e) {
return null;
}
URI uri = URI.create(url.toExternalForm());
if (!"file".equals(uri.getScheme())) {
return null;
}
Expand Down

0 comments on commit b161856

Please sign in to comment.