Java try/catch返回跳出if语句?

Java try/catch返回跳出if语句?,java,android,Java,Android,当contactMap不为null且不为空时,以下代码返回null而不引发异常 private List<Contact> getParseQuery(final Map<String, Contact> contactMap) { if (contactMap != null && !contactMap.isEmpty()) { // removed some code here to make this

当contactMap不为null且不为空时,以下代码返回null而不引发异常

    private List<Contact> getParseQuery(final Map<String, Contact> contactMap) {
        if (contactMap != null && !contactMap.isEmpty()) {
            // removed some code here to make this easier to spot
            try {
                List<Person> people = mainQuery.find();
                for (Person person : people) {
                    Contact contact = contactMap.get(person.getPhone());
                    contact.setUser(person);
                    contacts.add(contact);
                }
                return contacts;
            } catch (Exception e) {
                e.printStackTrace();
                return null;
            }
        } else {
            return null;
        }
    }
private List getParseQuery(最终映射contactMap){
if(contactMap!=null&!contactMap.isEmpty()){
//删除了一些代码,使其更容易识别
试一试{
List people=mainQuery.find();
用于(人:人){
Contact-Contact=contactMap.get(person.getPhone());
联系人:setUser(个人);
联系人。添加(联系人);
}
返回联系人;
}捕获(例外e){
e、 printStackTrace();
返回null;
}
}否则{
返回null;
}
}

为什么返回空值?我用“人员”列表中的一条数据逐步浏览了这段代码。但是,在第一次之后,它返回到“for”语句来检查列表中是否有更多的人,然后下一行在“else”中返回null?这怎么可能呢?不会引发异常。

您确定正在对源文件的匹配版本进行调试吗?为什么不在if语句之前尝试转储put to debug?您确定它实际上返回了
null
?由于代码流控制,可能会出现这种情况,尽管较低级别的字节码在返回位置可能有“contacts”,而程序指针看起来好像在“returnnull”。退出该函数,如果您尚未执行此操作,请查看实际返回的内容。在调试之前,请清理项目并重新启动adb服务器。againI不一定相信调试器知道正在执行两条
return null
语句中的哪一条,特别是如果优化重新排列了代码,使得字节码中实际上只有一个
returnnull
。我会尝试在每个
return
之前放置一个
System.out.println
,以确定程序的运行方向。