Source:
<code>public void badConstructionTest() throws IOException { String name = "log_non_existent"; File file = new File(tempDir, name); try { new LogSegment(name, file, STANDARD_SEGMENT_SIZE, metrics, true); fail("Construction should have failed because the backing file does not exist"); } catch (IllegalArgumentException e) { } try { new LogSegment(name, file, metrics); fail("Construction should have failed because the backing file does not exist"); } catch (IllegalArgumentException e) { } name = tempDir.getName(); file = new File(tempDir.getParent(), name); try { new LogSegment(name, file, STANDARD_SEGMENT_SIZE, metrics, true); fail("Construction should have failed because the backing file does not exist"); } catch (IllegalArgumentException e) { } name = tempDir.getName(); file = new File(tempDir.getParent(), name); try { new LogSegment(name, file, metrics); fail("Construction should have failed because the backing file does not exist"); } catch (IllegalArgumentException e) { } <START> LogSegment segment = getSegment("log_current", STANDARD_SEGMENT_SIZE, true); <END> file = segment.getView().getFirst(); byte[] header = getHeader(segment); byte savedByte = header[0]; header[0] = (byte) (header[0] + 10); writeHeader(segment, header); try { new LogSegment(name, file, metrics); fail("Construction should have failed because version is unknown"); } catch (IllegalArgumentException e) { } header[0] = savedByte; header[2] = header[2] == (byte) 1 ? (byte) 0 : (byte) 1; writeHeader(segment, header); try { new LogSegment(name, file, metrics); fail("Construction should have failed because crc check should have failed"); } catch (IllegalStateException e) { } closeSegmentAndDeleteFile(segment); }</code><technical_language>this is mis-leading. write headers a file named "log_current". change file name</technical_language>

Target:
public void badConstructionTest() throws IOException { String name = "log_non_existent"; File file = new File(tempDir, name); try { new LogSegment(name, file, STANDARD_SEGMENT_SIZE, metrics, true); fail("Construction should have failed because the backing file does not exist"); } catch (IllegalArgumentException e) { } try { new LogSegment(name, file, metrics); fail("Construction should have failed because the backing file does not exist"); } catch (IllegalArgumentException e) { } name = tempDir.getName(); file = new File(tempDir.getParent(), name); try { new LogSegment(name, file, STANDARD_SEGMENT_SIZE, metrics, true); fail("Construction should have failed because the backing file does not exist"); } catch (IllegalArgumentException e) { } name = tempDir.getName(); file = new File(tempDir.getParent(), name); try { new LogSegment(name, file, metrics); fail("Construction should have failed because the backing file does not exist"); } catch (IllegalArgumentException e) { } LogSegment segment = getSegment("dummy_log", STANDARD_SEGMENT_SIZE, true); file = segment.getView().getFirst(); byte[] header = getHeader(segment); byte savedByte = header[0]; header[0] = (byte) (header[0] + 10); writeHeader(segment, header); try { new LogSegment(name, file, metrics); fail("Construction should have failed because version is unknown"); } catch (IllegalArgumentException e) { } header[0] = savedByte; header[2] = header[2] == (byte) 1 ? (byte) 0 : (byte) 1; writeHeader(segment, header); try { new LogSegment(name, file, metrics); fail("Construction should have failed because crc check should have failed"); } catch (IllegalStateException e) { } closeSegmentAndDeleteFile(segment); }