2626import java .util .Base64 ;
2727import java .util .List ;
2828import java .util .Set ;
29+ import java .util .logging .Logger ;
2930import java .util .stream .Collectors ;
3031import org .netbeans .api .project .Project ;
3132import org .openide .filesystems .FileObject ;
3738 */
3839public class ContextHelper {
3940
41+ final static Logger LOG = Logger .getLogger (ContextHelper .class .getName ());
42+
4043 public static String getProjectContext (
4144 final Set <FileObject > projectContext ,
4245 final Project project ,
@@ -113,10 +116,17 @@ public static String getTextFilesContext(
113116 inputForAI .append (relativePath )
114117 .append ("\n " );
115118 } else {
119+ LOG .finest (() -> "including file " + file + " in context" );
116120 try {
117121 final String mimeType = Files .probeContentType (Path .of (file .toURI ()));
118122
119- if (!mimeType .startsWith ("image" )) {
123+ //
124+ // mimeType can be null if probeContentType() is not able
125+ // to determine the mime type; it should not happen often though
126+ // as getFilesContextList() returnes files with a controlled
127+ // list of extensions (via configuration)
128+ //
129+ if (mimeType != null && !mimeType .startsWith ("image" )) {
120130 String text = getLatestContent (file );
121131 if (text != null ) {
122132 if ("java" .equals (file .getExt ()) && excludeJavadoc ) {
@@ -128,8 +138,11 @@ public static String getTextFilesContext(
128138 .append (text )
129139 .append ("\n \n " );
130140 }
141+ } else {
142+ LOG .finest (() -> file + " discarted due to mime type " + mimeType );
131143 }
132144 } catch (Exception ex ) {
145+ LOG .finest (() -> "ups, error " + ex + " in including files in context" );
133146 Exceptions .printStackTrace (ex );
134147 }
135148 }
0 commit comments