https://blog.csdn.net/liumiaocn/article/details/83550309
https://note.youdao.com/ynoteshare1/index.html?id=3c1e6a08a21ada4dfe0123281637e299&type=note
?https://blog.csdn.net/liumiaocn/article/details/83550309
?
?
?
文本版:
soanr規則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不應該被作為分母
?