对于PMD,如果要忽略特定警告,可以使用// NOPMD该行来忽略该行.
FindBugs有类似的东西吗?
我只是测试开源软件Geonetwork的一些东西,现在我想将一个形状文件从我的postGIS数据库导出到我的计算机但我无法测试它因为我总是得到一个findbugs警告:硬编码引用org中的绝对路径名. fao.geonet.services.resources.Download.exec(Element,ServiceContext)
有谁知道如何抑制或避免这种警告?或者另一种解决方案我如何测试导出是否有效?
这是代码:
` 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 …Run Code Online (Sandbox Code Playgroud) 我使用字符串作为锁,因此要确保该对象是一个新实例.FindBugs抱怨,因为直接定义字符串通常更有效(使用双引号).我的代码看起来像:
/** A lock for the list of inputs. */
@edu.umd.cs.findbugs.annotations.SuppressWarnings("DM_STRING_CTOR")
//We want a new String object here as this is a lock.
private final Object inputListLock = new String("inputListLock");
Run Code Online (Sandbox Code Playgroud)
我在这里做错了吗?Eclipse FindBugs插件仍然将此报告为一个问题:
Pattern id: DM_STRING_CTOR, type: Dm, category: PERFORMANCE Using the java.lang.String(String) constructor wastes memory because the object so constructed will be functionally indistinguishable from the String passed as a parameter. Just use the argument String directly.