input
stringlengths
205
73.3k
output
stringlengths
64
73.2k
instruction
stringclasses
1 value
#vulnerable code @Test public void testAppender() throws Exception { final Logger logger = ctx.getLogger(); logger.debug("This is test message number 1"); Thread.sleep(1500); // Trigger the rollover for (int i = 0; i < 16; ++i) { l...
#fixed code @Test public void testAppender() throws Exception { final Logger logger = ctx.getLogger(); logger.debug("This is test message number 1"); Thread.sleep(1500); // Trigger the rollover for (int i = 0; i < 16; ++i) { logger....
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private static void setupQueue() throws Exception { // MockContextFactory becomes the primary JNDI provider final StatusConsoleListener l = new StatusConsoleListener(Level.ERROR); StatusLogger.getLogger().registerListener(l); MockContextF...
#fixed code private static void setupQueue() throws Exception { // MockContextFactory becomes the primary JNDI provider final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR); StatusLogger.getLogger().registerListener(listener); Mock...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(final String[] args) throws Exception { if (args.length != 4) { usage("Wrong number of arguments."); } final String qcfBindingName = args[0]; final String queueBindingName = args[1]; final Stri...
#fixed code public static void main(final String[] args) throws Exception { final JmsQueueReceiver receiver = new JmsQueueReceiver(); receiver.doMain(args); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static Charset getSupportedCharset(final String charsetName) { Charset charset = null; if (charsetName != null) { if (Charset.isSupported(charsetName)) { charset = Charset.forName(charsetName); } } ...
#fixed code public static Charset getSupportedCharset(final String charsetName) { Charset charset = null; if (charsetName != null) { if (Charset.isSupported(charsetName)) { charset = Charset.forName(charsetName); } } ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @GenerateMicroBenchmark public String test03_getCallerClassNameReflectively() { return ReflectiveCallerClassUtility.getCaller(3).getName(); } #location 3 #vulnerability type NULL_DEREFERENCE
#fixed code @GenerateMicroBenchmark public String test03_getCallerClassNameReflectively() { return ReflectionUtil.getCallerClass(3).getName(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testFlush() throws IOException { final OutputStream out = EasyMock.createMock("out", OutputStream.class); out.flush(); // expect the flush to come through to the mocked OutputStream out.close(); replay(out); ...
#fixed code @Test public void testFlush() throws IOException { final OutputStream out = EasyMock.createMock("out", OutputStream.class); out.flush(); // expect the flush to come through to the mocked OutputStream out.close(); replay(out); try (...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testAppender() throws Exception { for (int i=0; i < 100; ++i) { logger.debug("This is test message number " + i); } final File dir = new File(DIR); assertTrue("Directory not created", dir.exists() && dir....
#fixed code @Test public void testAppender() throws Exception { for (int i=0; i < 100; ++i) { logger.debug("This is test message number " + i); } final File dir = new File(DIR); assertThat(dir, both(exists()).and(hasFiles())); final...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testReconnect() throws Exception { TestSocketServer testServer = null; ExecutorService executor = null; Future<InputStream> futureIn; final InputStream in; try { executor = Executors.newSingleThr...
#fixed code @Test public void testReconnect() throws Exception { List<String> list = new ArrayList<String>(); TestSocketServer server = new TestSocketServer(list); server.start(); Thread.sleep(300); //System.err.println("Initializing logger")...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void forceRemap(final int linesPerIteration, final int iterations, final IPerfTestRunner runner) { final int LINESEP = System.getProperty("line.separator").getBytes(Charset.defaultCharset()).length; final int bytesPerLine = 0 + IPerfTestRunner.TH...
#fixed code private void forceRemap(final int linesPerIteration, final int iterations, final IPerfTestRunner runner) { final int LINESEP = System.lineSeparator().getBytes(Charset.defaultCharset()).length; final int bytesPerLine = 0 + IPerfTestRunner.THROUGHPUT_MSG.getByte...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void getStream() { final LoggerStream stream = logger.getStream(Level.DEBUG); stream.println("Debug message 1"); stream.print("Debug message 2"); stream.println(); stream.println(); // verify blank log message ...
#fixed code @Test public void getStream() { final PrintWriter stream = logger.printWriter(Level.DEBUG); stream.println("println"); stream.print("print followed by println"); stream.println(); stream.println("multiple\nlines"); stream.pr...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testSubset() throws Exception { Properties props = new Properties(); props.load(new FileInputStream("target/test-classes/log4j2-properties.properties")); Properties subset = PropertiesUtil.extractSubset(props, "appender.Stdo...
#fixed code @Test public void testSubset() throws Exception { Properties props = new Properties(); props.load(ClassLoader.getSystemResourceAsStream("log4j2-properties.properties")); Properties subset = PropertiesUtil.extractSubset(props, "appender.Stdout.filte...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void format(final LogEvent event, final StringBuilder toAppendTo) { final long timestamp = event.getTimeMillis(); synchronized (this) { if (timestamp != lastTimestamp) { lastTimestamp = timestamp; ...
#fixed code @Override public void format(final LogEvent event, final StringBuilder toAppendTo) { final long timestamp = event.getTimeMillis(); toAppendTo.append(timestamp - startTime); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private static void setupQueue() throws Exception { // MockContextFactory becomes the primary JNDI provider final StatusConsoleListener l = new StatusConsoleListener(Level.ERROR); StatusLogger.getLogger().registerListener(l); MockContextF...
#fixed code private static void setupQueue() throws Exception { // MockContextFactory becomes the primary JNDI provider final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR); StatusLogger.getLogger().registerListener(listener); Mock...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testWrite_dataExceedingBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); final RandomAccessFile raf = new RandomAccessFile(file, "rw"); final OutputStream...
#fixed code @Test public void testWrite_dataExceedingBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final OutputS...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testWrite_multiplesOfBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); final RandomAccessFile raf = new RandomAccessFile(file, "rw"); final OutputStream o...
#fixed code @Test public void testWrite_multiplesOfBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final OutputStr...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testWrite_dataExceedingMinBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); final RandomAccessFile raf = new RandomAccessFile(file, "rw"); final OutputStr...
#fixed code @Test public void testWrite_dataExceedingMinBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final Outp...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public T build() { verify(); // first try to use a builder class if one is available try { LOGGER.debug("Building Plugin[name={}, class={}]. Searching for builder factory method...", pluginType.getElementName(), ...
#fixed code @Override public T build() { verify(); // first try to use a builder class if one is available try { LOGGER.debug("Building Plugin[name={}, class={}]. Searching for builder factory method...", pluginType.getElementName(), ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testAppender() throws Exception { for (int i=0; i < 100; ++i) { logger.debug("This is test message number " + i); } Thread.sleep(50); final File dir = new File(DIR); assertTrue("Directory not crea...
#fixed code @Test public void testAppender() throws Exception { for (int i=0; i < 100; ++i) { logger.debug("This is test message number " + i); } Thread.sleep(50); final File dir = new File(DIR); assertThat(dir, both(exists()).and(h...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private static void copyFile(final File source, final File destination) throws IOException { if (!destination.exists()) { destination.createNewFile(); } FileChannel srcChannel = null; FileChannel destChannel = null; F...
#fixed code private static void copyFile(final File source, final File destination) throws IOException { if (!destination.exists()) { destination.createNewFile(); } Files.copy(source.toPath(), destination.toPath()); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override protected void releaseSub() { if (transceiver != null) { try { transceiver.close(); } catch (final IOException ioe) { LOGGER.error("Attempt to clean up Avro transceiver failed", ioe); ...
#fixed code @Override protected void releaseSub() { if (rpcClient != null) { try { rpcClient.close(); } catch (final Exception ex) { LOGGER.error("Attempt to close RPC client failed", ex); } } ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testJmsQueueAppenderCompatibility() throws Exception { assertEquals(0, queue.size()); final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsQueueAppender"); final LogEvent expected = createLogEvent(); ...
#fixed code @Test public void testJmsQueueAppenderCompatibility() throws Exception { final JmsAppender appender = (JmsAppender) ctx.getRequiredAppender("JmsQueueAppender"); final LogEvent expected = createLogEvent(); appender.append(expected); then(ses...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static Object deserializeStream(final String witness) throws Exception { final FileInputStream fileIs = new FileInputStream(witness); final ObjectInputStream objIs = new ObjectInputStream(fileIs); return objIs.readObject(); } ...
#fixed code public static Object deserializeStream(final String witness) throws Exception { final FileInputStream fileIs = new FileInputStream(witness); final ObjectInputStream objIs = new ObjectInputStream(fileIs); try { return objIs.readObject(); ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(final String[] args) throws Exception { if (args.length < 1 || args.length > 2) { System.err.println("Incorrect number of arguments: " + args.length); printUsage(); return; } final int p...
#fixed code public static void main(final String[] args) throws Exception { final CommandLineArguments cla = parseCommandLine(args, TcpSocketServer.class, new CommandLineArguments()); if (cla.isHelp()) { return; } if (cla.getConfigLocation() !=...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void checkConfiguration() { final long current; if (((counter.incrementAndGet() & MASK) == 0) && ((current = System.currentTimeMillis()) >= nextCheck)) { LOCK.lock(); try { nextCheck = current ...
#fixed code @Override public void checkConfiguration() { final long current; if (((counter.incrementAndGet() & MASK) == 0) && ((current = System.nanoTime()) - nextCheck >= 0)) { LOCK.lock(); try { nextCheck = current + intervalN...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static boolean execute(final File source, final File destination, final boolean deleteSource) throws IOException { if (source.exists()) { final FileInputStream fis = new FileInputStream(source); final FileOutputStream fos =...
#fixed code public static boolean execute(final File source, final File destination, final boolean deleteSource) throws IOException { if (source.exists()) { try (final FileInputStream fis = new FileInputStream(source); final BufferedOut...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void verifyFile(final int count) throws Exception { // String expected = "[\\w]* \\[\\s*\\] INFO TestLogger - Test$"; final String expected = "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3} \\[[^\\]]*\\] INFO TestLogger - Test"; final ...
#fixed code private void verifyFile(final int count) throws Exception { // String expected = "[\\w]* \\[\\s*\\] INFO TestLogger - Test$"; final String expected = "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3} \\[[^\\]]*\\] INFO TestLogger - Test"; final Patter...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testMemMapBasics() throws Exception { final File f = new File(LOGFILE); if (f.exists()) { assertTrue(f.delete()); } assertTrue(!f.exists()); final Logger log = LogManager.getLogger(); ...
#fixed code @Test public void testMemMapBasics() throws Exception { final File f = new File(LOGFILE); if (f.exists()) { assertTrue(f.delete()); } assertTrue(!f.exists()); final Logger log = LogManager.getLogger(); t...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(final String[] args) throws Exception { if (args.length < 1 || args.length > 2) { System.err.println("Incorrect number of arguments: " + args.length); printUsage(); return; } final int p...
#fixed code public static void main(final String[] args) throws Exception { final CommandLineArguments cla = parseCommandLine(args, UdpSocketServer.class, new CommandLineArguments()); if (cla.isHelp()) { return; } if (cla.getConfigLocation() !=...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(String[] args) throws Exception { System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName()); Logger logger = LogManager.getLogger(); if (!(logger instanceof AsyncLogger)) { throw n...
#fixed code public static void main(String[] args) throws Exception { System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName()); Logger logger = LogManager.getLogger(); if (!(logger instanceof AsyncLogger)) { throw new Ill...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void getStream_Marker() { final LoggerStream stream = logger.getStream(MarkerManager.getMarker("HI"), Level.INFO); stream.println("Hello, world!"); stream.print("How about this?\n"); stream.println("Is this thing on?"); ...
#fixed code @Test public void getStream_Marker() { final PrintWriter stream = logger.printWriter(MarkerManager.getMarker("HI"), Level.INFO); stream.println("println"); stream.print("print with embedded newline\n"); stream.println("last line"); ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testFlush() throws IOException { final OutputStream out = EasyMock.createMock("out", OutputStream.class); out.flush(); // expect the flush to come through to the mocked OutputStream out.close(); replay(out); ...
#fixed code @Test public void testFlush() throws IOException { final OutputStream out = EasyMock.createMock("out", OutputStream.class); out.flush(); // expect the flush to come through to the mocked OutputStream out.close(); replay(out); ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public String toSerializable(final LogEvent event) { final StringBuilder buffer = prepareStringBuilder(strBuilder); try { // Revisit when 1.3 is out so that we do not need to create a new // printer for each event. ...
#fixed code @Override public String toSerializable(final LogEvent event) { final StringBuilder buffer = getStringBuilder(); // Revisit when 1.3 is out so that we do not need to create a new // printer for each event. // No need to close the printer. ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public String toString() { return "JeroMqAppender [context=" + context + ", publisher=" + publisher + ", endpoints=" + endpoints + "]"; } #location 3 #vulnerability type THREAD_SAFETY_VI...
#fixed code @Override public String toString() { return "JeroMqAppender{" + "name=" + getName() + ", state=" + getState() + ", manager=" + manager + ", endpoints=" + endpoints + '}'; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void stop() { LOGGER.debug("Stopping LoggerContext[name={}, {}]...", getName(), this); configLock.lock(); try { if (this.isStopped()) { return; } this.setStopping(); ...
#fixed code @Override public void stop() { stop(0, null); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(final String[] args) throws Exception { if (args.length != 4) { usage("Wrong number of arguments."); } final String tcfBindingName = args[0]; final String topicBindingName = args[1]; final Stri...
#fixed code public static void main(final String[] args) throws Exception { final JmsTopicReceiver receiver = new JmsTopicReceiver(); receiver.doMain(args); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private static void encode(final ConcurrentMap<String, ConcurrentMap<String, PluginType<?>>> map) { final String fileName = rootDir + PATH + FILENAME; DataOutputStream dos = null; try { final File file = new File(rootDir + PATH); ...
#fixed code private static void encode(final ConcurrentMap<String, ConcurrentMap<String, PluginType<?>>> map) { final String fileName = rootDir + PATH + FILENAME; DataOutputStream dos = null; try { final File file = new File(rootDir + PATH); ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test(expected = IOException.class) public void connectionFailsWithoutValidServerCertificate() throws SslConfigurationException, IOException { TrustStoreConfiguration tsc = new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, null); SslConfigur...
#fixed code @Test(expected = IOException.class) public void connectionFailsWithoutValidServerCertificate() throws IOException, StoreConfigurationException { TrustStoreConfiguration tsc = new TrustStoreConfiguration(TestConstants.TRUSTSTORE_FILE, null, null, null); Ssl...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private static EnumMap<Level, String> createLevelStyleMap(final String[] options) { Map<String, String> styles = options.length < 2 ? null : AnsiEscape.createMap(options[1]); EnumMap<Level, String> levelStyles = new EnumMap<Level, String>(LEVEL_STYLES_DE...
#fixed code private static EnumMap<Level, String> createLevelStyleMap(final String[] options) { if (options.length < 2) { return DEFAULT_STYLES; } Map<String, String> styles = AnsiEscape.createMap(options[1]); EnumMap<Level, String> levelStyles...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void addScript(Script script) { ScriptEngine engine = manager.getEngineByName(script.getLanguage()); if (engine == null) { logger.error("No ScriptEngine found for language " + script.getLanguage()); } if (engine.getFact...
#fixed code public void addScript(Script script) { ScriptEngine engine = manager.getEngineByName(script.getLanguage()); if (engine == null) { logger.error("No ScriptEngine found for language " + script.getLanguage() + ". Available languages are: " + ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @SuppressWarnings("unchecked") protected void doConfigure() { boolean setRoot = false; boolean setLoggers = false; for (final Node child : rootNode.getChildren()) { createConfiguration(child, null); if (child.getObject...
#fixed code @SuppressWarnings("unchecked") protected void doConfigure() { boolean setRoot = false; boolean setLoggers = false; for (final Node child : rootNode.getChildren()) { createConfiguration(child, null); if (child.getObject() == ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testReconnect() throws Exception { TestSocketServer testServer = null; ExecutorService executor = null; Future<InputStream> futureIn; final InputStream in; try { executor = Executors.newSingleThr...
#fixed code @Test public void testReconnect() throws Exception { List<String> list = new ArrayList<String>(); TestSocketServer server = new TestSocketServer(list); server.start(); Thread.sleep(300); //System.err.println("Initializing logger")...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testWrite_dataExceedingMinBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); final RandomAccessFile raf = new RandomAccessFile(file, "rw"); final OutputStr...
#fixed code @Test public void testWrite_dataExceedingMinBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final Outp...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(String[] args) throws Exception { System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName()); System.setProperty("log4j.configurationFile", "perf3PlainNoLoc.xml"); Logger logger = LogManager.ge...
#fixed code public static void main(String[] args) throws Exception { if (args.length < 2) { System.out.println("Please specify thread count and interval (us)"); return; } // double targetLoadLevel = Double.parseDouble(args[0]); fina...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void releaseSub() { try { if (info != null) { info.session.close(); info.conn.close(); } } catch (final JMSException ex) { LOGGER.error("Error closing " + getName(),...
#fixed code @Override public void releaseSub() { if (info != null) { cleanup(false); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @BeforeClass public static void setupClass() throws Exception { // MockContextFactory becomes the primary JNDI provider final StatusConsoleListener l = new StatusConsoleListener(Level.ERROR); StatusLogger.getLogger().registerListener(l); ...
#fixed code @BeforeClass public static void setupClass() throws Exception { // MockContextFactory becomes the primary JNDI provider final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR); StatusLogger.getLogger().registerListener(listene...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testAppender() throws Exception { for (int i=0; i < 100; ++i) { logger.debug("This is test message number " + i); } final File dir = new File(DIR); assertTrue("Directory not created", dir.exists() && dir....
#fixed code @Test public void testAppender() throws Exception { for (int i=0; i < 100; ++i) { logger.debug("This is test message number " + i); } final File dir = new File(DIR); assertThat(dir, both(exists()).and(hasFiles())); final...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testAsyncLogUsesNanoTimeClock() throws Exception { final File file = new File("target", "NanoTimeToFileTest.log"); // System.out.println(f.getAbsolutePath()); file.delete(); final AsyncLogger log = (AsyncLogger) LogM...
#fixed code @Test public void testAsyncLogUsesNanoTimeClock() throws Exception { final File file = new File("target", "NanoTimeToFileTest.log"); // System.out.println(f.getAbsolutePath()); file.delete(); final AsyncLogger log = (AsyncLogger) LogManager...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @BeforeClass public static void setupClass() throws Exception { // MockContextFactory becomes the primary JNDI provider final StatusConsoleListener l = new StatusConsoleListener(Level.ERROR); StatusLogger.getLogger().registerListener(l); ...
#fixed code @BeforeClass public static void setupClass() throws Exception { // MockContextFactory becomes the primary JNDI provider final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR); StatusLogger.getLogger().registerListener(listene...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testWrite_multiplesOfBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); final RandomAccessFile raf = new RandomAccessFile(file, "rw"); final OutputStream o...
#fixed code @Test public void testWrite_multiplesOfBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final OutputStr...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testAppender() throws Exception { for (int i = 0; i < 8; ++i) { logger.debug("This is test message number " + i); } Thread.sleep(50); final File dir = new File(DIR); assertTrue("Directory not crea...
#fixed code @Test public void testAppender() throws Exception { for (int i = 0; i < 8; ++i) { logger.debug("This is test message number " + i); } Thread.sleep(50); final File dir = new File(DIR); assertThat(dir, both(exists()).and(h...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testEnvironment() throws Exception { ctx = Configurator.initialize("-config", null); LogManager.getLogger("org.apache.test.TestConfigurator"); final Configuration config = ctx.getConfiguration(); assertNotNull("No co...
#fixed code @Test public void testEnvironment() throws Exception { ctx = Configurator.initialize("-config", null); LogManager.getLogger("org.apache.test.TestConfigurator"); final Configuration config = ctx.getConfiguration(); assertNotNull("No configur...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testNoArgBuilderCallerClassInfo() throws Exception { final PrintStream ps = IoBuilder.forLogger().buildPrintStream(); ps.println("discarded"); final ListAppender app = context.getListAppender("IoBuilderTest"); final ...
#fixed code @Test public void testNoArgBuilderCallerClassInfo() throws Exception { try (final PrintStream ps = IoBuilder.forLogger().buildPrintStream()) { ps.println("discarded"); final ListAppender app = context.getListAppender("IoBuilderTest"); ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testThresholds() { RegexFilter filter = RegexFilter.createFilter(Pattern.compile(".* test .*"), false, null, null); filter.start(); assertTrue(filter.isStarted()); assertSame(Filter.Result.NEUTRAL, filter...
#fixed code @Test public void testThresholds() throws Exception { RegexFilter filter = RegexFilter.createFilter(".* test .*", null, false, null, null); filter.start(); assertTrue(filter.isStarted()); assertSame(Filter.Result.NEUTRAL, fi...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public String toSerializable(final LogEvent event) { final Message message = event.getMessage(); final Object[] parameters = message.getParameters(); final StringBuilder buffer = prepareStringBuilder(strBuilder); try { ...
#fixed code @Override public String toSerializable(final LogEvent event) { final Message message = event.getMessage(); final Object[] parameters = message.getParameters(); final StringBuilder buffer = getStringBuilder(); // Revisit when 1.3 is out so t...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected ConfigurationSource getInputFromString(final String config, final ClassLoader loader) { try { final URL url = new URL(config); return new ConfigurationSource(url.openStream(), FileUtils.fileFromURI(url.toURI())); } catch...
#fixed code protected ConfigurationSource getInputFromString(final String config, final ClassLoader loader) { try { final URL url = new URL(config); return new ConfigurationSource(url.openStream(), FileUtils.fileFromUri(url.toURI())); } catch (fina...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testConfigurableBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); final RandomAccessFile raf = new RandomAccessFile(file, "rw"); final OutputStream os = N...
#fixed code @Test public void testConfigurableBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final OutputStream o...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @BeforeClass public static void setupClass() throws Exception { // MockContextFactory becomes the primary JNDI provider final StatusConsoleListener l = new StatusConsoleListener(Level.ERROR); StatusLogger.getLogger().registerListener(l); ...
#fixed code @BeforeClass public static void setupClass() throws Exception { // MockContextFactory becomes the primary JNDI provider final StatusConsoleListener listener = new StatusConsoleListener(Level.ERROR); StatusLogger.getLogger().registerListener(listene...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testFlush() throws IOException { final OutputStream out = EasyMock.createMock(OutputStream.class); out.flush(); // expect the flush to come through to the mocked OutputStream out.close(); replay(out); final ...
#fixed code @Test public void testFlush() throws IOException { final OutputStream out = EasyMock.createMock(OutputStream.class); out.flush(); // expect the flush to come through to the mocked OutputStream out.close(); replay(out); try (final O...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testAppender() throws Exception { for (int i=0; i < 100; ++i) { logger.debug("This is test message number " + i); } final File dir = new File(DIR); assertTrue("Directory not created", dir.exists() && dir....
#fixed code @Test public void testAppender() throws Exception { for (int i=0; i < 100; ++i) { logger.debug("This is test message number " + i); } final File dir = new File(DIR); assertThat(dir, both(exists()).and(hasFiles())); final...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private static void encode(final ConcurrentMap<String, ConcurrentMap<String, PluginType>> map) { final String fileName = rootDir + PATH + FILENAME; try { final File file = new File(rootDir + PATH); file.mkdirs(); final...
#fixed code private static void encode(final ConcurrentMap<String, ConcurrentMap<String, PluginType>> map) { final String fileName = rootDir + PATH + FILENAME; DataOutputStream dos = null; try { final File file = new File(rootDir + PATH); f...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private String readContents(final URI uri, final Charset charset) throws IOException { InputStream in = null; try { in = uri.toURL().openStream(); final Reader reader = new InputStreamReader(in, charset); final StringB...
#fixed code private String readContents(final URI uri, final Charset charset) throws IOException { if (charset == null) { throw new IllegalArgumentException("charset must not be null"); } Reader reader = null; try { InputStream in =...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected boolean isFiltered(LogEvent event) { if (hasFilters) { for (Filter filter : filters) { if (filter.filter(event) == Filter.Result.DENY) { return true; } } } retu...
#fixed code protected boolean isFiltered(LogEvent event) { Filters f = filters; if (f.hasFilters()) { for (Filter filter : f) { if (filter.filter(event) == Filter.Result.DENY) { return true; } } ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testTcpAppenderDeadlock() throws Exception { // @formatter:off final SocketAppender appender = SocketAppender.newBuilder() .withHost("localhost") .withPort(DYN_PORT) .withReconnectDel...
#fixed code @Test public void testTcpAppenderDeadlock() throws Exception { // @formatter:off final SocketAppender appender = SocketAppender.newBuilder() .withHost("localhost") .withPort(DYN_PORT) .withReconnectDelayMill...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testAppender() throws Exception { final Logger logger = ctx.getLogger(); // Trigger the rollover for (int i = 0; i < 10; ++i) { // 30 chars per message: each message triggers a rollover logger.debug("...
#fixed code @Test public void testAppender() throws Exception { final Logger logger = ctx.getLogger(); // Trigger the rollover for (int i = 0; i < 10; ++i) { // 30 chars per message: each message triggers a rollover logger.debug("This i...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void log(final LogEvent event) { counter.incrementAndGet(); try { if (isFiltered(event)) { return; } event.setIncludeLocation(isIncludeLocation()); callAppenders(event); ...
#fixed code public void log(final LogEvent event) { beforeLogEvent(); try { if (!isFiltered(event)) { processLogEvent(event); } } finally { afterLogEvent(); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void format(final LogEvent event, final StringBuilder output) { final long timestamp = event.getMillis(); synchronized (this) { if (timestamp != lastTimestamp) { lastTimestamp = timestamp; ...
#fixed code @Override public void format(final LogEvent event, final StringBuilder output) { final long timestamp = event.getMillis(); synchronized (this) { if (timestamp != lastTimestamp) { lastTimestamp = timestamp; cache...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected ConfigurationSource getInputFromResource(final String resource, final ClassLoader loader) { final URL url = Loader.getResource(resource, loader); if (url == null) { return null; } InputStream is = null; try {...
#fixed code protected ConfigurationSource getInputFromResource(final String resource, final ClassLoader loader) { final URL url = Loader.getResource(resource, loader); if (url == null) { return null; } InputStream is = null; try { ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public String toSerializable(final LogEvent event) { final StringBuilder buffer = prepareStringBuilder(strBuilder); try { // Revisit when 1.3 is out so that we do not need to create a new // printer for each event. ...
#fixed code @Override public String toSerializable(final LogEvent event) { final StringBuilder buffer = getStringBuilder(); // Revisit when 1.3 is out so that we do not need to create a new // printer for each event. // No need to close the printer. ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testFlush() throws IOException { final OutputStream out = EasyMock.createMock(OutputStream.class); out.flush(); // expect the flush to come through to the mocked OutputStream out.close(); replay(out); final ...
#fixed code @Test public void testFlush() throws IOException { final OutputStream out = EasyMock.createMock(OutputStream.class); out.flush(); // expect the flush to come through to the mocked OutputStream out.close(); replay(out); try (final O...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testWrite_dataExceedingBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); final RandomAccessFile raf = new RandomAccessFile(file, "rw"); final OutputStream...
#fixed code @Test public void testWrite_dataExceedingBufferSize() throws IOException { final File file = File.createTempFile("log4j2", "test"); file.deleteOnExit(); try (final RandomAccessFile raf = new RandomAccessFile(file, "rw")) { final OutputS...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void executeProxyRequest( HttpMethod httpMethodProxyRequest, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException { if (doLog) { log("proxy: "+httpServletRequest.get...
#fixed code private void executeProxyRequest( HttpMethod httpMethodProxyRequest, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException { if (doLog) { log("proxy: "+httpServletRequest.getReques...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); String doLogStr = servletConfig.getInitParameter(P_LOG); if (doLogStr != null) { this.doLog = Boolean.parseBoolean(doLogStr); } S...
#fixed code @Override public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); String doLogStr = servletConfig.getInitParameter(P_LOG); if (doLogStr != null) { this.doLog = Boolean.parseBoolean(doLogStr); } String ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public String toString() { return toStringHelper().toString(); } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code @Override public String toString() { return MoreObjects.toStringHelper(this) .add("requestMetadata", requestMetadata) .add("temporaryAccess", temporaryAccess).toString(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public AccessToken refreshAccessToken() throws IOException { Socket socket = new Socket("localhost", this.getAuthPort()); socket.setSoTimeout(READ_TIMEOUT_MS); AccessToken token; try { PrintWriter out = new PrintWriter(socket....
#fixed code @Override public AccessToken refreshAccessToken() throws IOException { Socket socket = new Socket("localhost", this.getAuthPort()); socket.setSoTimeout(READ_TIMEOUT_MS); AccessToken token; try { OutputStream os = socket.getOutputStream(); os.write(...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void refreshAccessToken() throws IOException{ final ServerSocket authSocket = new ServerSocket(0); Runnable serverTask = new Runnable() { @Override public void run() { try { Socket clientSocket = authSocket.accept(); ...
#fixed code @Test public void refreshAccessToken() throws IOException{ final ServerSocket authSocket = new ServerSocket(0); try { Runnable serverTask = new Runnable() { @Override public void run() { try { Socket clientSocket = authSocke...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public AccessToken refreshAccessToken() throws IOException { Socket socket = new Socket("localhost", this.getAuthPort()); socket.setSoTimeout(READ_TIMEOUT_MS); AccessToken token; try { PrintWriter out = new PrintWriter(socket....
#fixed code @Override public AccessToken refreshAccessToken() throws IOException { Socket socket = new Socket("localhost", this.getAuthPort()); socket.setSoTimeout(READ_TIMEOUT_MS); AccessToken token; try { OutputStream os = socket.getOutputStream(); os.write(...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void refresh_refreshesToken() throws IOException { final String accessToken1 = "1/MkSJoj1xsli0AccessToken_NKPY2"; final String accessToken2 = "2/MkSJoj1xsli0AccessToken_NKPY2"; MockTokenServerTransport transport = new MockTokenServerTransport();...
#fixed code @Test public void refresh_refreshesToken() throws IOException { final String accessToken1 = "1/MkSJoj1xsli0AccessToken_NKPY2"; final String accessToken2 = "2/MkSJoj1xsli0AccessToken_NKPY2"; MockTokenServerTransport transport = new MockTokenServerTransport(); t...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void readDictionaryFromFile(String file, ArrayList<Integer> wordSizes) { for (int wordSize : wordSizes) { int wordCount = 0; IntVar[] list = new IntVar[wordSize]; for (int i = 0; i < wordSize; i++) li...
#fixed code public void readDictionaryFromFile(String file, ArrayList<Integer> wordSizes) { for (int wordSize : wordSizes) { int wordCount = 0; IntVar[] list = new IntVar[wordSize]; for (int i = 0; i < wordSize; i++) list[i] ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void commonInitialization(IntVar[] list, int[] weights, IntVar sum) { queueIndex = 1; assert (list.length == weights.length) : "\nLength of two vectors different in SumWeight"; numberArgs = (short) (list.length + 1); numberId ...
#fixed code private void commonInitialization(IntVar[] list, int[] weights, IntVar sum) { queueIndex = 1; assert (list.length == weights.length) : "\nLength of two vectors different in SumWeight"; numberArgs = (short) (list.length + 1); numberId = idNu...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static String[] readFile(String file) { List<String> result = new ArrayList<String>(); System.out.println("readFile(" + file + ")"); try { BufferedReader inr = new BufferedReader(new InputStreamReader(new FileIn...
#fixed code public static String[] readFile(String file) { List<String> result = new ArrayList<String>(); System.out.println("readFile(" + file + ")"); try(BufferedReader inr = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"))) { ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void queueVariable(int level, Var var) { int i = varToIndex.get(var); indexQueue.add(i); } #location 4 #vulnerability type NULL_DEREFERENCE
#fixed code @Override public void queueVariable(int level, Var var) { Integer iVal = varXToIndex.get(var); if (iVal == null) iVal = varYToIndex.get(var); int i = iVal.intValue(); indexQueue.add(i); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Parameterized.Parameters public static Collection<String> parametricTest() throws IOException { FileReader file = new FileReader(relativePath + timeCategory + listFileName); BufferedReader br = new BufferedReader(file); String line = ""; ...
#fixed code @Parameterized.Parameters public static Collection<String> parametricTest() throws IOException { return fileReader(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void commonInitialization(Store store, IntVar[] list, int[] weights, int sum) { assert ( list.length == weights.length ) : "\nLength of two vectors different in Propagations"; this.store = store; this.b = sum; HashMap<IntVar, Integer> parameters = new Has...
#fixed code private void commonInitialization(Store store, IntVar[] list, int[] weights, int sum) { assert ( list.length == weights.length ) : "\nLength of two vectors different in Propagations"; this.store = store; this.b = sum; numberId = idNumber++; LinkedHashMap<IntVar, Inte...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Parameterized.Parameters public static Collection<String> parametricTest() throws IOException { FileReader file = new FileReader(relativePath + timeCategory + listFileName); BufferedReader br = new BufferedReader(file); String line = ""; ...
#fixed code @Parameterized.Parameters public static Collection<String> parametricTest() throws IOException { return fileReader(timeCategory); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void impose(Store store) { store.registerRemoveLevelListener(this); for (int i = 0; i < list.length; i++) { list[i].putModelConstraint(this, getConsistencyPruningEvent(list[i])); } store.addChanged(this); ...
#fixed code @Override public void impose(Store store) { super.impose(store); store.registerRemoveLevelListener(this); this.store = store; if (debugAll) { for (Var var : list) System.out.println("Variable " + var); } ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void uppendToLatexFile(String desc, String fileName) { try { System.out.println("save latex file " + fileName); OutputStreamWriter char_output = new OutputStreamWriter( new FileOutputStream(fileName), ...
#fixed code public void uppendToLatexFile(String desc, String fileName) { try(OutputStreamWriter char_output = new OutputStreamWriter(new FileOutputStream(fileName), Charset.forName("UTF-8").newEncoder()); ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected static Collection<String> fileReader(String timeCategory) throws IOException { System.out.println("timeCategory" + timeCategory); FileReader file = new FileReader(relativePath + timeCategory + listFileName); BufferedReader br = new Buff...
#fixed code protected static Collection<String> fileReader(String timeCategory) throws IOException { System.out.println("timeCategory" + timeCategory); FileReader file = new FileReader(relativePath + timeCategory + listFileName); try( BufferedReader br = new Buffer...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void readFile(String file) { System.out.println("readFile(" + file + ")"); try { BufferedReader inr = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); String str; int...
#fixed code public void readFile(String file) { System.out.println("readFile(" + file + ")"); try(BufferedReader inr = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"))) { String str; int lineCount = 0; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code void propagate(SimpleHashSet<FloatVar> fdvs) { while (!fdvs.isEmpty()) { FloatVar v = fdvs.removeFirst(); VariableNode n = varMap.get(v); n.propagate(); } } #location 8 ...
#fixed code RootBNode buildBinaryTree(BinaryNode[] nodes) { BinaryNode[] nextLevelNodes = new BinaryNode[nodes.length / 2 + nodes.length % 2]; // System.out.println ("next level length = " + nextLevelNodes.length); if (nodes.length > 1) { for (int i ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static String[] readFile(String file) { List<String> result = new ArrayList<String>(); System.out.println("readFile(" + file + ")"); try { BufferedReader inr = new BufferedReader(new InputStreamReader(new FileIn...
#fixed code public static String[] readFile(String file) { List<String> result = new ArrayList<String>(); System.out.println("readFile(" + file + ")"); try(BufferedReader inr = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"))) { ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void queueVariable(int level, Var var) { Integer iVal = varXToIndex.get(var); if (iVal == null) iVal = varYToIndex.get(var); int i = iVal.intValue(); indexQueue.add(i); } #location 7 ...
#fixed code @Override public void queueVariable(int level, Var var) { ArrayList<Integer> iValX = varXToIndex.get(var); ArrayList<Integer> iValY = varYToIndex.get(var); if (iValX != null) for (int i : iValX) indexQueue.add(i); if (iValY != null) for (int i : iValY) ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void readDictionaryFromFile(String file, List<Integer> wordSizes) { for (int wordSize : wordSizes) { int wordCount = 0; IntVar[] list = new IntVar[wordSize]; for (int i = 0; i < wordSize; i++) list[i]...
#fixed code public void readDictionaryFromFile(String file, List<Integer> wordSizes) { for (int wordSize : wordSizes) { int wordCount = 0; IntVar[] list = new IntVar[wordSize]; for (int i = 0; i < wordSize; i++) list[i] = bla...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Parameterized.Parameters public static Collection<String> parametricTest() throws IOException { FileReader file = new FileReader(relativePath + timeCategory + listFileName); BufferedReader br = new BufferedReader(file); String line = ""; ...
#fixed code @Parameterized.Parameters public static Collection<String> parametricTest() throws IOException { return fileReader(timeCategory); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static int[][] readFile(String file) { int[][] problem = null; // The problem matrix int r = 0; int c = 0; System.out.println("readFile(" + file + ")"); int lineCount = 0; try { BufferedReader inr = ...
#fixed code public static int[][] readFile(String file) { int[][] problem = null; // The problem matrix int r = 0; int c = 0; System.out.println("readFile(" + file + ")"); int lineCount = 0; try { BufferedReader inr = new Bu...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code int estimatePruningRecursive(IntVar xVar, Integer v, List<IntVar> exploredX, List<Integer> exploredV) { if (exploredX.contains(xVar)) return 0; exploredX.add(xVar); exploredV.add(v); int pruning = 0; IntDomain xDom...
#fixed code int estimatePruning(IntVar x, Integer v) { List<IntVar> exploredX = new ArrayList<IntVar>(); List<Integer> exploredV = new ArrayList<Integer>(); int pruning = estimatePruningRecursive(x, v, exploredX, exploredV); SimpleArrayList<IntVar> curr...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void commonInitialization(IntVar[] list, int[] weights, int sum) { queueIndex = 4; assert (list.length == weights.length) : "\nLength of two vectors different in SumWeightDom"; numberArgs = (short) (list.length + 1); numberId ...
#fixed code private void commonInitialization(IntVar[] list, int[] weights, int sum) { queueIndex = 4; assert (list.length == weights.length) : "\nLength of two vectors different in SumWeightDom"; numberArgs = (short) (list.length + 1); numberId = idNu...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void consistency(final Store store) { IntVar nonGround = null; int numberOnes = 0; for (IntVar e : x) if (e.min() == 1) numberOnes++; else if (e.max() != 0) ...
#fixed code @Override public void consistency(final Store store) { IntVar nonGround = null; int numberOnes = 0; int numberZeros = 0; for (IntVar e : x) { if (e.min() == 1) numberOnes++; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void model() { String lines[] = new String[100]; /* read from file args[0] or qcp.txt */ try { BufferedReader in = new BufferedReader(new FileReader(filename)); String str; while ((str = in.readL...
#fixed code @Override public void model() { String lines[] = new String[100]; /* read from file args[0] or qcp.txt */ try { BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "UTF-8")); Stri...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void readAuction(String filename) { noGoods = 0; try { BufferedReader br = new BufferedReader(new FileReader(filename)); // the first line represents the input goods String line = br.readLine(); S...
#fixed code public void readAuction(String filename) { noGoods = 0; try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(filename), "UTF-8")); // the first line represents the input goods String lin...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void readFile(String file) { System.out.println("readFile(" + file + ")"); try { BufferedReader inr = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8")); String str; int...
#fixed code public void readFile(String file) { System.out.println("readFile(" + file + ")"); try(BufferedReader inr = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"))) { String str; int lineCount = 0; ...
Below is the vulnerable code, please generate the patch based on the following information.