Skip to content

Commit fa0ce53

Browse files
committed
JS: Skip files with unsupported file encoding
1 parent e2b1f6a commit fa0ce53

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

javascript/extractor/src/com/semmle/js/extractor/FileExtractor.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import java.io.FileInputStream;
66
import java.io.FileReader;
77
import java.io.IOException;
8-
import java.nio.charset.Charset;
8+
import java.nio.charset.CharacterCodingException;
99
import java.nio.charset.StandardCharsets;
1010
import java.nio.file.Path;
1111
import java.util.LinkedHashSet;
@@ -17,6 +17,7 @@
1717
import com.semmle.js.extractor.trapcache.ITrapCache;
1818
import com.semmle.util.data.StringUtil;
1919
import com.semmle.util.exception.Exceptions;
20+
import com.semmle.util.exception.ResourceError;
2021
import com.semmle.util.extraction.ExtractorOutputConfig;
2122
import com.semmle.util.files.FileUtil;
2223
import com.semmle.util.io.WholeIO;
@@ -438,7 +439,16 @@ public Integer extract(File f, ExtractorState state) throws IOException {
438439
}
439440

440441
// populate source archive
441-
String source = new WholeIO(config.getDefaultEncoding()).strictread(f);
442+
WholeIO wholeIO = new WholeIO(config.getDefaultEncoding(), true);
443+
String source = wholeIO.read(f);
444+
if (source == null) {
445+
if (wholeIO.getLastException() instanceof CharacterCodingException) {
446+
System.err.println("Skipped due to unsupported character encoding: " + f);
447+
return 0;
448+
} else {
449+
throw new ResourceError("Failed to read file " + f, wholeIO.getLastException());
450+
}
451+
}
442452
outputConfig.getSourceArchive().add(f, source);
443453

444454
// extract language-independent bits

0 commit comments

Comments
 (0)