INTERNAL: Adjust @NonNullApi and @NonNullFields using package-info.#97
INTERNAL: Adjust @NonNullApi and @NonNullFields using package-info.#97uhm0311 wants to merge 1 commit intonaver:developfrom
@NonNullApi and @NonNullFields using package-info.#97Conversation
| @Nullable | ||
| private ArcusClientPool client; | ||
| @Nullable | ||
| private String url; | ||
| @Nullable | ||
| private String serviceCode; |
There was a problem hiding this comment.
생성자에서 null이 아닌 값을 넣어주지 않기 때문에 처음 객체를 생성하면 null이 들어갑니다.
그래서 @Nullable을 붙였습니다.
|
|
||
| ConnectionFactoryBuilder cfb = new ConnectionFactoryBuilder() | ||
| .setFrontCacheExpireTime(frontCacheExpireTime) | ||
| .setTimeoutExceptionThreshold(timeoutExceptionThreshold) | ||
| .setFrontCacheCopyOnRead(frontCacheCopyOnRead) | ||
| .setFrontCacheCopyOnWrite(frontCacheCopyOnWrite) | ||
| .setMaxReconnectDelay(maxReconnectDelay); | ||
|
|
||
| if (maxFrontCacheElements > 0) { | ||
| cfb.setMaxFrontCacheElements(maxFrontCacheElements); | ||
| } | ||
| if (globalTranscoder != null) { | ||
| cfb.setTranscoder(globalTranscoder); | ||
| } | ||
|
|
||
| client = ArcusClient.createArcusClientPool(url, serviceCode, cfb, poolSize); |
There was a problem hiding this comment.
ZK 접속 주소와 서비스 코드가 null이 아님을 검증하기 위해 ArcusClientPool 객체를 여기서 생성합니다.
기존과 같이 getObject() 메소드에서 생성하되, 프로퍼티의 검증 코드를 중복으로 복사하는 방법이 있습니다.
getObject() 메소드 내에서 afterPropertiesSet()을 호출하는 경우 IDE가 url과 serviceCode의 null 여부 검증을 인식하지 못해서 검증 코드를 복사해야 합니다.
Assert.notNull(this.url, "Url property must be provided.");
Assert.notNull(this.serviceCode, "ServiceCode property must be provided.");
Assert.isTrue(this.poolSize > 0, "PoolSize property must be larger than 0.");
Assert.isTrue(this.timeoutExceptionThreshold > 0, "TimeoutExceptionThreshold must be larger than 0.");
Assert.isTrue(this.maxReconnectDelay > 0, "MaxReconnectDelay must be larger than 0.");| private int frontExpireSeconds; | ||
| private long timeoutMilliSeconds = DEFAULT_TIMEOUT_MILLISECONDS; | ||
| private ArcusClientPool arcusClient; | ||
| private ArcusClientPool arcusClient = new ArcusClientPoolPlaceholder(); |
There was a problem hiding this comment.
arcusClient 필드가 가장 @Nullable을 붙일지 말지 애매한 필드입니다.
본 변경사항은 @Nullable을 붙이는 대신 Placeholder 개념의 초기값을 넣어주는 것입니다.
이 필드에 @Nullable을 붙이면 IDE는 캐시 연산을 위해 이 필드에 참조할 때마다 null 여부를 체크해야 한다고 합니다.
이 필드에 @Nullable을 붙이지 않으면 처음에 null이 들어가고 있다고 알립니다.
ArcusCacheManager를 사용하지 않는 경우 객체 생성 시 처음에는 null이 들어가기 때문입니다.
단, ArcusCacheManager를 사용하는 경우 생성자에서 null이 아닌 값을 할당합니다.
There was a problem hiding this comment.
여기에 대한 제 생각은 다음과 같습니다. @jhpark816님도 의견 주시면 좋을 것 같습니다.
- Placeholder 대신
@Nullable을 붙입니다. IDE를 사용하지 않는 배포 환경에는 영향이 없기 때문에 문제가 될 것 같지 않습니다. - 인자가 없는 public 생성자를 deprecate하고 필수 인자를 받는 생성자를 제공합니다.
- 인자가 없는 public 생성자가 제거되는 시점에 필수 인자에 대한
@Nullable도 제거합니다.
src/main/java/com/navercorp/arcus/spring/cache/ArcusCacheConfiguration.java
Show resolved
Hide resolved
| return 0; | ||
| } | ||
| return key.hashCode() & (mutexes.length - 1); | ||
| return Objects.hashCode(key) & (mutexes.length - 1); |
There was a problem hiding this comment.
key 매개변수는 개념적으로 null이 아니어야 합니다.
하지만 null 체크하는 if문을 제거하면, 기존에 null을 넣던 곳에서 NullPointerExcpetion이 발생합니다.
Objects.hashCode() 메소드는 내부적으로 null 체크를 해주어 null인 경우 0을 반환하고 그렇지 않으면 Object.hashCode() 값을 반환하므로 null인 경우와 그렇지 않은 경우 모든 동작이 동일합니다.
| this.name = this.getNamePlaceholder(); | ||
| this.serviceId = this.getServiceIdPlaceholder(); |
There was a problem hiding this comment.
이 두 필드는 내부 로직적으로 null이 아닌 값으로 동작합니다
하지만 ArcusCacheManager를 사용하지 않는다면 처음에는 null이 들어갑니다.
@Nullable을 붙이는 대신 Placeholder 개념의 초기값을 넣어줍니다.
| public ArcusCacheConfiguration() { | ||
| this.serviceId = this.getServiceIdPlaceholder(); | ||
| } | ||
|
|
There was a problem hiding this comment.
ArcusCache 생성자에서 serviceId에 Placeholder 개념의 초기값을 넣어주는 것과 동일합니다.
|
@uhm0311 @jhpark816 |
|
FactoryBean이 아니어도 Placeholder를 두는 곳은 있습니다. |
|
지난 PR변경사항들과 JDK8버전으로 올라간 develop 브랜치상 기록을 봤을 때 <dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>${com.google.code.findbugs.version}</version>
<scope>provided</scope>
</dependency> |
|
@kiheyunkim Arcus Spring의 경우 Compile Warning이 발생하면 컴파일이 되지 않도록 설정해두고 개발하고 있습니다. Spring 문서에서도 이에 관련한 내용을 다루고 있습니다. |
|
@uhm0311 @oliviarla |
🔗 Related Issue
⌨️ What I did
@Nullable을 붙입니다.@Nullable설정을 어디까지 붙일지가 애매하여 논의가 필요합니다.