How to suppress a FindBugs warning (hard-coded absolute path reference)?

I am just testing some things for the open source Geonetwork software and now I want to export the form file from my postGIS database to my computer, but I cannot check it because I always get the findbugs warning: Hard-coded link to absolute path to org.fao.geonet.services.resources.Download.exec (Element, ServiceContext)

Does anyone know how to suppress or avoid this warning? Or another solution, how can I check if export is working?

Here is the code:

` Map parameter1= new HashMap(); parameter1.put("dbtype", "postgis"); parameter1.put("host", "localhost"); parameter1.put("port", "5433"); parameter1.put("database", "geonetwork"); parameter1.put("schema", "mydata"); parameter1.put("user", "postgres"); parameter1.put("passwd", "dominik1"); parameter1.put("Expose primary keys", false); parameter1.put(PostgisNGDataStoreFactory.VALIDATECONN, true); parameter1.put(PostgisNGDataStoreFactory.MAX_OPEN_PREPARED_STATEMENTS, 100); parameter1.put(PostgisNGDataStoreFactory.LOOSEBBOX, true); parameter1.put(PostgisNGDataStoreFactory.PREPARED_STATEMENTS, true); System.out.println("parameter1: " + parameter1); DataStore pds = new PostgisNGDataStoreFactory().createDataStore(parameter1); FeatureSource fs = pds.getFeatureSource("dano"); SimpleFeatureCollection fc = (SimpleFeatureCollection) fs.getFeatures(); SimpleFeature f = (SimpleFeature) fc.toArray()[0]; // create shapefile File sfile = new File("C:/Users/Tinis/Downloads/dano.zip"); parameter1 = new HashMap(); parameter1.put("url", sfile.toURI().toURL()); parameter1.put("create spatial index", Boolean.FALSE); DirectoryDataStore dds = new DirectoryDataStore(new File(sfile.getAbsolutePath()), (FileStoreFactory) new ShapefileDataStoreFactory.ShpFileStoreFactory(new ShapefileDataStoreFactory(), parameter1)); dds.createSchema(fc.getSchema()); String typeName = dds.getTypeNames()[0]; SimpleFeatureSource featureSource = dds.getFeatureSource(typeName); SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource; // write data to shapefile Transaction t = new DefaultTransaction("addTransaction"); featureStore.setTransaction(t); featureStore.addFeatures(fc); t.commit(); t.close(); ` 

The line that gives the findbugs warning immediately after // creating a comment on the form file

I hope someone can help me with this problem. Thanks!

+6
source share
2 answers

Create an xxx.properties (ResourceBundle) file with the entry:

 danoZip = C:/Users/Tinis/Downloads/dano.zip 

And touch:

 ResourceBundle bundle = ResourceBundle.getBundle("xxx"); String danoZipPath = bundle.getString("danoZip"); File sfile = new File(danoZipPath); 

In this way, you put the configuration of the hard-coded file into a custom properties file.

+5
source

You can use a filter file to describe errors that should be ignored.

http://findbugs.sourceforge.net/manual/filter.html

0
source

Source: https://habr.com/ru/post/974093/


All Articles