Skip to content

#9.3sonar质量控制改正

公司定义的编码规范:http://sonar.ispeco.com:9001/coding_rules#languages=java|types=BUG

##一、java改错

1.	工具类没有私有构造:	Add a private constructor to hide the implicit public one.
2.	方法抛异常直接抛exception:	Define and throw a dedicated exception instead of using a generic one  定义并抛出专用异常,而不是使用通用异常
3.	字符串,数字定义常量:	Assign this magic number 400 to a well-named constant, and use the constant instead.
3.	字符串定义常量也要加final,除非是卸载interface接口里专有定义常量,不然都是 public static final修饰

小错误:

1.	注释里TODO : // TODO今天没做完,明天做       改完后要删掉注释
2.	导入了没有用的包
3.	注释覆盖率没达到10%
4.	还在用System.out.println()输出语句			应换成log打印
5.	字符串拼接问题	如:	casService = “http://127.0.0.1:” + port + “/ shiro-cas” ;
6.	注释横着写	如:loginDbgContext .port = loginPort ; // =连接器;

莫名的错误(跟校验规则油管)

1.	返回一个List<对象>,Date :	Return a copy of "" 					没问题
2.	public String userId; 使userId成为静态最终常量或非公共常量    一个成员变量要final或static没搞懂
3.	重写clone()就是有问题,  异常后返回null没问题啊

特殊

1.	catch (InterruptedException e) { LOGGER.log(Level.WARN, "Interrupted!", e);}——————线程打断
	InterruptedException这个异常是线程被阻塞,就能捕捉异常,但往往不够,如:	
while(true){
    try {
     Thread.sleep(1000);
    }catch(InterruptedException ex)
    {
          logger.error("thread interrupted",ex);
    } 
}
这个时候其实线程并未中断,执行完这条语句之后线程会继续执行while循环,开始sleep,所以说如果没有对InterruptedException进行处理,后果就是线程可能无法中断
最正确,最合乎规范的是如下:
while(!Thread.isInterrupted()){
    try {
     Thread.sleep(1000);
    }catch(InterruptedException e) {
    	//手动线程打断
         Thread.currentThread().interrupt();
    } 
}

##二、css改错

1.	标签顺序问题
2.	重复的内容定义
3.	i,b 换成  em,strong
4.	img 添加 alt
5.	注释里不应有代码
6.	font-family属性,要在最后加通用字体系列:  sans—serid

三、重复

html 中英页面重复