有效的java建议我们不应该catch
NullPointerException
.总是对的吗?
在许多捕捉的情况下NullPointerException
,捕捉身体只打电话printStackTrace()
.
如果我不赶上NullPointerException
并打电话printStackTrace()
,我怎么能检查exception
发生的地方?
而且如果我抓住NullPointerException
并且catch
身体是空的,那么我们当时无法得到任何堆栈信息,是吗?
UPDATE
我分析了google android源码AOSP4.2.2_r1.2中捕获RuntimeException的统计信息.
有249个RuntimeException捕获,以下是catch-body的统计信息.
42%: throw it again as other Exceptions (RuntimeException: 33%, others: 8%)
32%: just return null or 0/false/true or other default values
14%: just call log or printstacktrace
5%: just comment like "// Fall through.", "// ignore, not a valid type.", "// system process dead", "// do nothing"
2%: empty body
3%: display error messages or …
Run Code Online (Sandbox Code Playgroud) 我们使用Klocwork作为静态分析工具.
Klocwork是一种商业工具,具有许多优点,但也存在假阳性等局限性.
我想知道谁曾将Klocwork与Findbugs等其他开源工具进行比较.
通常,已知商业工具比开源工具更可靠.
但我认为Klocwork在特定业务领域也有一些可靠的问题,比如android.
你能否说Klocwork优于其他开源工具,尤其是Findbugs在误报和漏报方面?
我正在尝试使用抑制过滤器,但会发生意外错误.
以下是错误消息.
"无法初始化模块SuppressionFilter - 无法将模块SuppressionFilter中的属性'file'设置为'checkstyle-suppressions.xml':无法找到checkstyle-suppressions.xml - 文档根元素"suppressions",必须与DOCTYPE根"module"匹配."
你能让我知道如何解决这个错误吗?
以下是我使用的配置文件和抑制文件内容.我通过eclipse菜单配置了抑制过滤器(windows> preferences> checkstyle> configure>已知模块Filter> Suppression Filter> add)
======================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="severity" value="warning"/>
<module name="TreeWalker">
<module name="MagicNumber">
<property name="ignoreNumbers" value="-1, 0, 1"/>
</module>
</module>
</module>
Run Code Online (Sandbox Code Playgroud)
===================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<suppressions>
<suppress checks="MagicNumberCheck"
files="Home.java"
lines="350-370"/>
</suppressions>
Run Code Online (Sandbox Code Playgroud) 我将 ruby 哈希数据转换为 xml。我的 xml 包含键类型,例如 type="integer"
<problemID type="integer">3</problemID>
Run Code Online (Sandbox Code Playgroud)
如何从我的 xml 中删除类型信息?比如下面这行
<problemID>3</problemID>
Run Code Online (Sandbox Code Playgroud)
这是我从哈希数据生成 xml 的代码。
my_xml = my_hash.to_xml(:root => 'problem')
Run Code Online (Sandbox Code Playgroud)
非常感谢。
这是我测试HashSet的示例代码.我希望结果是[3K,1K]但这个代码导致[1K,3K,3K]
你能让我知道为什么代码不能调用等于?
import java.util.HashSet;
class SutdaCard{
private int num;
private boolean isKwang;
SutdaCard(){
this(1,true);
}
SutdaCard(int num, boolean isKwang){
this.num = num;
this.isKwang = isKwang;
}
public String toString(){
return num+(isKwang ? "K":"");
}
public boolean equals(Object obj){
String compareValue = obj.toString();
String thisValue = toString();
System.out.println("equals");
return thisValue.equals(compareValue);
}
public int hashcode(){
return toString().hashCode();
}
}
Run Code Online (Sandbox Code Playgroud)
class exercise11_11 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
HashSet<SutdaCard> set = new …
Run Code Online (Sandbox Code Playgroud) java ×2
checkstyle ×1
findbugs ×1
hash ×1
hashset ×1
klocwork ×1
ruby ×1
suppression ×1
xml ×1