Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject piped input (/dev/stdin) for BedToIntervalList #1918

Merged
merged 3 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/picard/util/BedToIntervalList.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,13 @@ public class BedToIntervalList extends CommandLineProgram {
@Override
protected int doWork() {
IOUtil.assertFileIsReadable(INPUT);
if(INPUT.getPath().equals("/dev/stdin")) {
throw new IllegalArgumentException("BedToIntervalList does not support reading from standard input - a file must be provided.");
}

IOUtil.assertFileIsReadable(SEQUENCE_DICTIONARY);
IOUtil.assertFileIsWritable(OUTPUT);

try {
// create a new header that we will assign the dictionary provided by the SAMSequenceDictionaryExtractor to.
final SAMFileHeader header = new SAMFileHeader();
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/picard/util/BedToIntervalListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ public void testLengthZeroIntervalsSkipped(final String inputBed) throws IOExcep
doTest(inputBed, "header.sam", false);
}

@Test(expectedExceptions = IllegalArgumentException.class)
public void testRejectStdin() throws IOException {
final BedToIntervalList program = new BedToIntervalList();
final File outputFile = File.createTempFile("bed_to_interval_list_test.", ".interval_list");
outputFile.deleteOnExit();
program.OUTPUT = outputFile;
program.SEQUENCE_DICTIONARY = new File(TEST_DATA_DIR, "header.sam");
program.UNIQUE = true;
program.INPUT = new File("/dev/stdin");
program.doWork();
}

@DataProvider
public Object[][] testBedToIntervalListDataProvider() {
return new Object[][]{
Expand Down
Loading