Skip to content

Commit e011bcf

Browse files
Jesse EicharFrançois Prunayre
Jesse Eichar
authored and
François Prunayre
committed
more findbugs warnings fixed
1 parent 9b38374 commit e011bcf

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

code_quality/findbugs-excludes.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<Class name="~.*\..*Test" />
99
</Match>
1010
<Match>
11-
<Class name="~org\.fao\.geonet\.[h-zG-Z].*" />
11+
<Class name="~org\.fao\.geonet\.[h-zH-Z].*" />
1212
</Match>
1313
<Match>
1414
<Class name="jeeves.server.JeevesEngine" />

web/src/main/java/org/fao/geonet/Geonetwork.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,8 @@ public Object start(Element config, ServiceContext context) throws Exception {
185185
JeevesJCS.setConfigFilename(path + "WEB-INF/classes/cache.ccf");
186186

187187
// force caches to be config'd so shutdown hook works correctly
188-
JeevesJCS jcsDummy = JeevesJCS.getInstance(Processor.XLINK_JCS);
189-
jcsDummy = JeevesJCS.getInstance(XmlResolver.XMLRESOLVER_JCS);
188+
JeevesJCS.getInstance(Processor.XLINK_JCS);
189+
JeevesJCS.getInstance(XmlResolver.XMLRESOLVER_JCS);
190190

191191

192192

@@ -228,7 +228,6 @@ public Object start(Element config, ServiceContext context) throws Exception {
228228

229229
boolean z3950Enable = settingMan.getValueAsBool("system/z3950/enable", false);
230230
String z3950port = settingMan.getValue("system/z3950/port");
231-
String host = settingMan.getValue(Geonet.Settings.SERVER_HOST);
232231

233232
// null means not initialized
234233
ApplicationContext app_context = null;
@@ -934,7 +933,9 @@ public void stop() {
934933
private DataStore createShapefileDatastore(String indexDir) throws Exception {
935934

936935
File file = new File(indexDir + "/" + SPATIAL_INDEX_FILENAME + ".shp");
937-
file.getParentFile().mkdirs();
936+
if(!file.getParentFile().mkdirs() && !file.getParentFile().exists()) {
937+
throw new RuntimeException("Unable to create the spatial index (shapefile) directory: "+file.getParentFile());
938+
}
938939
if (!file.exists()) {
939940
logger.info("Creating shapefile "+file.getAbsolutePath());
940941
} else {

web/src/main/java/org/fao/geonet/GeonetworkDataDirectory.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import jeeves.utils.BinaryFile;
1111
import jeeves.utils.Log;
1212

13+
import org.apache.commons.io.IOUtils;
1314
import org.fao.geonet.constants.Geonet;
1415

1516
/**
@@ -110,6 +111,8 @@ private static String lookupProperty(JeevesServlet jeevesServlet, ServiceConfig
110111
// Instead of looking for geonetwork.dir, get geonetwork_dir
111112
value = System.getenv(key.replace('.', '_'));
112113
break;
114+
default:
115+
throw new IllegalArgumentException("Did not expect value: "+j);
113116
}
114117

115118
if (value == null || value.equalsIgnoreCase("")) {
@@ -259,17 +262,26 @@ private void initDataDirectory(String path, ServiceConfig handlerConfig) {
259262
if (!schemaCatFile.exists()) {
260263
Log.info(Geonet.DATA_DIRECTORY,
261264
" - Copying schema plugin catalogue ...");
265+
FileInputStream in = null;
266+
FileOutputStream out = null;
262267
try {
263-
FileInputStream in = new FileInputStream(path + "WEB-INF"
268+
in = new FileInputStream(path + "WEB-INF"
264269
+ File.separator + Geonet.File.SCHEMA_PLUGINS_CATALOG);
265-
FileOutputStream out = new FileOutputStream(schemaCatFile);
270+
out = new FileOutputStream(schemaCatFile);
266271

267-
BinaryFile.copy(in, out, true, true);
272+
BinaryFile.copy(in, out, false, false);
268273
} catch (IOException e) {
269274
Log.info(
270275
Geonet.DATA_DIRECTORY,
271276
" - Error copying schema plugin catalogue: "
272277
+ e.getMessage());
278+
} finally {
279+
if(in != null) {
280+
IOUtils.closeQuietly(in);
281+
}
282+
if(out != null) {
283+
IOUtils.closeQuietly(out);
284+
}
273285
}
274286
}
275287

@@ -307,8 +319,8 @@ private void setResourceDir(String webappName, ServiceConfig handlerConfig,
307319

308320
// Create directory if it does not exist
309321
File file = new File(dir);
310-
if (!file.exists()) {
311-
file.mkdirs();
322+
if (!file.exists() && !file.mkdirs()) {
323+
throw new RuntimeException("Unable to create directory: "+file);
312324
}
313325

314326
Log.info(Geonet.DATA_DIRECTORY, " - " + envKey + " is " + dir);

web/src/main/java/org/fao/geonet/lib/ServerLib.java

+14-7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
import java.util.List;
3434
import java.util.Properties;
3535

36+
import javax.annotation.CheckForNull;
37+
import javax.annotation.Nullable;
3638
import javax.servlet.ServletContext;
3739

3840
import jeeves.server.overrides.ConfigurationOverrides;
@@ -47,19 +49,24 @@ public class ServerLib
4749
//---
4850
//---------------------------------------------------------------------------
4951

50-
public ServerLib(ServletContext servletContext, String appPath) throws IOException
52+
public ServerLib(@Nullable ServletContext servletContext, String appPath) throws IOException
5153
{
5254
this.appPath = appPath;
5355

5456
serverProps = new Properties();
5557

56-
InputStream stream = servletContext.getResourceAsStream(SERVER_PROPS);
57-
if (stream == null) {
58-
stream = servletContext.getResourceAsStream(SERVER_PROPS.replace("/",File.separator));
59-
if(stream == null) {
60-
stream = new FileInputStream(appPath + (SERVER_PROPS.replace("/",File.separator)));
61-
}
58+
InputStream stream = null;
59+
if(servletContext != null) {
60+
stream = servletContext.getResourceAsStream(SERVER_PROPS);
61+
if (stream == null) {
62+
stream = servletContext.getResourceAsStream(SERVER_PROPS.replace("/",File.separator));
63+
}
64+
}
65+
66+
if(stream == null) {
67+
stream = new FileInputStream(appPath + (SERVER_PROPS.replace("/",File.separator)));
6268
}
69+
6370
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
6471

6572
try {

0 commit comments

Comments
 (0)