본문 바로가기
  • SDXL 1.0 + 한복 LoRA
  • SDXL 1.0 + 한복 LoRA

pmd14

[디비파기 | PMD] AddEmptyString 외 2건 AddEmptyString우선순위 : 3The conversion of literals to strings by concatenating them with empty strings is inefficient. It is much better to use one of the type-specific toString() methods instead. 문자열로 형변환을 할 때 빈 문자열로 + 연산을 하는 것은 비효율적이다. 이럴 경우에는 각 타입별로 구현된 toString() 메소드를 이용하는 것이 더 낫다. 샘플 코드12String s = "" + 123; // inefficient String t = Integer.toString(456); // preferred approach AvoidArrayLoop.. 2016. 4. 24.
[디비파기 | PMD] AvoidInstantiatingObjectsInLoops 외 3건 AvoidInstantiatingObjectsInLoops우선순위 : 3New objects created within loops should be checked to see if they can created outside them and reused. Loop 안에서 객체의 인스턴스를 생성할 때는 Loop 밖에서 생성한 후 재사용 가능한지 확인하라 샘플코드12345678public class Something {public static void main( String as[] ) { for (int i = 0; i < 10; i++) {Foo f = new Foo(); // Avoid this whenever you can it's really expensive} }} 부연설명 잘 아다시피 insta.. 2016. 4. 11.
[디비 파기 | PMD] PositionLiteralsFirstInComparisons 외 4건 PositionLiteralsFirstInComparisons우선순위 : 3 Position literals first in comparisons, if the second argument is null then NullPointerExceptions can be avoided, they will just return false. equals()를 통한 비교를 할 때는 항상 상수 값을 앞에 두어야 한다. 만일 두번째 인자가 null인 경우에는 NullPointerException이 발생하지 않으며 단순히 false를 리턴하게 된다. 하지만 상수가 아닌 참조타입의 변수가 앞에 오게 되면 이 변수가 null인 경우 NullPointerException이 발생하게 된다. 샘플 코드12345class Foo {.. 2016. 4. 3.
[디비 파기 | PMD] FinalFieldCouldBeStatic 외 4건 FinalFieldCouldBeStatic우선순위 : 3 컴파일 타임에 상수가 할당되는 final 필드는 자동으로 static으로 변환된다. 따라서 이러한 필드들은 runtime시의 부하를 줄여주기 위해 static을 명시적으로 지정해주는 것이 좋다. 샘플 코드123public class Foo { public final int BAR = 42; // this could be static and save some space} OptimizableToArrayCall우선순위 : 3Calls to a collection’s toArray() method should specify target arrays sized to match the size of the collection. Initial arrays .. 2016. 3. 26.
[디비 파기 | PMD] ConstructorCallsOverridableMethod외 4건 ConstructorCallsOverridableMethod우선순위 : 1영어 실력이 그지같아서 번역이 힘드네요…원문 적고 설명은 샘플 밑에 부연 설명으로 대신하겠습니다.마지막 줄만 설명하자면 일반적인 제어의 흐름을 따르는 메소드 호출을 하라는 것인데 예를들어생성자인 Foo()에서 public 메소드인 buz()를 호출하는 private 메소드 bar()를 호출하는 것과 같이 비비 꼬아놓으면문제의 소지가 있다는 말입니다. 원문Calling overridable methods during construction poses a risk of invoking methods on an incompletely constructed object and can be difficult to debug. It may l.. 2016. 3. 19.
[디비 파기 | PMD] NullAssignment 외 3건 NullAssignment우선순위 : 3코드 중간에서 변수에 null을 할당하는 것은 좋지 않은 형태이다.이런 형태의 할당은 종종 개발자들이 프로그램의 흐름을 이해하지 못하고 코딩을 하고 있다는 표시가 될 수 있다.주의 : 이런 형태의 경우가 드물게는 garbage collectoin에 도움이 되는 경우도 있다. (물론 잘 이해하고 사용했을경우) 이렇게 의도하고 사용한 경우에는 이 룰을 무시해도 좋다. 샘플코드1234567public void bar() { Object x = null; // this is OK x = new Object(); // big, complex piece of code here x = null; // this is not required // big, complex piece .. 2016. 3. 13.
[디비 파기 | PMD] AvoidBranchingStatementAsLastInLoop외 3건 AvoidBranchingStatementAsLastInLoop우선순위 : 2루프의 가장 마지막 위치에서 분기문을 사용하는 경우 버그가 발생할 가능성이 높다.사용한 방법이 버그가 아닌지 확인하거나 다른 접근 방법을 사용해야 한다. 샘플 코드1234567891011121314 // unusual use of branching statement in a loopfor (int i = 0; i 2016. 3. 5.
[디비 파기 | PMD] CheckResultSet CheckResultSet우선순위 : 3Database 사용과 관련하여 ResultSet클래스의 탐색 메소드(next, previous, first, last)를 사용하는 경우반드시 그 리턴 값을 확인하여야 한다. 만일 이 메소드들이 false를 리턴하는 경우 적절한 처리를 해주어야 한다. 샘플 코드11234Statement stat = conn.createStatement();ResultSet rst = stat.executeQuery("SELECT name FROM person");rst.next(); // 나쁜 예. 만일 next()의 결과가 false인 경우에는 어떻게 처리될 것인가?String firstName = rst.getString(1); 샘플 코드212345678Statement sta.. 2016. 2. 28.
[디비 파기 | PMD] BrokenNullCheck BrokenNullCheck우선순위 : 2null 체크가 잘못되어 NullPointerException이 발생하는 경우로 논리 연산자인 &&나 ||를 잘못 사용하여 발생하게 된다. 샘플 코드1234567891011public String bar(String string) { // ||연산자의 특성상 string이 null인경우 string != null은 거짓이 되고 || 연산자는 뒤의 문장도 실행하게 된다. // string이 null이므로 string.equals("")는 NullPointerException을 발생시킨다. if (string!=null || !string.equals("")) return string; // ||연산자의 특성상 string이 null인경우 string == null은.. 2016. 2. 28.
반응형