#vulnerable code 
                              public static String getFilenameFromImage(BufferedImage img){
     if (! PreferencesUser.getInstance().getPrefMoreTextOCR()) {
       return "";
     }
		 TextRecognizer tr = TextRecognizer.getInstance();
		 String text = tr.recognize(img);
		 text = text.replaceAll("\\W","");
		 if( text.length() > MAX_OCR_TEXT_LENGTH ) {
       return text.substring(0, MAX_OCR_TEXT_LENGTH);
     }
		 return text;
   } 
                            #location 6 
                            #vulnerability type NULL_DEREFERENCE
#fixed code
                              public static String getFilenameFromImage(BufferedImage img){
		 TextRecognizer tr = TextRecognizer.getInstance();
     if (! PreferencesUser.getInstance().getPrefMoreTextOCR() || tr == null) {
       return "";
     }
		 String text = tr.recognize(img);
		 text = text.replaceAll("\\W","");
		 if( text.length() > MAX_OCR_TEXT_LENGTH ) {
       return text.substring(0, MAX_OCR_TEXT_LENGTH);
     }
		 return text;
   }