|
5 | 5 | import java.io.FileInputStream; |
6 | 6 | import java.io.FileReader; |
7 | 7 | import java.io.IOException; |
8 | | -import java.nio.charset.Charset; |
| 8 | +import java.nio.charset.CharacterCodingException; |
9 | 9 | import java.nio.charset.StandardCharsets; |
10 | 10 | import java.nio.file.Path; |
11 | 11 | import java.util.LinkedHashSet; |
|
17 | 17 | import com.semmle.js.extractor.trapcache.ITrapCache; |
18 | 18 | import com.semmle.util.data.StringUtil; |
19 | 19 | import com.semmle.util.exception.Exceptions; |
| 20 | +import com.semmle.util.exception.ResourceError; |
20 | 21 | import com.semmle.util.extraction.ExtractorOutputConfig; |
21 | 22 | import com.semmle.util.files.FileUtil; |
22 | 23 | import com.semmle.util.io.WholeIO; |
@@ -438,7 +439,16 @@ public Integer extract(File f, ExtractorState state) throws IOException { |
438 | 439 | } |
439 | 440 |
|
440 | 441 | // 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 | + } |
442 | 452 | outputConfig.getSourceArchive().add(f, source); |
443 | 453 |
|
444 | 454 | // extract language-independent bits |
|
0 commit comments