Skip to content

Commit

Permalink
[Issue #577] fixes NPE on Catalog File Connection (#580)
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Gasdorf <[email protected]>
  • Loading branch information
fgdrf authored Oct 29, 2021
1 parent 3de01f2 commit 98cfcdd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
/**
* uDig - User Friendly Desktop Internet GIS client
* https://locationtech.org/projects/technology.udig
* (C) 2021, Eclipse Foundation
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution
* License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html).
*/
package org.locationtech.udig.catalog.ui;

import static org.junit.Assert.*;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import org.eclipse.core.runtime.FileLocator;
Expand All @@ -14,6 +22,7 @@
public class FileConnectionFactoryTest {

private FileConnectionFactory fileConnectionFactory = null;

@Before
public void setUp() throws Exception {
fileConnectionFactory = new FileConnectionFactory();
Expand All @@ -35,4 +44,13 @@ public void testSecondExtensionFromMultibleExtensionFileProvider() throws Except
assertTrue(canProcess);
}

@Test
public void createConnectionURL_nullContext_returnNull() {
assertNull(fileConnectionFactory.createConnectionURL(null));
}

@Test
public void createConnectionURL_unsupportedType_returnNull() {
assertNull(fileConnectionFactory.createConnectionURL(1L));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@ public Map<String, Serializable> createConnectionParameters(Object context) {

@Override
public URL createConnectionURL(Object context) {
URL url = ID.cast(context).toURL();
if (context == null) {
return null;
}

if (url == null) {
ID id = ID.cast(context);

if (id == null) {
return null;
}
URL url = checkedURL(id.toURL());

url = checkedURL(url);
if (url == null || url.getFile() == null) {
return null;
}
Expand All @@ -81,6 +85,9 @@ public URL createConnectionURL(Object context) {

/** Check that any trailing #layer is removed from the url */
static public URL checkedURL(URL url) {
if (url == null) {
return null;
}
String check = url.toExternalForm();
int hash = check.indexOf('#');
if (hash == -1) {
Expand Down

0 comments on commit 98cfcdd

Please sign in to comment.