Buggy code:
public class PostController { private static DateTimeFormatter FILENAME_TIME_FORMAT = DateTimeFormatter . ofPattern ( "uuuuMMddHHmmss" ) ; private static DateTimeFormatter EVENT_TIME_FORMAT = DateTimeFormatter . ofPattern ( "uuuu-MM-dd<seq2seq4repair_space>HH:mm" ) ; public static Response getAll ( IHTTPSession session , Map < String , String > args , Map < String , String > files , ViewContext context , Model model ) { } public static Response getSingle ( IHTTPSession session , Map < String , String > args , Map < String , String > files , ViewContext context , Model model ) { } public static Response getNew ( IHTTPSession session , Map < String , String > args , Map < String , String > files , ViewContext context , Model model ) { } public static Response postNew ( IHTTPSession session , Map < String , String > args , Map < String , String > files , ViewContext context , Model model ) { String datePattern = "[0-9]{4}-[0-9]{2}-[0-9]{2}<seq2seq4repair_space>[0-9]{2}:[0-9]{2}" ; Function < String , String > saniziteContent = ( s ) -> View . sanitizePostContent ( s . replace ( "&quot;" , "\"" ) . replace ( "&amp;" , "&" ) ) ; Validator validator = new Validator ( model . getSessionManager ( ) ) . validateSingle ( "validCsrfToken" , model . getSessionManager ( ) :: validateToken , "csrf_token" ) . validateSingle ( "hasTitle" , View :: sanitizeStrict , ( s ) -> ( s . length ( ) ) > 0 , "title" ) . validateSingle ( "hasContent" , saniziteContent , ( s ) -> ( s . length ( ) ) > 0 , "content" ) . validateSingle ( "hasContact" , View :: sanitizeStrict , ( s ) -> ( s . length ( ) ) > 0 , "contact" ) . validateMultiple ( "validDateIfEvent" , ( p ) -> ( ! ( p [ 0 ] . equals ( "on" ) ) ) || ( p [ 1 ] . matches ( datePattern ) ) , "is-event" , "date" ) . validateFlag ( "isEvent" , "is-event" ) ; context . setValidator ( validator ) ; if ( ! ( validator . validate ( session . getParms ( ) ) ) ) { return new Response ( View . make ( "post.new" , context ) ) ; } int i = 0 ; String image = "image" + i ; Map < String , String > params = session . getParms ( ) ; String uploadfolder = ( ( String ) ( config . get ( "litepost.public.uploadfolder" ) ) ) ; ArrayList < File > loadedImages = new ArrayList < > ( ) ; ArrayList < String > sources = new ArrayList < > ( ) ; while ( params . containsKey ( image ) ) { String filename = LocalDateTime . now ( ) . format ( PostController . FILENAME_TIME_FORMAT ) ; String imagename = params . get ( image ) ; <START_BUG> if ( imagename != null ) { <END_BUG> String extension = imagename . substring ( imagename . lastIndexOf ( '.' ) ) ; String outfilename = filename + extension ; File output = new File ( ( ( uploadfolder + ( File . separator ) ) + outfilename ) ) ; int filenum = 1 ; while ( output . exists ( ) ) { outfilename = ( ( filename + "-" ) + filenum ) + extension ; output = new File ( ( ( uploadfolder + ( File . separator ) ) + outfilename ) ) ; filenum ++ ; } File input = new File ( files . get ( image ) ) ; if ( input . exists ( ) ) { try { loadedImages . add ( output ) ; Files . copy ( input , output ) ; input . delete ( ) ; sources . add ( outfilename ) ; } catch ( IOException e ) { for ( File f : loadedImages ) { f . delete ( ) ; } return Router . error ( e , context ) ; } } } i ++ ; image = "image" + i ; } try { String title = validator . value ( "title" ) ; String content = validator . value ( "content" ) ; String contact = validator . value ( "contact" ) ; model . getPostManager ( ) . insert ( title , content , contact ) ; ResultSet rs = model . getQueryManager ( ) . executeQuery ( "getLastId" , "Posts" ) ; int postId = rs . getInt ( 1 ) ; for ( String s : sources ) { String src = Router . linkTo ( "upload" , s ) ; model . getPostManager ( ) . addImage ( src , postId ) ; } if ( validator . flag ( "is-event" ) ) { LocalDateTime date = LocalDateTime . from ( PostController . EVENT_TIME_FORMAT . parse ( validator . value ( "date" ) ) ) ; model . getPostManager ( ) . makeEvent ( postId , date ) ; } } catch ( SQLException e ) { return Router . error ( e , context ) ; } return Router . redirectTo ( "allPosts" ) ; } public static Response commentPost ( IHTTPSession session , Map < String , String > args , Map < String , String > files , ViewContext context , Model model ) { } }

Fix:
if ( ( imagename != null ) && ( ! ( imagename . isEmpty ( ) ) ) ) {