Sonar Java默认扫描规则

规则如下:

  • ".equals()" should not be used to test the values of "Atomic" classes:equals()方法不应该用在原子类型的数据上(如:AtomicInteger, AtomicLong, AtomicBoolean).
  • "=+" should not be used instead of "+=":"=+"不可以替代 “+=”.
  • "==" and "!=" should not be used when "equals" is overridden:如果继承自对象的 equals method没有被重写,则使用等号"==操作符和equals方法来比较两个对象是等价的,否则不能用等号操作符.
  • "@CheckForNull" or "@Nullable" should not be used on primitive types:"@CheckForNull" 或者 "@Nullable" 注解不应该用于基本类型(byte, short, int, long, float, double, boolean, char).
  • "@Controller" classes that use "@SessionAttributes" must call "setComplete" on their "SessionStatus" objects:使用了“@SessionAttributes”注解的“@Controller”类必须在其“SessionStatus”对象上调用“setComplete”.
  • "@Deprecated" code should not be used:被@Deprecated 注解标注的代码不应该被使用.
  • "@EnableAutoConfiguration" should be fine-uned:@EnableAutoConfiguration”缺点是它可能加载和配置应用程序永远不会使用的bean,因此会消耗比实际需要更多的CPU和RAM。@EnableAutoConfiguration应该配置为排除应用程序不需要的所有bean.
  • "@Import"s should be preferred to "@ComponentScan"s:由于@ComponentScan会减慢项目启动的速度,应该选择显式引入jar包的“@Import”注解,而不是“@ComponentScan”注解.
  • "@NonNull" values should not be set to null:@NonNull注解修饰的字段不能被赋为null, 标记为@NotNull、@NonNull或@NonNull的字段、参数和返回值通常在使用前不检查空值。将这些值中的一个设置为null,或者在构造函数中没有设置这样的类fieldin,可能会在运行时导致nullpointerexception.
  • "@Override" should be used on overriding and implementing methods:在重写和实现方法时,需要添加"@Override"注解.
  • "@RequestMapping" methods should be "public":"@RequestMapping"注解应该用来修饰public方法/类.
  • "@RequestMapping" methods should specify HTTP method:@RequestMapping应该显式的指定HTTP请求的类型.
  • "@SpringBootApplication" and "@ComponentScan" should not be used in the default package:"@SpringBootApplication" 和 "@ComponentScan" 注解不应该在默认包中使用.
  • "action" mappings should not have too many "forward" entries:action映射不应该有太多的“forward”实体.
  • "Arrays.stream" should be used for primitive arrays:流应该被用在基本类型数组上.
  • "Bean Validation" (JSR 380) should be properly configured:"Bean Validation" (JSR 380)应该被正确的配置,未添加@Valid 注解时,Bean Validation 校验将不会生效.
  • "BigDecimal(double)" should not be used:由于精度的原因,BigDecimal(double) 类型不应该被使用,往往会使用valueof()方法将double类型数据进行转化.
  • "catch" clauses should do more than rethrow:catch 捕获到异常之后,不应该仅仅只是抛出异常
  • "Class.forName()" should not load JDBC 4.0+ drivers:“Class.forName()”不应该加载JDBC 4.0+驱动程序
  • "clone" should not be overridden:clone()方法不应该被重写,重写可能导致浅克隆的问题
  • "Cloneables" should implement "clone":Cloneables 接口需要实现 clone()方法
  • "close()" calls should not be redundant:不应该有多余的close()方法的调用
  • "collect" should be used with "Streams" instead of "list::add":使用 Streams 时,应该用 collect,因为collect 的进程是并行且安全的
  • "Collections.EMPTY_LIST", "EMPTY_MAP", and "EMPTY_SET" should not be used:因为"Collections.EMPTY_LIST", "EMPTY_MAP", and "EMPTY_SET"会返回默认的集合,会导致对于返回值判null的步骤缺失的问题,不推荐使用
  • "compareTo" results should not be checked for specific values:“compareTo”结果不应检查特定值,通常检查>0或者<0
  • "compareTo" should not be overloaded:compareTo 参数个数不应该超出声明的个数
  • "compareTo" should not return "Integer.MIN_VALUE":compareTo 的返回值不能是Integer.MIN_VALUE
  • "DateUtils.truncate" from Apache Commons Lang library should not be used:Apache Commons Lang 的日期截取方法 DateUtils.truncate() 不会四舍五入,不应该被使用
  • "default" clauses should be last:switch中 default应该被放在最后
  • "DefaultMessageListenerContainer" instances should not drop messages during restarts:DefaultMessageListenerContainer实例不应该在重启期间删除消息
  • "deleteOnExit" should not be used:java程序执行结束后,有自己的回收机制,不需要用deleteOnExit回收临时文件
  • "Double.longBitsToDouble" should not be used for "int":int类型的数据转换为lone double 会存在精度问题,不应该这样使用
  • "entrySet()" should be iterated when both the key and value are needed:在需要获取map中的键值对key和value时,应该用entryset()方法
  • "enum" fields should not be publicly mutable:集合类型的值不应该是可变的
  • "equals" method overrides should accept "Object" parameters:重载的equals方法,应该能接受object类型的参数
  • "equals" method parameters should not be marked "@Nonnull":equals方法的参数不应该被@Nonnull注解修饰,equals()方法可以接受为null的数据
  • "equals" methods should be symmetric and work for subclasses:equals方法可以应用于子类,因为"=="操作符需要保证两端数据的对称性,但父类不是子类的实例
  • "equals(Object obj)" and "hashCode()" should be overridden in pairs:equals(Object obj)和hashCode()应该成对出现
  • "equals(Object obj)" should be overridden along with the "compareTo(T obj)" method:equals(Object obj)和compareTo(T obj)应该一起重写
  • "equals(Object obj)" should test argument type:因为equals方法能接受泛型参数,所以需要对于传递的参数类型进行验证
  • "Exception" should not be caught when not required by called methods:当调用的方法不需要捕获异常时,不应该捕获到异常(主要针对于运行时异常和检查异常):运行时如果异常应该能正常捕获到,并提醒开发人员调整
  • "Externalizable" classes should have no-arguments constructors:Externalizable 类需要有无参构造函数
  • "File.createTempFile" should not be used to create a directory:File.createTempFile 不够安全,不应该用于创建新的目录
  • "final" classes should not have "protected" members:final 类是不可被继承的,不应该有protected 类型的元素
  • "finalize" should not set fields to "null":finalize 修饰的空间不应该被置为null
  • "for" loop increment clauses should modify the loops' counters:循环增量子句应该修改计数器
  • "for" loop stop conditions should be invariant:循环停止的条件应该是不可变的
  • "getClass" should not be used for synchronization:getClass方法不应该被用在synchronization 修饰的方法中
  • "hashCode" and "toString" should not be called on array instances:array 实例中不应该使用 hashCode 和 toString 方法
  • "HostnameVerifier.verify" should not always return true:HostnameVerifier.verify 不应该一直返回 true
  • "HttpOnly" should be set on cookies:应该在 cookies 中设置 HttpOnly 属性,可以有效地防止XSS攻击
  • "HttpSecurity" URL patterns should be correctly ordered:用HttpSecurity 方法配置url 应该按照一定的声明顺序
  • "HttpServletRequest.getRequestedSessionId()" should not be used:不应该使用 HttpServletRequest.getRequestedSessionId() 方法获取 sessionId
  • "if ... else if" constructs should end with "else" clauses:if ... else if 结构应该以 else 语句结束
  • "indexOf" checks should not be for positive numbers:indexOf()方法结果判断不应该仅针对于正数
  • "indexOf" checks should use a start position:indexOfF方法应该传入起始地址参数
  • "instanceof" operators that always return "true" or "false" should be removed:如果 instanceof 操作符的结果一直返回true或者false,那么相关的调用语句应该被删除
  • "Integer.toHexString" should not be used to build hexadecimal strings:Integer.toHexString方法不应该用于构建16进制字符串
  • "InterruptedException" should not be ignored:不应该忽略InterruptedException(方法阻塞)报错
  • "iterator" should not return "this":iterator()方法不应该返回this
  • "Iterator.hasNext()" should not call "Iterator.next()":Iterator.hasNext()是判断是否有下一个元素,但并不会改变指针指向,而next()会改变指针指向,如果没有下一个元素,会直接报空指针异常
  • "Iterator.next()" methods should throw "NoSuchElementException":Iterator.next() 方法应该抛出 NoSuchElementException 异常
  • "java.lang.Error" should not be extended:java.lang.Error 不应该被继承
  • "java.nio.Files#delete" should be preferred:因为java.nio.Files#delete会抛异常并说明异常的原因,所以在删除文件时应优先考虑java.nio.Files#delete方法
  • "java.time" classes should be used for dates and times:获取日期或者时间,应该使用java.time方法
  • "javax.crypto.NullCipher" should not be used for anything other than testing:javax.crypto.NullCipher 应该只用于测试
  • "Lock" objects should not be "synchronized":被锁定的对象不应该被 synchronized 修饰
  • "main" should not "throw" anything:main方法不应该抛出任何异常
  • "Map.get" and value test should be replaced with single method call:需要同时获取map的键值对时,应该使用单个的获取方法
  • "notifyAll" should be used:应该使用notifyAll方法唤醒所有休眠的进程
  • "null" should not be used with "Optional":Optional修饰的对象不应该被赋值为null
  • "Object.finalize()" should remain protected (versus public) when overriding:Object.finalize() 方法应该只有垃圾回收器才可以调用
  • "Object.wait(...)" and "Condition.await(...)" should be called inside a "while" loop:“Object.wait(…)”和“condition .wait(…)”应该在while循环中调用
  • "Object.wait(...)" should never be called on objects that implement "java.util.concurrent.locks.Condition":实现“java.util.concurrent.locks.Condition”的对 象不应该调用“Object.wait(…)”方法
  • "Preconditions" and logging arguments should not require evaluation:“先决条件”和日志参数不应该需要计算,换言之,在调用"Preconditions" 和 logging 方法时,参数应该是可确定的
  • "PreparedStatement" and "ResultSet" methods should be called with valid indices:应该使用有效的索引(>0)调用“PreparedStatement”和“ResultSet”方法,因为“PreparedStatement”和“ResultSet”方法的索引都是从1开始
  • "private" methods called only by inner classes should be moved to those classes:只由内部类调用的“私有”方法应该放到这些类里
  • "public static" fields should be constant:“公共静态”字段应该是常量
  • "Random" objects should be reused:应该重用“随机”对象:随机数种子在创建一个random对象的时候生成,相同 的随机数种子,产生相同随机数的几率非常高
  • "read" and "readLine" return values should be used:“read”和“readLine”返回值应该被使用
  • "read(byte[],int,int)" should be overridden:read(byte[],int,int)方法应该被重载
  • "readObject" should not be "synchronized":readObject 方法不应该被 同步修饰符(synchronized)修饰
  • "readResolve" methods should be inheritable:“readResolve”方法应该是可继承的,因为readResolve()允许在反序列化期间对于对象的状态进行微调
  • "ResultSet.isLast()" should not be used:不应该使用“ResultSet.isLast()”方法,因为.isLast()方法会将指针的指向移动到下一个元素上,从而可能导致空指针,而.next()方法则是先判断下一个元素是否存在
  • "runFinalizersOnExit" should not be called:不应该调用“runFinalizersOnExit”,因为runFinalizersOnExit()方法可能导致正在被其他进程调用的对象被终止,是不安全的
  • "ScheduledThreadPoolExecutor" should not have 0 core threads:ScheduledThreadPoolExecutor(任务调度进程池)的大小和 corePoolSize的一致,所以 核心进程的个数不能为0
  • "SecureRandom" seeds should not be predictable:“安全随机数”种子不应该是可预测的
  • "Serializable" inner classes of non-serializable classes should be "static":序列化/反序列化方法应该是被static修饰符修饰的
  • "SingleConnectionFactory" instances should be set to "reconnectOnException":“SingleConnectionFactory”实例应该设置为“reconnectOnException”,因为在不启用reconnectOnException设置的情况下使用SingleConnectionFactory将 在连接出错时无法自动恢复连接
  • "StandardCharsets" constants should be preferred:应该首先考虑标准字符集(ISO_8859_1、US_ASCII、UTF_16 、UTF_16BE 、UTF_16LE 、UTF_8)
  • "static" members should be accessed statically:静态常量应该被静态访问
  • "Stream" call chains should be simplified when possible:流的方法调用应当尽可能的简洁
  • "Stream.peek" should be used with caution:.peek()方法主要用于debug,而且仅在对流内元素进行操作时,peek()才会被调用,所以在使用时需要谨慎
  • "StringBuilder" and "StringBuffer" should not be instantiated with a character:"StringBuilder" 和 "StringBuffer"不应该被单个字符实例化
  • "super.finalize()" should be called at the end of "Object.finalize()" implementations:super.finalize()应该在Object.finalize()方法中最后一行被调用,防止系统资源冲突
  • "switch" statements should have "default" clauses:switch()方法中需要用 default子句,控制除了case以外的其他场景
  • "switch" statements should have at least 3 "case" clauses:switch()方法至少需要有3个 case子句,case子句<=2的场景,用if...else即可
  • "switch" statements should not contain non-case labels:“switch”语句不应该包含无case关键字的列举情况
  • "switch" statements should not have too many "case" clauses:switch语句不应该包含太多(>30)的case子句,子句太多时,用map的性能会更高
  • "Thread.run()" should not be called directly:Thread.run()方法不应该被直接调用,因为Thread.run()方法会导致代码在当前进程中被执行
  • "Thread.sleep" should not be used in tests:Thread.sleep()方法不应该在测试过程中被调用
  • "ThreadGroup" should not be used:ThreadGroup()不应该被调用
  • "ThreadLocal.withInitial" should be preferred:应优先考虑ThreadLocal.withInitial()方法
  • "Threads" should not be used where "Runnables" are expected:“线程”不应该使用在预期“可运行项”的地方
  • "throws" declarations should not be superfluous:“throws”声明不应该抛出多个异常
  • "toArray" should be passed an array of the proper type:在没有参数的情况下,.toArray()方法将会返回一个 object,若用.toArray()方法来转换固定类型的数组,需要将正确类型的参数传入
  • "toString()" and "clone()" methods should not return null:"toString()" 和 "clone()"方法,不应该返回null
  • "toString()" should never be called on a String object:在String对象上不应该调用“toString()”
  • "URL.hashCode" and "URL.equals" should be avoided:url的equals和hashCode方法都可能触发名称服务(通常是DNS)查找来解析主机名或IP地址。根据配置和网络状态,这可能需要很长时间,应该避免调用"URL.hashCode" 和 "URL.equals"
  • "volatile" variables should not be used with compound operators:对被volatile修饰的变量不应该进行复合型操作符运 算(应该只进行原子运算)
  • "wait" should not be called when multiple locks are held:当持有多个锁时,不应调用“wait”
  • "wait", "notify" and "notifyAll" should only be called when a lock is obviously held on an object:“wait”、“notify”和“notifyAll”只应在对象上明显持有锁时(如被synchronized修饰)调用
  • "wait(...)" should be used instead of "Thread.sleep(...)" when a lock is held:如果在当前线程持有锁时调用thread .sleep(…),可能会导致性能和可伸缩性问题,或者更糟的情况是死锁。所以当锁被持有时,应该使用“wait(…)”而不是“Thread.sleep(…)”方法
  • "write(byte[],int,int)" should be overridden:当直接子类化java.io.OutputStream 或者 java.io.FilterOutputStream时,因为不能每次传递一个byte的数据,“write(byte[],int,int)”方法应该被重写
  • "writeObject" should not be the only "synchronized" code in a class:“writeObject”不应该是类中唯一的“synchronized”修饰符修饰的方法
  • A "for" loop update clause should move the counter in the right direction:“for”循环更新子句应该将计数器移动到正确的方向
  • A "while" loop should be used instead of a "for" loop:当for循环中只定义了条件表达式,并且缺少初始化和增量表达式时,应该使用while循环来增加可读性
  • A conditionally executed single line should be denoted by indentation:有if条件执行的单行应该用缩进表示(未添加{}时)
  • A field should not duplicate the name of its containing class:字段不应重复其包含的类的名称
  • Abstract classes without fields should be converted to interfaces:没有字段的抽象类应该转换为接口:接口是为了暴露给外部,内部抽象类被继承即可
  • Abstract methods should not be redundant:抽象方法不应该是多余的
  • Accessing Android external storage is security-sensitive:访问Android外部存储是安全敏感的
  • AES encryption algorithm should be used with secured mode:AES加密算法应采用安全模式(ECB模式并不安全,不建议用ECB进行组合)
  • All branches in a conditional structure should not have exactly the same implementation:条件结构(if...else/switch等)中不建议有相同操作的分支
  • An iteration on a Collection should be performed on the type handled by the Collection:对集合的迭代应该是对集合所处理的类型执行
  • Annotation repetitions should not be wrapped:不应该重复包装注解
  • Anonymous inner classes containing only one method should become lambdas:只包含一个方法的匿名内部类应该成为lambdas
  • Array designators "[]" should be located after the type in method signatures:数组指示符“[]”应该位于方法签名中的类型之后
  • Array designators "[]" should be on the type, not the variable:数组指示符“[]”应该位于类型后,而不是变量后
  • Arrays should not be created for varargs parameters:不应该为不定长参数参数创建数组
  • Assertion arguments should be passed in the correct order:应该按照正确的顺序传递断言参数
  • Assertions should be complete:断言应该是完整的
  • Asserts should not be used to check the parameters of a public method:断言不应用于检查公共方法的参数
  • Assignments should not be made from within sub启用expressions:不应该在子表达式中进行赋值
  • Assignments should not be redundant:任务不应该是多余的
  • Authentication should not rely on insecure "PasswordEncoder":身份验证不应该依赖于不安全的“密码编码器”
  • Basic authentication should not be used:不应该使用Basic身份认证方式:Basic 身份认证方式是当前最常用的方式,Base64编码加密后,配合username+password可以满足通常的需求
  • Blocks should be synchronized on "private final" fields:块应该在“private final”修饰的字段上同步
  • Boolean checks should not be inverted:不应该使用反转布尔操作
  • Boolean expressions should not be gratuitous:布尔表达式不应该是完全不变的(应该有改变其值的操作)
  • Boolean literals should not be redundant:不应该进行无意义的布尔计算(如表达式和true/false判等、表达式反转等)
  • Boxing and unboxing should not be immediately reversed:装箱(创建int/Integer类型值的对象)和拆箱(将对象中原始值解出来)不应连续操作
  • Broadcasting intents is security-sensitive:广播意图是不安全的
  • Case insensitive string comparisons should be made without intermediate upper or lower casing:不区分大小写的字符串比较应该在没有中间大小写转化的情况下进行
  • Catches should be combined:相同代码块的Catches 异常操作应该合并
  • Changing or bypassing accessibility is security启用sensitive:更改或绕过可访问性检查是不安全的
  • Child class fields should not shadow parent class fields:子类不应该有和父类的字段名相同的字段
  • Child class methods named for parent class methods should be overrides:子类中重写的与父类方法命名一致的方法,static修饰符等也要和父类保持一致
  • Class names should comply with a naming convention:类名应该符合命名约定
  • Class names should not shadow interfaces or superclasses:类名不应和他实现的接口或父类命名相同
  • Class variable fields should not have public accessibility:类变量字段应该是私有的
  • Classes extending java.lang.Thread should override the "run" method:扩展的 java.lang 线程应该是有重载的run()方法
  • Classes from "sun.*" packages should not be used:"sun.*" packages 不应该被使用,几乎总是由应该使用的Java API类包装
  • Classes named like "Exception" should extend "Exception" or a subclass:像“Exception”这样命名的类应该继承了 “Exception”或其子类,否则不符合清晰、交流式的命名规范
  • Classes should not access their own subclasses during initialization:类在初始化期间不应该访问它们自己的子类
  • Classes should not be compared by name:类不应该按名称进行比较
  • Classes should not be empty:类不应该是空的
  • Classes that override "clone" should be "Cloneable" and call "super.clone()":重载了clone()方法的类应该是实现 Cloneable接口的,并且调用了 super.clone()方法
  • Classes with only "static" methods should not be instantiated:只有静态方法的类不应该被实例化
  • Cognitive Complexity of methods should not be too high:方法的功能复杂度不应过高
  • Collapsible "if" statements should be merged:应该合并无需分层的“if”语句
  • Collection sizes and array length comparisons should make sense:集合大小和数组长度比较应该是有意义的
  • Collection.isEmpty() should be used to test for emptiness:应该使用Collection.isEmpty()来判断是否为空
  • Collections should not be passed as arguments to their own methods:集合不应该作为参数传递给它们自己的方法
  • Composed "@RequestMapping" variants should be preferred:应该首选组合的“@RequestMapping”变体(@GetMapping、@PostMapping)
  • Conditionally executed blocks should be reachable:条件执行的块应该都是可以访问(不能导致死锁)
  • Conditionals should start on new lines:条件句应该从新行开始(if...else.../if..else if.../if...)
  • Configuring loggers is security-sensitive:配置日志记录器是不安全的
  • Constant names should comply with a naming convention:常量名称应该符合命名约定
  • Constants should not be defined in interfaces:常量不应该在接口中定义
  • Constructors should not be used to instantiate "String", "BigInteger", "BigDecimal" and primitive-wrapper classes:构造函数不应该用于实例化“String”、“BigInteger”、“BigDecimal”和原子类包装
  • Consumed Stream pipelines should not be reused:使用的流管道不应重用
  • Controlling permissions is security-sensitive:权限控制是不安全的:有权限划分控制,才能满足不同的用户权限的不同,从而抵御黑客攻击
  • Cookie domains should be as narrow as possible:Cookie域设置应该尽可能的详细
  • Creating cookies without the "secure" flag is security-sensitive:创建没有“secure”标志的cookie是不安全的
  • Credentials should not be hard-coded:凭证不应该直接赋值(需要通过调用方法等方式去获取)
  • Cryptographic keys should not be too short:秘钥不应该太短(对于Blowfish算法,密钥至少128位长,对于RSA算法,密钥至少2048位长。)
  • Cryptographic RSA algorithms should always incorporate OAEP (Optimal Asymmetric Encryption Padding):密码RSA算法应该始终包含OAEP(最佳非对称加密填充)
  • Custom serialization method signatures should meet requirements:自定义序列化方法签名应满足要求(作用域的限制等)
  • Databases should be password启用protected:数据库应该有密码保护
  • Dead stores should be removed:死存储的变量代码应该被移除
  • Declarations should use Java collection interfaces such as "List" rather than specific implementation classes such as "LinkedList":类中字段声明应该使用Java集合接口,如“List”“Set”
  • Default EJB interceptors should be declared in "ejb-jar.xml":缺省EJB拦截器应该在“EJB 启用jar.xml”中声明。
  • Defined filters should be used:已定义的过滤器应该被调用
  • Delivering code in production with debug features activated is security-sensitive:在生产环境中交付被激活的调试特性的代码是不安全的
  • Dependencies should not have "system" scope:依赖声明中不应该包含system scope
  • Deprecated "${pom}" properties should not be used:弃用的${pom}特性不应该再被使用
  • Deprecated code should be removed:弃用的代码应该被删除
  • Deprecated elements should have both the annotation and the Javadoc tag:被弃用的代码块应该添加@Deprecated注解以及标签
  • Deserializing objects from an untrusted source is security-sensitive:从不可信源反序列化对象是不安全的
  • Deserializing with XMLDecoder is security-sensitive:反序列化XMLDecoder对象是不安全的
  • Disabling Spring Security's CSRF protection is security-sensitive:禁用spring的跨域资源共享(CSRF)保护是不安全的
  • Dissimilar primitive wrappers should not be used with the ternary operator without explicit casting:在没有显式强制转换的情况下,不应该将不同的基本类型与三元运算符一起使用
  • Double Brace Initialization should not be used:不应该使用双花括号初始化
  • Double-checked locking should not be used:不应该使用双重检查锁定
  • Empty arrays and collections should be returned instead of null:需要返回数组/集合的方法,应该返回空数组/集合,而不是null
  • Empty statements should be removed:应该删除空语句(如仅一个;)
  • Enabling Cross-Origin Resource Sharing is security-sensitive:启用跨域资源共享是不安全的
  • Encrypting data is security-sensitive:(不具备随机性的)加密数据是不安全的
  • Enumeration should not be implemented:枚举不应该像其他接口一样被实现,而复制后的迭代器是可以被实现的
  • Exception classes should be immutable:异常类应该是不可变的
  • Exception should not be created without being thrown:创建的异常应该被抛出
  • Exception types should not be tested using "instanceof" in catch blocks:不应该在 catch代码块中用instanceof对异常的类型进行判断处理
  • Exceptions should be either logged or rethrown but not both:异常应该被记录或者抛出,但不能同时被记录和抛出:存在通过日志将异常打印,同时让异常被其他的进行捕获的场景
  • Exceptions should not be thrown from servlet methods:不应该从servlet方法中抛出异常
  • Exceptions should not be thrown in finally blocks:不应该在 finally中抛出异常
  • Execution of the Garbage Collector should be triggered only by the JVM:垃圾回收器只能由JVM触发
  • Expanding archive files is security-sensitive:展开归档文档是不安全的(应该验证归档文件展开的路径;不应展开到可以展开存档文件的根目录之外;应用程序应该控制扩展数据的大小,以避免成为Zip炸弹攻击的受害者)
  • Expressions used in "assert" should not produce side effects:“断言”中使用的表达式不应该需要计算(由于assert语句在默认情况下不被执行(断言必须使用JVM标志启用),永远不应该依赖于他们的解决方案来评估正确程序功能所需的任何逻辑。)
  • Factory method injection should be used in "@Configuration" classes:当在@Configuration修饰的类中使用@Autowired时,依赖关系需要在类实例化前得到解决,这可能会导致bean的早期初始化出问题,或者导致上下文查找不应该找到bean的位置。为了避免这个棘手的问题并优化上下文加载的方式,应该尽可能晚地请求依赖项。这意味着对于仅在单个@Bean方法中使用的依赖项,使用参数注入而不是字段注入。
  • Field names should comply with a naming convention:字段名应该符合命名约定(正则表达式)
  • Fields in a "Serializable" class should either be transient or serializable:“可序列化”类中的字段应该是可转换的或可序列化的
  • Fields in non-serializable classes should not be "transient":不可序列化的类中的字段不应该被"transient"关键字修饰
  • Files opened in append mode should not be used with ObjectOutputStream:在append 模式下打开的文件不应该和ObjectOutputStream一起使用
  • Formatting SQL queries is security-sensitive:格式化SQL查询是不安全的
  • Future keywords should not be used as names:关键字不应该用作名称,可能无法被解析
  • Generic exceptions should never be thrown:永远不应该抛出泛型异常
  • Generic wildcard types should not be used in return parameters:方法返回的参数类型不应该是泛型:可以对于子类继承的父类A和子类A1本身进行相同的操作,但是返回的类型不同,此处需要返回参数为泛型
  • Getters and setters should access the expected fields:getter和setter方法应该访问预期的字段
  • Getters and setters should be synchronized in pairs:getter和setter应该成对同步
  • Hashing data is security-sensitive:哈希数据是不安全的(为了安全目的,只使用目前已知较强的哈希算法。完全避免在安全上下文中使用MD5和SHA1之类的算法。)
  • Hibernate should not update database schemas:Hibernate不应该更新数据库模式(hibernate.hbm2ddl.auto只有在validate时才可以使用,否则可能导致数据库的模式被更改)
  • Identical expressions should not be used on both sides of a binary operator:不应该在二元操作符的两边使用相同的表达式
  • IllegalMonitorStateException should not be caught:不应该捕获非法的monitorstateexception异常
  • Inappropriate "Collection" calls should not be made:不应该做不合适的Collection方法调用(当提供给Collection.remove()/Collection.contains()方法的对象的实际类型与集合实例化的declaredon类型不一致时,这些方法总是返回false或null)
  • Inappropriate regular expressions should not be used:不应该使用不合适的正则表达式
  • Inheritance tree of classes should not be too deep:类的继承树不应该太深(限制5层)
  • Inner class calls to super class methods should be unambiguous:对超类方法的内部类的调用应该是明确的
  • InputSteam.read() implementation should not return a signed byte:InputSteam.read()的实现不应该返回带符号的字节(java文档注明,InputSteam.read()方法的值字节必须是0到255范围内的整数。如果由于到达了流的末尾而没有可用的字节,则返回值启用1。)
  • Instance methods should not write to "static" fields:“static ”字段不应该在实例方法中处理
  • Interface names should comply with a naming convention:接口的命名应该符合命名规范(的正则表达式)
  • Intermediate Stream methods should not be left unused:中间流方法不应该闲置,应该提供对应的终端操作(流操作有两种类型:中间操作(返回另一个流)和终端操作(返回比流更多的内容)。中间操作是惰性的,如果中间流操作的结果没有提供给终端操作,那么它就没有任何作用)
  • Ints and longs should not be shifted by zero or more than their number of bits-1:int和long类型数据的位移不应该>或者等于0
  • Invalid "Date" values should not be used:不应使用无效的“日期”值(需要确定year\month\day的有效取值范围)
  • Java 8 features should be preferred to Guava:Java 8特性应该优先于Guava特性(Guava特性修复了java7中一些缺少的Api,在java8中,这些Api被修复)
  • Java 8's "Files.exists" should not be used:java8中不应该使用"Files.exists"方法(exists方法在JDK 8中性能明显较差,当用于检查实际上不存在的文件时,会显著降低应用程序的运行速度。)
  • Jump statements should not be redundant:不应该有多余的跳转语句
  • Jump statements should not occur in "finally" blocks:跳转语句(break, continue, return, throw, goto)不应该出现在finally代码块中
  • JUnit assertions should not be used in "run" methods:JUnit断言不应该在“run”方法中使用
  • JUnit framework methods should be declared properly:应该正确地声明JUnit框架方法(命名要正确)
  • JUnit rules should be used:应该使用JUnit规则(没有被使用的任何测试类字段都不应该被定义)
  • JUnit test cases should call super methods:JUnit测试用例应该调用super()方法
  • Labels should not be used:Labels 不应该被使用
  • Lambdas containing only one statement should not nest this statement in a block:只包含一条语句的Lambdas(匿名函数)不应该将此语句嵌套在块中(无需用{})
  • Lambdas should be replaced with method references:应该用方法引用替换Lambdas(匿名函数)
  • LDAP connections should be authenticated:应该对LDAP连接进行身份验证
  • LDAP deserialization should be disabled:应该禁用LDAP反序列化
  • Local variable and method parameter names should comply with a naming convention:局部变量和方法参数的名称应该符合命名约定
  • Local variables should not be declared and then immediately returned or thrown:不应该在声明局部变量后,立即将变量返回或抛出
  • Local variables should not shadow class fields:局部变量不应该和类字段同名
  • Locks should be released:锁应该被释放
  • Loggers should be named for their enclosing classes:日志记录器应该用他们的封闭类来命名
  • Loop conditions should be true at least once:循环体至少需要被执行一次
  • Loops should not be infinite:循环不应该是无限的
  • Loops should not contain more than a single "break" or "continue" statement:循环应该只包含一个“break”或“continue”语句
  • Loops with at most one iteration should be refactored:最多只执行一次的循环应该被重构
  • Map values should not be replaced unconditionally:不应该无条件的替换映射(Map)值
  • Maps with keys that are enum values should be replaced with EnumMap:带有enum值键的映射应该替换为EnumMap
  • Math operands should be cast before assignment:应该在数学计算之前,至少对一个操作数完成对最终类型的强制类型转换
  • Method names should comply with a naming convention:方法的命名应该满足命名规则
  • Method overrides should not change contracts:方法重写不应更改约定(超类方法参数如果被@Nullable、@CheckForNull、@NotNull、@NonNull和@NonNull修饰,则子类重写的方法参数也应该有相应的限制)
  • Method parameters, caught exceptions and foreach variables' initial values should not be ignored:方法参数、捕获的异常和foreach变量的初始值不应该被忽略
  • Methods "wait(...)", "notify()" and "notifyAll()" should not be called on Thread instances:方法”wait(…)”,“notify()”和“notifyAll()”不应该在线程实例上调用
  • Methods and field names should not be the same or differ only by capitalization:类里面的方法和字段名不应该完全相同或者仅大小写不同
  • Methods and field names should not be the same or differ only by capitalization:在随机整数生成中,不应该使用返回浮点值的“随机”方法
  • Methods returns should not be invariant:方法返回不应该是不变的
  • Methods should not be empty:方法不应该是空的
  • Methods should not be named "tostring", "hashcode" or "equal":方法不应该被命名为“tostring”、“hashcode”或“equal”
  • Methods should not call same-class methods with incompatible "@Transactional" values:方法不应该调用具有不兼容的“@Transactional”值的同类方法
  • Methods should not have identical implementations:两个方法不应该有相同的实现
  • Methods should not have too many parameters:方法不应该有太多的参数
  • Methods should not return constants:方法不应该返回常量
  • Min and max used in combination should not always return the same value:组合使用的Min和max不应该总是返回相同的值
  • Modifiers should be declared in the correct order:修饰符应该按照正确的顺序声明
  • Multiline blocks should be enclosed in curly braces:多行代码块应该用大括号括起来
  • Multiple variables should not be declared on the same line:多个变量不应该在同一行中声明
  • Mutable fields should not be "public static":可变字段不应该是“public static”
  • Neither "Math.abs" nor negation should be used on numbers that could be "MIN_VALUE":Math.abs 和逻辑非的运算不应该作用在可以设置为 MIN_VALUE 的数字上
  • Neither DES (Data Encryption Standard) nor DESede (3DES) should be used:不应该使用DES(数据加密标准)或DESede (3DES)
  • Nested "enum"s should not be declared static:嵌套的“枚举”类型不应该声明为静态的
  • Nested blocks of code should not be left empty:嵌套的代码块不应该是空的
  • Nested code blocks should not be used:不应该使用嵌套代码块
  • Non-constructor methods should not have the same name as the enclosing class:非构造函数方法不应该具有与所包含类相同的名称
  • Non-primitive fields should not be "volatile:非基础字段(数组、对象等)不应该被volatile 修饰符修饰
  • Non-public methods should not be "@Transactional":不应该在非public方法上添加@Transactional注解
  • Non-serializable classes should not be written:类应该都是可序列化的
  • Non-serializable objects should not be stored in "HttpSession" objects:不可序列化的对象不应该存储在“HttpSession”对象中
  • Non-thread-safe fields should not be static:非线程安全字段不应该是静态的
  • Null checks should not be used with "instanceof":判空检查不应与“instanceof”一起使用。
  • Null pointers should not be dereferenced:不应该取消对空指针的引用
  • Null should not be returned from a "Boolean" method:不应该从返回值为“布尔”类型的方法返回Null
  • Nullness of parameters should be guaranteed:应保证方法参数不为空
  • Objects should not be created only to "getClass":对象不应该只为了“getClass”方法创建(仅仅为了调用getClass而创建对象是对内存和周期的浪费)
  • Only static class initializers should be used:应该只使用静态初始化方法
  • Optional value should only be accessed after calling isPresent():在调用get()方法之前,应该先判空处理
  • Overrides should match their parent class methods in synchronization:子类重写的方法应该与父类方法的同步保持一致
  • Overriding methods should do more than simply call the same method in the super class:子类中重写一个方法不应该只是为了简单的调用父类的同名方法
  • Package declaration should match source file directory:包声明应该匹配源文件目录
  • Package names should comply with a naming convention:包的名称应该符合命名规则
  • Packages containing only "package-info.java" should be removed:只包含"package启用info.java" 包应该被删除
  • Parameters should be passed in the correct order:方法的参数应该按照正确的顺序传递
  • Parentheses should be removed from a single lambda input parameter when its type is inferred:仅带单参数的lambda(匿名函数),应该将该参数的圆括号删除
  • Parsing should be used to convert "Strings" to primitives:可以使用解析方法将String解析为期望的基本类型
  • Persistent entities should not be used as arguments of "@RequestMapping" methods:持久化实体不应该用作“@RequestMapping”方法的参数
  • Primitive wrappers should not be instantiated only for "toString" or "compareTo" calls:应该使用基本包装器类的静态toString()或compare方法。
  • Primitives should not be boxed just for "String" conversion:不应该为了调用toString方法而将基本类型的数据进行类型转换
  • Printf-style format strings should be used correctly:Printf启用style格式字符串应该被正确使用(Printf-style的字符串是在运行时解释的,而不是由编译器验证的,所以它们可能包含导致创建错误字符串的错误)
  • Printf-style format strings should not lead to unexpected behavior at runtime:Printf-style 格式字符串不应该在运行期间导致意外的操作发生
  • Private fields only used as local variables in methods should become local variables:只在方法中用作局部变量的私有字段应该设置为局部变量
  • Public constants and fields initialized at declaration should be "static final" rather than merely "final":在初始化时声明的公共常量和字段应该是“static final”,而不仅仅是“final”。
  • Raw byte values should not be used in bitwise operations in combination with shifts:带符号的原始字节值不应该进行位移操作
  • Reading the Standard Input is security-sensitive:读取标准输入的数据是不安全的
  • Receiving intents is security-sensitive:公开的接收器是不安全的
  • Redundant casts should not be used:不应该使用冗余类型转换
  • Redundant pairs of parentheses should be removed:应该删除多余的括号
  • Reflection should not be used to check non-runtime annotations:反射不应用与检查非运行时注解(只有已被赋予运行时保留策略的注释才可用于反射。使用其他保留策略测试总是返回false)
  • Related "if/else if" statements should not have the same condition:相关的if.../else if...代码块中不应该有相同的判断条件
  • Resources should be closed:(实现close - able接口或其超级接口autoclose - able的连接、流、文件和其他)类在使用后需要关闭。必须在finally块else中执行close调用,否则将无法执行调用。
  • Return of boolean expressions should not be wrapped into an "if-then-else" statement:布尔表达式的返回不应该封装到“if-then-else”语句中
  • Return values from functions without side effects should not be ignored:不应该忽略没有副作用的函数的返回值(可能是无效代码,或者代码的效果与预期不符)
  • Return values should not be ignored when they contain the operation status code:不应该忽略返回值中包含的操作状态代码
  • Sections of code should not be commented out:不应该保留被注释的代码
  • Sending emails is security-sensitive:代码中发送电子邮件是不安全的
  • Servlets should not have mutable instance fields:Servlets实例中不应该包含可变的字段
  • Setting JavaBean properties is security启用sensitive:设置javaBean属性是不安全的
  • Short-circuit logic should be used in boolean contexts:短路逻辑应该在布尔上下文中使用
  • Silly bit operations should not be performed:有些可预期得到结果的位操作(如&启用1得到原始值)是不需要执行的
  • Silly equality checks should not be made:一些对等检查是不需要做的(不同类型的判等、两个数组的判等)
  • Silly math should not be performed:一些可预测结果的数学运算不需要做(如x%1)
  • SMTP SSL connection should check server identity:SMTP SSL连接应该检查服务器标识
  • Source files should not have any duplicated blocks:原文件中不应该存在重复的块
  • Standard outputs should not be used directly to log anything:应该使用日志程序记录输出内容(便于检索
  • Static fields should not be updated in constructors:不应该在构造函数中更新静态的字段
  • Static non-final field names should comply with a naming convention:被static修饰(但未被final修饰)的字段,命名应该符合命名规范
  • String function use should be optimized for single characters:字符串函数(如indexOf(“”))的使用应该优化为单个字符
  • String literals should not be duplicated:字符串文字不应该重复
  • String offset-based methods should be preferred for finding substrings from offsets:基于字符串偏移量的方法才应该是从偏移量中寻找子字符串的首选方法
  • String.valueOf() should not be appended to a String:valueof()不应该被附加到字符串中
  • Strings and Boxed types should be compared using "equals()":字符串内容以及数据类型的比较应该使用equals()方法
  • Strings should not be concatenated using '+' in a loop:字符串在遍历过程中不应该通过"+"号来进行扩展(应该使用append())
  • Struts validation forms should have unique names:Struts验证表单应该名称惟一
  • Subclasses that add fields should override "equals":父类中包含equals()方法,添加了字段的子类中需要重写equals()方法
  • Switch cases should end with an unconditional "break" statement:Switch case应该以无条件的“break”语句结束
  • Synchronization should not be based on Strings or boxed primitives:同步不应该基于字符串或基础类型的数据
  • Synchronized classes Vector, Hashtable, Stack and StringBuffer should not be used:不应该使用Synchronized 修饰类向量、散列表、堆栈和StringBuffer
  • Ternary operators should not be nested:三元式运算不应该嵌套
  • TestCases should contain tests:测试用例文件中应该包含测试方法
  • Tests should include assertions:测试应该包含断言(该条规则支持自扩展)
  • Tests should not be ignored:不应该跳过测试
  • The default unnamed package should not be used:不应该使用默认的未命名包
  • The diamond operator ("<>") should be used:应该使用diamond操作符(“<>”)(不必在声明和构造函数中都声明List的类型,可以使用<>简化构造函数声明,编译器将推断出类型。)
  • The non-serializable super class of a "Serializable" class should have a no-argument constructor:可序列化类的不可序列化超类应该包含无参的构造函数
  • The Object.finalize() method should not be called:不应该调用Object.finalize()方法(Object.finalize()方法应该由垃圾回收器调用)
  • The Object.finalize() method should not be overriden:Object.finalize()不应该被重载(应该只由垃圾回收器调用)
  • The signature of "finalize()" should match that of "Object.finalize()":“finalize()”的签名应该与“Object.finalize()”的签名匹配(Object.finalize()方法应该由垃圾回收器调用,其他方法不应该命名为finalize)
  • The value returned from a stream read should be checked:应该检查从流读取的返回值的长度是否大于0(不能保证流返回的不是0字节)
  • Throwable and Error should not be caught:Throwable 和 Error 不应该被捕获(Throwable 是所有异常的超类, Error是所有错误的超类,程序捕捉到也无法处理)
  • Throwable.printStackTrace(...) should not be called:printstacktrace(…)不应该被调用(默认情况下,printstacktrace(…)将一个Throwable及其堆栈信息打印到某个流,这可能会无意中暴露敏感信息)
  • Track uses of "FIXME" tags:跟踪“FIXME”标签的使用(FIXME标记通常用于标记怀疑有bug的地方,但是开发人员希望稍后处理这些地方。)
  • Track uses of "TODO" tags:跟踪“TODO”标签
  • TrustManagers should not blindly accept any certificates:TrustManagers(信托管理) 不能盲目的接受任何证书
  • Try-catch blocks should not be nested:不应该嵌套的使用try-catch代码块
  • Try-with-resources should be used:应该使用try-with启用resources 结构(代替try-finally结构)
  • Two branches in a conditional structure should not have exactly the same implementation:(switch启用case/if...else if/if...else)条件结构中的两个分支不应该具有完全相同的实现
  • Type parameter names should comply with a naming convention:类型参数名称应该符合命名约定
  • Unary prefix operators should not be repeated:不应该重复使用一元表达式的前缀操作符(针对于“!, ~, 启用, +”)
  • Unnecessary imports should be removed:应该删除不必要的import
  • Untrusted XML should be parsed with a local, static DTD:不可信的XML应该使用本地静态DTD进行解析
  • Unused "private" classes should be removed:应该删除未使用的private类(未使用的私有类属于死代码)
  • Unused "private" fields should be removed:未使用的 private字段应该被删除(死代码应该被处理)
  • Unused "private" methods should be removed:未使用的private方法应该被删除(死代码应该被清理)
  • Unused labels should be removed:未使用的标签应该被删除
  • Unused local variables should be removed:未使用的局部变量应该被删除
  • Unused method parameters should be removed:方法中未使用的参数应该被删除
  • Unused type parameters should be removed:未使用的方法返回参数类型应该被删除
  • URIs should not be hardcoded:URI永远不应该硬编码,应该用可定制的参数替换它,保证代码的可移植性(此外,即使动态获取URI的元素,如果路径分隔符是硬代码,那么可移植性仍然是有限的)
  • Using command line arguments is security-sensitive:使用命令行参数是不安全的
  • Using environment variables is security-sensitive:使用环境变量是不安全的
  • Using hardcoded IP addresses is security-sensitive:硬编码(直接编码)IP地址是不安全的
  • Using non-standard cryptographic algorithms is security-sensitive:使用非标准的密码编码算法是不安全的
  • Using pseudorandom number generators (PRNGs) is security-sensitive:使用伪随机数生成器是不安全的(确定的算法产生的随机数都是伪随机数,很容易被黑客获取seed从而破解)
  • Using regular expressions is security-sensitive:使用正则表达式是不安全的(影响性能),改为提醒:
  • Using Sockets is security-sensitive:(直接)使用套接字是不安全的
  • Using unsafe Jackson deserialization configuration is security-sensitive:不应该使用不安全的JACKSON反序列化方法(如果可能,使用@JsonTypeInfo(use = Id. name)代替@JsonTypeInfo(use = Id. class)或@JsonTypeInfo(use = Id. MINIMAL_CLASS),因此需要使用@JsonTypeName和@JsonSubTypes注解)
  • Utility classes should not have public constructors:Utility 是静态类,不能被实例化,就算扩展,也不应该有公共的构造函数
  • Validating SSL/TLS connections is security-sensitive:验证SSL/TLS链接是不安全的(SSL/TLS协议加密网络连接,服务器通常提供一个数字证书来证明其身份。接受所有SSL/TLScertificates会使应用程序容易受到中间人攻击(Man启用in启用the启用middle attack, MITM)的攻击。)
  • Value-based classes should not be used for locking:基于值的类不应该用于锁定(基于值的类只为了作为值的包装器,没有构造函数,通过工厂化方法实例化,不会指定返回实例的标识)
  • Values should not be uselessly incremented:值不应该毫无意义的递增
  • Variables should not be self-assigned:变量不应该自赋值
  • Weak SSL protocols should not be used:不应该使用弱SSL协议
  • Web applications should not have a "main" method:web应用不应该有main()方法
  • Week Year ("YYYY") should not be used for date formatting:日期格式不应使用Week Year ("YYYY") (因为存在一周中跨年的情况)
  • Writing cookies is security-sensitive:编写cookies是不安全的(cookie应该只用于管理用户会话。最佳实践是将所有与用户相关的信息保存在服务器端,并将它们链接到用户会话,而不是将它们发送到客户机)
  • XML transformers should be secured:XML 转换程序应该受到保护
  • Zero should not be a possible denominator:0不应该被作为分母

版权声明:著作权归作者所有。

相关推荐

Ubuntu修改docker安装image的默认路径

Docker的镜像默认安装在/var/lib/docker,如果要修改镜像的安装路径,可以在配置文件daemon.json中指定。在Linux系统daemon.json默认路径为/etc/docker/daemon.json。在daemon.json添加配置graph,如:$ sudo vim /etc/docker/daemon.json {   

Html对加载失败的图片使用默认图片替换

在img标签使用onerror监听图片的加载,如果出现错误:1、设置onerror=null,这是为了避免default.png也加载失败2、把图片的src属性设置为默认图片的url,加载默认图片替换。<img src="myimg.png" onError="this.onerror=null;this.src='default.png';&quo

MySQL类型隐式转换规则

在MySQL语句里,如果操作符应用于不同的类型的操作数,为了兼容让操作数兼容,MySQL会对操作数做类型转换,有些是自动的隐式转换。“+”号操作符使用“+”号相加的是字符串或字符串和数字,字符串会隐式转换为数字。以数字开头的字符串以数字开头的字符串,它会截取前面的数字字符串,转换为对应的数字。mysql> select '1a' + 1; +-----

使用Swift 3/Swift 4扫描二维码

iOS的AVFoundation内置了对二维码和条形码扫描的支持。使用AVFoundation扫描二维码的功能需要几件事:创建AVCaptureSession,用于捕获二维码创建预览捕获二维码成功后,委派回调来处理二维码的meta信息下面的例子是基于UIViewController开发的扫描二维码Controller,使用AVCaptureMetadataOutputObjectsDelegate

AngularJS非字符插值计算规则

在AngularJS里,插值会把嵌入的表达式转换为字符串,对于非字符串转换规则如下:1、undefined和null转换为空字符串''。2、如果值是一个Object对象,但不是Number,Date和Array类型,$interpolate变量会先查找用户自定义的toString()函数,如果找到了,使用toString()函数来转换为字符串。注意,这里的用户自定义意味myObject.toStr