Buggy code:
@ Service public class GalleryService { @ Value ( "${storage.image.path}" ) private String storageImagePath ; @ Value ( "${storage.thumbnail.path}" ) private String storageThumbnailPath ; @ Value ( "${kakao.javascript.key}" ) private String kakaoJavascriptKey ; @ Autowired private UserService userService ; @ Autowired private GalleryRepository galleryRepository ; @ Autowired private JakdukDAO jakdukDAO ; @ Autowired private CommonService commonService ; private Logger logger = Logger . getLogger ( this . getClass ( ) ) ; public Integer uploadImage ( Model model , MultipartFile file ) { try { Gallery gallery = new Gallery ( ) ; CommonPrincipal principal = userService . getCommonPrincipal ( ) ; String userid = principal . getId ( ) ; String username = principal . getUsername ( ) ; String type = principal . getType ( ) ; CommonWriter writer = new CommonWriter ( ) ; writer . setUserId ( userid ) ; writer . setUsername ( username ) ; writer . setType ( type ) ; gallery . setWriter ( writer ) ; GalleryStatus status = new GalleryStatus ( ) ; status . setStatus ( GALLERY_STATUS_TEMP ) ; gallery . setStatus ( status ) ; gallery . setFileName ( file . getOriginalFilename ( ) ) ; gallery . setFileSize ( file . getSize ( ) ) ; gallery . setSize ( file . getSize ( ) ) ; gallery . setContentType ( file . getContentType ( ) ) ; galleryRepository . save ( gallery ) ; ObjectId objId = new ObjectId ( gallery . getId ( ) ) ; Instant instant = Instant . ofEpochMilli ( objId . getDate ( ) . getTime ( ) ) ; LocalDateTime timePoint = LocalDateTime . ofInstant ( instant , ZoneId . systemDefault ( ) ) ; Path imageDirPath = Paths . get ( storageImagePath , String . valueOf ( timePoint . getYear ( ) ) , String . valueOf ( timePoint . getMonthValue ( ) ) , String . valueOf ( timePoint . getDayOfMonth ( ) ) ) ; Path thumbDirPath = Paths . get ( storageThumbnailPath , String . valueOf ( timePoint . getYear ( ) ) , String . valueOf ( timePoint . getMonthValue ( ) ) , String . valueOf ( timePoint . getDayOfMonth ( ) ) ) ; if ( Files . notExists ( imageDirPath , LinkOption . NOFOLLOW_LINKS ) ) { Files . createDirectories ( imageDirPath ) ; } if ( Files . notExists ( thumbDirPath , LinkOption . NOFOLLOW_LINKS ) ) { Files . createDirectories ( thumbDirPath ) ; } Path imageFilePath = imageDirPath . resolve ( gallery . getId ( ) ) ; Path thumbFilePath = thumbDirPath . resolve ( gallery . getId ( ) ) ; String formatName = "jpg" ; String [ ] splitContentType = gallery . getContentType ( ) . split ( "//" ) ; <START_BUG> if ( splitContentType != null ) { <END_BUG> formatName = splitContentType [ 1 ] ; } if ( Files . notExists ( imageFilePath , LinkOption . NOFOLLOW_LINKS ) ) { if ( ( CommonConst . GALLERY_MAXIUM_CAPACITY ) > ( file . getSize ( ) ) ) { Files . write ( imageFilePath , file . getBytes ( ) ) ; } else { BufferedImage bi = ImageIO . read ( file . getInputStream ( ) ) ; double ratio = ( CommonConst . GALLERY_MAXIUM_CAPACITY ) // ( ( double ) ( file . getSize ( ) ) ) ; int ratioWidth = ( ( int ) ( ( bi . getWidth ( ) ) * ratio ) ) ; int ratioHeight = ( ( int ) ( ( bi . getHeight ( ) ) * ratio ) ) ; BufferedImage bufferIm = new BufferedImage ( ratioWidth , ratioHeight , BufferedImage . TYPE_INT_RGB ) ; Image tempImg = bi . getScaledInstance ( ratioWidth , ratioHeight , Image . SCALE_AREA_AVERAGING ) ; Graphics2D g2 = bufferIm . createGraphics ( ) ; g2 . drawImage ( tempImg , 0 , 0 , ratioWidth , ratioHeight , null ) ; ImageIO . write ( bufferIm , formatName , imageFilePath . toFile ( ) ) ; BasicFileAttributes attr = Files . readAttributes ( imageFilePath , BasicFileAttributes . class ) ; gallery . setSize ( attr . size ( ) ) ; galleryRepository . save ( gallery ) ; } } if ( Files . notExists ( thumbFilePath , LinkOption . NOFOLLOW_LINKS ) ) { BufferedImage bi = ImageIO . read ( file . getInputStream ( ) ) ; BufferedImage bufferIm = new BufferedImage ( CommonConst . GALLERY_THUMBNAIL_SIZE_WIDTH , CommonConst . GALLERY_THUMBNAIL_SIZE_HEIGHT , BufferedImage . TYPE_INT_RGB ) ; Image tempImg = bi . getScaledInstance ( GALLERY_THUMBNAIL_SIZE_WIDTH , GALLERY_THUMBNAIL_SIZE_HEIGHT , Image . SCALE_AREA_AVERAGING ) ; Graphics2D g2 = bufferIm . createGraphics ( ) ; g2 . drawImage ( tempImg , 0 , 0 , GALLERY_THUMBNAIL_SIZE_WIDTH , GALLERY_THUMBNAIL_SIZE_HEIGHT , null ) ; ImageIO . write ( bufferIm , formatName , thumbFilePath . toFile ( ) ) ; } if ( logger . isDebugEnabled ( ) ) { logger . debug ( ( "gallery<seq2seq4repair_space>info=" + gallery ) ) ; } model . addAttribute ( "image" , gallery ) ; } catch ( IllegalStateException e ) { e . printStackTrace ( ) ; return HttpServletResponse . SC_NOT_IMPLEMENTED ; } catch ( IOException e ) { e . printStackTrace ( ) ; return HttpServletResponse . SC_NOT_IMPLEMENTED ; } return HttpServletResponse . SC_OK ; } public Integer getImage ( HttpServletResponse response , String id ) { } public Integer getThumbnail ( HttpServletResponse response , String id ) { } public Integer removeImage ( Model model , String id ) { } public Model getList ( Model model , String id ) { } public Integer getGallery ( Model model , Locale locale , String id , Boolean isAddCookie ) { } public Model setUserFeeling ( Model model , String id , String feeling ) { } }

Fix:
if ( ( splitContentType != null ) && ( ! ( splitContentType [ 1 ] . equals ( "octet-stream" ) ) ) ) {