Comparison method violates its general contract! JDK版本为1.7


Collections.sort(familyList, new Comparator<ContrRelpartyDerlawyerAndFamilyVO>() {
            @SuppressWarnings("unused")
            @Override
            public int compare(ContrRelpartyDerlawyerAndFamilyVO arg0, ContrRelpartyDerlawyerAndFamilyVO arg1) {
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                try {
                    if(arg0==null){
                           return -1;
                       }
                    if(arg1==null){
                           return 1;
                       }
                    if(arg0==null && arg1==null){
                           return 0;
                       }
                    if(arg0.getUpdateDate()==null){
                           return -1;
                    }
                    if(arg1.getUpdateDate()==null){
                           return 1;
                    }
                    if(arg0.getUpdateDate()==null && arg1.getUpdateDate()==null){
                           return 0;
                    }
                    Date dt1 = format.parse(arg0.getUpdateDate());
                    Date dt2 = format.parse(arg1.getUpdateDate());
                    if(dt1.getTime()<dt2.getTime()){
                        return 1;
                    }else if(dt1.getTime()>dt2.getTime()){
                        return -1;
                    }else{
                        return 0;
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }            
                return 0;
            }            
        });

JDK7中的Collections.Sort方法实现中,如果两个值是相等的,那么compare方法需要返回0,否则 可能 会在排序时抛错

用断点看下,运行在哪一行报错。