@ SuppressFBWarnings ( justification = "SourcePath should intentionally come from user file path" , value = "PATH_TRAVERSAL_IN" ) private List < Source > getSources ( int errorLine , String sourcePath ) throws IOException { Objects . requireNonNull ( sourcePath , Required . SOURCE_PATH . toString ( ) ) ; StringBuilder buffer = new StringBuilder ( ) ; buffer . append ( System . getProperty ( "user.dir" ) ) . append ( File . separator ) . append ( "src" ) . append ( File . separator ) . append ( "main" ) . append ( File . separator ) . append ( "java" ) ; List < Source > sources = new ArrayList <> ( ) ; Path templateFile = Paths . get ( buffer . toString ( ) ) . resolve ( sourcePath ) ; if ( Files . exists ( templateFile ) ) { List < String > lines = Files . readAllLines ( templateFile ) ; int index = 0 ; for ( String line : lines ) { if ( ( index + MAX_LINES > errorLine ) && ( index - MIN_LINES < errorLine ) ) { sources . add ( new Source ( ( index + 1 ) == errorLine , index + 1 , line ) ) ; } index ++ ; } } return sources ; }
Retrieves the lines of code where an exception occurred