ASH84

Software Engineer/Developer, co-founder of Payhere. Ex-Banksalad. Intereseted in iteroperability, bootstrap company, writting.

[findbugs] FileWriter, FileReader DM_DEFAULT_ENCODING 처리하기

created:2012-04-14
updated:2015-07-03
edit

findbugs를 통해서 잠재적 위험 검사를 할때, 일반적으로 텍스트 파일을 읽거나 쓰는 코드에서 DMDEFAULTENCODING 경고가 뜬다. 


해당 잠재적 위험에 대한 내용을 살펴보면,


Bug

Found reliance on default encoding in com.logamg.analysis.LogAnalysis.analysisLog(String): new java.io.FileReader(File) Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable. This will cause the application behaviour to vary between platforms. Use an alternative API and specify a charset name or Charset object explicitly.


Confidence: High, Rank: Of Concern (19)
Pattern: DMDEFAULTENCODING 
Type: Dm, Category: I18N (Internationalization


 

즉, 인코딩 지정에 대한 문제이다. 사실 위의 코드의 부분에서의 문제가 아니라, FileReader 나 FileWriter 를 BufferedReader, BufferedWriter 쓸때 문제가 생긴다. 즉, 이런식으로 말이다. 


인코딩 문제라는것은 알았는데, 대안 API(Alternative API)를 쓰라고만 나와서 약간 막막했는데, 

다음과 같이 수정하면 된다. 




#dev  #DM_DEFAULT_ENCODING  #encoding  #FindBugs  #Found reliance on default encoding  #정적분석툴