input
stringlengths
205
73.3k
output
stringlengths
64
73.2k
instruction
stringclasses
1 value
#vulnerable code @Override public String readFile(final String path) throws FileNotFoundException { return new java.util.Scanner(new java.io.File(this.fileBase, path), "UTF-8").useDelimiter("\\Z").next().toString(); } #location 3 ...
#fixed code @Override public String readFile(final String path) throws FileNotFoundException { try (Scanner scanner = new java.util.Scanner(new java.io.File(this.fileBase, path), "UTF-8")) { return scanner.useDelimiter("\\Z").next().toString(); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void createJarFromClassPathResources(final FileOutputStream fos, final String location) throws IOException { final Manifest m = new Manifest(); m.clear(); final Attributes global = m.getMainAttributes(); if (global.getValue(Attributes.Name.M...
#fixed code private void createJarFromClassPathResources(final FileOutputStream fos, final String location) throws IOException { final Manifest m = new Manifest(); m.clear(); final Attributes global = m.getMainAttributes(); if (global.getValue(Attributes.Name.MANIFES...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static byte[] classAsBytes(final String className) throws ClassNotFoundException { try { final URL resource = ClassUtils.class.getClassLoader().getResource( convertClassNameToFileName(className)); final BufferedInputStream stream = n...
#fixed code public static byte[] classAsBytes(final String className) throws ClassNotFoundException { final URL resource = ClassUtils.class.getClassLoader().getResource( convertClassNameToFileName(className)); try(BufferedInputStream stream = new BufferedInputStream( ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Tokenizer create(Reader reader) { logger.info(seg_type); Seg seg_method=null; if(seg_type.equals("max_word")){ seg_method = new MaxWordSeg(dic); }else if(seg_type.equals("complex")){ seg_method...
#fixed code @Override public Tokenizer create(Reader reader) { Seg seg_method=null; if(seg_type.equals("max_word")){ seg_method = new MaxWordSeg(dic); }else if(seg_type.equals("complex")){ seg_method = new ComplexSeg(dic); }else...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public boolean register(HttpServletResponse response , String userName , String passWord , String salt) { MiaoshaUser miaoShaUser = new MiaoshaUser(); miaoShaUser.setNickname(userName); String DBPassWord = MD5Utils.formPassToDBPass(passWord , s...
#fixed code public boolean register(HttpServletResponse response , String userName , String passWord , String salt) { MiaoshaUser miaoShaUser = new MiaoshaUser(); miaoShaUser.setNickname(userName); String DBPassWord = MD5Utils.formPassToDBPass(passWord , salt); ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static EntityManager createEntityManager() { init(false); return PersistUtilHelper.getEntityManager(); // return entityManagerFactory.createEntityManager(); } #location 2 #vulne...
#fixed code public static EntityManager createEntityManager() { init(false); return PersistUtilHelper.getEntityManager(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static EntityManager createEntityManager() { init(false); return PersistUtilHelper.getEntityManager(); // return entityManagerFactory.createEntityManager(); } #location 3 #vulne...
#fixed code public static EntityManager createEntityManager() { init(false); return PersistUtilHelper.getEntityManager(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void setValue(Integer value, boolean fireEvents) { if (value == null) { GWT.log("Value must be null", new RuntimeException()); return; } if (value < getMin()) { GWT.log("Value must not be l...
#fixed code @Override public void setValue(Integer value, boolean fireEvents) { try { checkRangeValue(value); setIntToRangeElement(VALUE, value); } catch(Exception e) { getLogger().log(Level.SEVERE, e.getMessage()); } ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void initialize(boolean strict) { try { activator = DOMHelper.getElementByAttribute("data-activates", getId()); if (alwaysShowActivator || !isFixed()) { String style = activator.getAttribute("style"); ...
#fixed code protected void initialize(boolean strict) { try { activator = DOMHelper.getElementByAttribute("data-activates", getId()); if (!isFixed()) { String style = activator.getAttribute("style"); if (alwaysShowActivator)...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void add(Widget child) { if(child instanceof MaterialImage) { child.getElement().getStyle().setProperty("border", "1px solid #e9e9e9"); child.getElement().getStyle().setProperty("textAlign", "center"); } ...
#fixed code @Override public void add(Widget child) { super.add(wrap(child)); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void setValue(Integer value, boolean fireEvents) { if (value == null) { GWT.log("Value must be null", new RuntimeException()); return; } if (value < getMin()) { GWT.log("Value must not be l...
#fixed code @Override public void setValue(Integer value, boolean fireEvents) { try { checkRangeValue(value); setIntToRangeElement(VALUE, value); } catch(Exception e) { getLogger().log(Level.SEVERE, e.getMessage()); } ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void load(boolean strict) { try { activator = DOMHelper.getElementByAttribute("data-activates", getId()); getNavMenu().setShowOn(ShowOn.SHOW_ON_MED_DOWN); if (alwaysShowActivator && !getTypeMixin().getStyle().equals(...
#fixed code protected void load(boolean strict) { try { activator = DOMHelper.getElementByAttribute("data-activates", getId()); MaterialWidget navMenu = getNavMenu(); if (navMenu != null) { navMenu.setShowOn(ShowOn.SHOW_ON_MED_...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void applyOverlayType() { setShowOnAttach(false); getNavMenu().setShowOn(ShowOn.SHOW_ON_LARGE); if (overlayOpeningHandler == null) { overlayOpeningHandler = addOpeningHandler(event -> { Scheduler.get().schedu...
#fixed code protected void applyOverlayType() { setShowOnAttach(false); if (overlayOpeningHandler == null) { overlayOpeningHandler = addOpeningHandler(event -> { Scheduler.get().scheduleDeferred(() -> $("#sidenav-overlay").css("visibility", "vi...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void load(boolean strict) { try { activator = DOMHelper.getElementByAttribute("data-activates", getId()); getNavMenu().setShowOn(ShowOn.SHOW_ON_MED_DOWN); if (alwaysShowActivator && !getTypeMixin().getStyle().equals(...
#fixed code protected void load(boolean strict) { try { activator = DOMHelper.getElementByAttribute("data-activates", getId()); MaterialWidget navMenu = getNavMenu(); if (navMenu != null) { navMenu.setShowOn(ShowOn.SHOW_ON_MED_...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void initialize(boolean strict) { try { activator = DOMHelper.getElementByAttribute("data-activates", getId()); MaterialWidget navMenu = new MaterialWidget(activator); navMenu.setShowOn(ShowOn.SHOW_ON_MED_DOWN); ...
#fixed code protected void initialize(boolean strict) { try { activator = DOMHelper.getElementByAttribute("data-activates", getId()); getNavMenu().setShowOn(ShowOn.SHOW_ON_MED_DOWN); if (alwaysShowActivator && getType() != SideNavType.FIXED) { ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void load(boolean strict) { try { activator = DOMHelper.getElementByAttribute("data-activates", getId()); getNavMenu().setShowOn(ShowOn.SHOW_ON_MED_DOWN); if (alwaysShowActivator && !getTypeMixin().getStyle().equals(...
#fixed code protected void load(boolean strict) { try { activator = DOMHelper.getElementByAttribute("data-activates", getId()); MaterialWidget navMenu = getNavMenu(); if (navMenu != null) { navMenu.setShowOn(ShowOn.SHOW_ON_MED_...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void add(Widget child) { if(child instanceof MaterialImage) { child.getElement().getStyle().setProperty("border", "1px solid #e9e9e9"); child.getElement().getStyle().setProperty("textAlign", "center"); } ...
#fixed code @Override public void add(Widget child) { super.add(wrap(child)); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void doRender(RunTemplate runTemplate, NumbericRenderData numbericData, XWPFTemplate template) throws Exception { NiceXWPFDocument doc = template.getXWPFDocument(); XWPFRun run = runTemplate.getRun(); List<TextRen...
#fixed code @Override public void doRender(RunTemplate runTemplate, NumbericRenderData numbericData, XWPFTemplate template) throws Exception { NiceXWPFDocument doc = template.getXWPFDocument(); XWPFRun run = runTemplate.getRun(); List<TextRenderDat...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void writeToFile(String path) throws IOException { FileOutputStream out = new FileOutputStream(path); this.write(out); this.close(); out.flush(); out.close(); } #location 7 ...
#fixed code public void writeToFile(String path) throws IOException { FileOutputStream out = null; try { out = new FileOutputStream(path); this.write(out); out.flush(); } finally { PoitlIOUtils.closeQuietlyMu...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static byte[] getUrlByteArray(String urlPath) { return toByteArray(getUrlPictureStream(urlPath)); } #location 2 #vulnerability type RESOURCE_LEAK
#fixed code public static byte[] getUrlByteArray(String urlPath) { try { return toByteArray(getUrlPictureStream(urlPath)); } catch (IOException e) { logger.error("getUrlPictureStream error,{},{}", urlPath, e); } return null; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override protected void afterRender(RenderContext context) { XWPFRun run = ((RunTemplate) context.getEleTemplate()).getRun(); clearPlaceholder(context); IRunBody parent = run.getParent(); if (parent instanceof XWPFParagraph) { ...
#fixed code @Override protected void afterRender(RenderContext context) { clearPlaceholder(context, true); // IRunBody parent = run.getParent(); // if (parent instanceof XWPFParagraph) { // ((XWPFParagraph) parent).removeRun(((RunTemplate) context.get...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void visit(InlineIterableTemplate iterableTemplate) { logger.info("Process InlineIterableTemplate:{}", iterableTemplate); BodyContainer bodyContainer = BodyContainerFactory.getBodyContainer(iterableTemplate); Object compute...
#fixed code @Override public void visit(InlineIterableTemplate iterableTemplate) { logger.info("Process InlineIterableTemplate:{}", iterableTemplate); super.visit((IterableTemplate) iterableTemplate); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void visit(InlineIterableTemplate iterableTemplate) { logger.info("Process InlineIterableTemplate:{}", iterableTemplate); BodyContainer bodyContainer = BodyContainerFactory.getBodyContainer(iterableTemplate); Object compute...
#fixed code @Override public void visit(InlineIterableTemplate iterableTemplate) { logger.info("Process InlineIterableTemplate:{}", iterableTemplate); super.visit((IterableTemplate) iterableTemplate); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void doRender(ChartTemplate eleTemplate, ChartMultiSeriesRenderData data, XWPFTemplate template) throws Exception { if (null == data) return; XWPFChart chart = eleTemplate.getChart(); List<XDDFChartData> chartSeri...
#fixed code @Override public void doRender(ChartTemplate eleTemplate, ChartMultiSeriesRenderData data, XWPFTemplate template) throws Exception { XWPFChart chart = eleTemplate.getChart(); List<XDDFChartData> chartSeries = chart.getChartSeries(); val...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private List<NiceXWPFDocument> getMergedDocxs(DocxRenderData data, Configure configure) { List<NiceXWPFDocument> docs = new ArrayList<NiceXWPFDocument>(); File docx = data.getDocx(); List<?> dataList = data.getDataList(); if (null == data...
#fixed code private List<NiceXWPFDocument> getMergedDocxs(DocxRenderData data, Configure configure) throws IOException { List<NiceXWPFDocument> docs = new ArrayList<NiceXWPFDocument>(); byte[] docx = data.getDocx(); List<?> dataList = data.getDataList(); i...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void shouldAddHeader() throws IOException { driver.addExpectation(onRequestTo("/") .withHeader("X-Trace-ID", "16c38974-7530-11e5-bb35-10ddb1ee7671") .withHeader("X-Request-ID", "2e7a3324-7530-11e5-...
#fixed code @Test public void shouldAddHeader() throws IOException { driver.addExpectation(onRequestTo("/") .withHeader("X-Trace-ID", "16c38974-7530-11e5-bb35-10ddb1ee7671") .withHeader("X-Request-ID", "2e7a3324-7530-11e5-ad30-1...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test void jdk() { Graphviz.useEngine(new GraphvizJdkEngine()); assertThat(Graphviz.fromString("graph g {a--b}").render(SVG_STANDALONE).toString(), startsWith(START1_7)); } #location 3 #vu...
#fixed code @Test void jdk() throws IOException, ScriptException { String script = new String(Files.readAllBytes(new File("../dist/bundle.js").toPath())); ScriptEngine js = new ScriptEngineManager().getEngineByExtension("js"); //js.eval(script); V8 v8 ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test void simple() throws IOException { Graphviz.fromString("graph{a--b}") .scale(2) .filter(new RoughFilter()) .render(Format.PNG) .toFile(new File("target/out.png")); } ...
#fixed code @Test void simple() throws IOException { FontTools.availableFontNamesGraph(new File("fonts.png")); final Graph g = graph("ex7").directed() .with( graph().cluster() .nodeAttr().with(Sty...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test void ex8() throws IOException { //## image Graphviz.useEngine(new GraphvizV8Engine()); Graphviz g = Graphviz.fromGraph(graph() .with(node(" ").with(Size.std().margin(.8, .7), Image.of("graphviz.png")))); g.basedi...
#fixed code @Test void ex8() throws IOException { //## image Graphviz g = Graphviz.fromGraph(graph() .with(node(" ").with(Size.std().margin(.8, .7), Image.of("graphviz.png")))); g.basedir(new File("example")).render(Format.PNG).toFile(new File(...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test void jdk() throws IOException, ScriptException { String script = new String(Files.readAllBytes(new File("../dist/bundle.js").toPath())); ScriptEngine js = new ScriptEngineManager().getEngineByExtension("js"); //js.eval(script); ...
#fixed code @Test void jdk() { Graphviz.useEngine(new GraphvizJdkEngine()); assertThat(Graphviz.fromString("graph g {a--b}").render(SVG_STANDALONE).toString(), startsWith(START1_7)); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test void cmdLineOutputDotFile() throws IOException, InterruptedException { final File dotFile = setUpFakeDotFile(); final CommandLineExecutor cmdExecutor = setUpFakeStubCommandExecutor(); final String envPath = dotFile.getParent(); ...
#fixed code @Test void cmdLineOutputDotFile() throws IOException, InterruptedException { final File dotOutputFolder = new File(temp, "out"); dotOutputFolder.mkdir(); final String dotOutputName = "test123"; // Configure engine to output the dotFile to ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void releaseEngine() { if (engine != null) { try { engine.close(); } catch (Exception e) { throw new GraphvizException("Problem closing engine", e); } } engine = nu...
#fixed code public static void releaseEngine() { synchronized (Graphviz.class) { if (engine != null) { doReleaseEngine(engine); } if (engineQueue != null) { for (final GraphvizEngine engine : engineQueue) { ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void useDefaultEngines() { useEngine(new GraphvizCmdLineEngine(), new GraphvizV8Engine(), new GraphvizServerEngine(), new GraphvizJdkEngine()); } #location 2 #vulnerabili...
#fixed code public static void useDefaultEngines() { useEngine(AVAILABLE_ENGINES); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void releaseEngine() { if (engine != null) { try { engine.close(); } catch (Exception e) { throw new GraphvizException("Problem closing engine", e); } } engine = nu...
#fixed code public static void releaseEngine() { synchronized (Graphviz.class) { if (engine != null) { doReleaseEngine(engine); } if (engineQueue != null) { for (final GraphvizEngine engine : engineQueue) { ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void useDefaultEngines() { useEngine(new GraphvizCmdLineEngine(), new GraphvizV8Engine(), new GraphvizServerEngine(), new GraphvizJdkEngine()); } #location 2 #vulnerabili...
#fixed code public static void useDefaultEngines() { useEngine(AVAILABLE_ENGINES); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void start(List<GraphvizEngine> engines) throws IOException { final boolean windows = System.getProperty("os.name").contains("windows"); final String executable = windows ? "java.exe" : "java"; final List<String> cmd = new ArrayList...
#fixed code public static void start(List<GraphvizEngine> engines) throws IOException { final String executable = SystemUtils.executableName("java"); final List<String> cmd = new ArrayList<>(Arrays.asList( System.getProperty("java.home") + "/bin/" + execut...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } int retryTimes = 0; Set<Integer> acceptStatCode; String charset = null; Ma...
#fixed code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } Set<Integer> acceptStatCode; String charset = null; Map<String, String> headers = null; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } int retryTimes = 0; Set<Integer> acceptStatCode; String charset = null; if...
#fixed code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } int retryTimes = 0; Set<Integer> acceptStatCode; String charset = null; Map<Stri...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void checkComponent() { if (downloader == null) { this.downloader = new HttpClientDownloader(); } } #location 2 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code protected void checkComponent() { if (downloader == null) { this.downloader = new HttpClientDownloader(); } if (pipelines.isEmpty()) { pipelines.add(new ConsolePipeline()); } downloader.setThread(threadNum); ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void run() { if (!stat.compareAndSet(STAT_INIT, STAT_RUNNING)) { throw new IllegalStateException("Spider is already running!"); } checkComponent(); if (startUrls != null) { for (String startUrl...
#fixed code @Override public void run() { if (!stat.compareAndSet(STAT_INIT, STAT_RUNNING)) { throw new IllegalStateException("Spider is already running!"); } checkComponent(); if (startUrls != null) { for (String startUrl : sta...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Ignore @Test public void testCookie() { Site site = Site.me().setDomain("www.diandian.com").addCookie("t", "yct7q7e6v319wpg4cpxqduu5m77lcgix"); HttpClientDownloader httpClientDownloader = new HttpClientDownloader(); Page download = httpC...
#fixed code @Ignore @Test public void testCookie() { Site site = Site.me().setDomain("www.diandian.com").addCookie("t", "yct7q7e6v319wpg4cpxqduu5m77lcgix"); HttpClientDownloader httpClientDownloader = new HttpClientDownloader(); Page download = httpClientD...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public Spider thread(int threadNum) { checkIfRunning(); this.threadNum = threadNum; if (threadNum <= 0) { throw new IllegalArgumentException("threadNum should be more than one!"); } if (threadNum == 1) { re...
#fixed code public Spider thread(int threadNum) { checkIfRunning(); this.threadNum = threadNum; if (threadNum <= 0) { throw new IllegalArgumentException("threadNum should be more than one!"); } if (threadNum == 1) { return t...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void readCursorFile() throws IOException { BufferedReader fileCursorReader = null; try { new BufferedReader(new FileReader(getFileName(fileCursor))); String line; //read the last number while ((line...
#fixed code private void readCursorFile() throws IOException { BufferedReader fileCursorReader = null; try { fileCursorReader = new BufferedReader(new FileReader(getFileName(fileCursor))); String line; //read the last number wh...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void readCursorFile() throws IOException { BufferedReader fileCursorReader = null; try { new BufferedReader(new FileReader(getFileName(fileCursor))); String line; //read the last number while ((line...
#fixed code private void readCursorFile() throws IOException { BufferedReader fileCursorReader = null; try { fileCursorReader = new BufferedReader(new FileReader(getFileName(fileCursor))); String line; //read the last number wh...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testGetHtmlCharset() throws IOException { HttpClientDownloader downloader = new HttpClientDownloader(); Site site = Site.me(); CloseableHttpClient httpClient = new HttpClientGenerator().getClient(site); // encoding i...
#fixed code @Test public void testGetHtmlCharset() throws Exception { HttpServer server = httpserver(12306); server.get(by(uri("/header"))).response(header("Content-Type", "text/html; charset=gbk")); server.get(by(uri("/meta4"))).response(with(text("<html>\n" ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void checkComponent() { if (downloader == null) { this.downloader = new HttpClientDownloader(); } } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code protected void checkComponent() { if (downloader == null) { this.downloader = new HttpClientDownloader(); } if (pipelines.isEmpty()) { pipelines.add(new ConsolePipeline()); } downloader.setThread(threadNum); ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void run() { if (!stat.compareAndSet(STAT_INIT, STAT_RUNNING) && !stat.compareAndSet(STAT_STOPPED, STAT_RUNNING)) { throw new IllegalStateException("Spider is already running!"); } checkComponent()...
#fixed code @Override public void run() { if (!stat.compareAndSet(STAT_INIT, STAT_RUNNING) && !stat.compareAndSet(STAT_STOPPED, STAT_RUNNING)) { throw new IllegalStateException("Spider is already running!"); } checkComponent(); ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void run() { checkRunningStat(); initComponent(); logger.info("Spider " + getUUID() + " started!"); final AtomicInteger threadAlive = new AtomicInteger(0); while (!Thread.currentThread().isInterrupted() && sta...
#fixed code @Override public void run() { checkRunningStat(); initComponent(); logger.info("Spider " + getUUID() + " started!"); final AtomicInteger threadAlive = new AtomicInteger(0); while (!Thread.currentThread().isInterrupted() && stat.get(...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testRemovePadding() throws Exception { String name = new Json(text).removePadding("callback").jsonPath("$.name").get(); assertThat(name).isEqualTo("json"); Page page = null; page.getJson().jsonPath("$.name").get(); ...
#fixed code @Test public void testRemovePadding() throws Exception { String name = new Json(text).removePadding("callback").jsonPath("$.name").get(); assertThat(name).isEqualTo("json"); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } int retryTimes = 0; Set<Integer> acceptStatCode; String charset = null; Ma...
#fixed code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } int retryTimes = 0; Set<Integer> acceptStatCode; String charset = null; Map<Stri...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void run() { checkRunningStat(); initComponent(); logger.info("Spider " + getUUID() + " started!"); while (!Thread.currentThread().isInterrupted() && stat.get() == STAT_RUNNING) { Request request = schedul...
#fixed code @Override public void run() { checkRunningStat(); initComponent(); logger.info("Spider " + getUUID() + " started!"); while (!Thread.currentThread().isInterrupted() && stat.get() == STAT_RUNNING) { Request request = scheduler.pol...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } int retryTimes = 0; Set<Integer> acceptStatCode; String charset = null; Ma...
#fixed code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } Set<Integer> acceptStatCode; String charset = null; Map<String, String> headers = null; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } int retryTimes = 0; Set<Integer> acceptStatCode; String charset = null; Ma...
#fixed code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } Set<Integer> acceptStatCode; String charset = null; Map<String, String> headers = null; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void run() { checkRunningStat(); initComponent(); logger.info("Spider " + getUUID() + " started!"); final AtomicInteger threadAlive = new AtomicInteger(0); while (!Thread.currentThread().isInterrupted() && sta...
#fixed code @Override public void run() { checkRunningStat(); initComponent(); logger.info("Spider " + getUUID() + " started!"); final AtomicInteger threadAlive = new AtomicInteger(0); while (!Thread.currentThread().isInterrupted() && stat.get(...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public Spider thread(int threadNum) { checkIfNotRunning(); if (threadNum <= 0) { throw new IllegalArgumentException("threadNum should be more than one!"); } if (downloader==null || downloader instanceof HttpClientDownloader){ ...
#fixed code public Spider thread(int threadNum) { checkIfNotRunning(); this.threadNum = threadNum; if (threadNum <= 0) { throw new IllegalArgumentException("threadNum should be more than one!"); } if (threadNum == 1) { retur...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void setThread(int thread) { poolSize = thread; httpClientPool = new HttpClientPool(thread); } #location 4 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code @Override public void setThread(int thread) { poolSize = thread; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override protected void pushWhenNoDuplicate(Request request, Task task) { if (!inited.get()) { init(task); } queue.add(request); fileUrlWriter.println(request.getUrl()); } #location 4 ...
#fixed code @Override protected void pushWhenNoDuplicate(Request request, Task task) { /* if (!inited.get()) { init(task); }*/ queue.add(request); fileUrlWriter.println(request.getUrl()); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } int retryTimes = 0; Set<Integer> acceptStatCode; String charset = null; Ma...
#fixed code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } Set<Integer> acceptStatCode; String charset = null; Map<String, String> headers = null; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void run() { checkRunningStat(); initComponent(); logger.info("Spider " + getUUID() + " started!"); final AtomicInteger threadAlive = new AtomicInteger(0); while (!Thread.currentThread().isInterrupted() && sta...
#fixed code @Override public void run() { checkRunningStat(); initComponent(); logger.info("Spider " + getUUID() + " started!"); final AtomicInteger threadAlive = new AtomicInteger(0); while (!Thread.currentThread().isInterrupted() && stat.get(...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void setThread(int thread) { poolSize = thread; } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code @Override public void setThread(int thread) { httpClientGenerator.setPoolSize(thread); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } Set<Integer> acceptStatCode; String charset = null; Map<String, String> headers = ...
#fixed code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } Set<Integer> acceptStatCode; String charset = null; Map<String, String> headers = null; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void run() { checkRunningStat(); initComponent(); logger.info("Spider " + getUUID() + " started!"); final AtomicInteger threadAlive = new AtomicInteger(0); while (!Thread.currentThread().isInterrupted() && sta...
#fixed code @Override public void run() { checkRunningStat(); initComponent(); logger.info("Spider " + getUUID() + " started!"); final AtomicInteger threadAlive = new AtomicInteger(0); while (!Thread.currentThread().isInterrupted() && stat.get(...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void run() { if (!stat.compareAndSet(STAT_INIT, STAT_RUNNING) && !stat.compareAndSet(STAT_STOPPED, STAT_RUNNING)) { throw new IllegalStateException("Spider is already running!"); } checkComponent()...
#fixed code @Override public void run() { if (!stat.compareAndSet(STAT_INIT, STAT_RUNNING) && !stat.compareAndSet(STAT_STOPPED, STAT_RUNNING)) { throw new IllegalStateException("Spider is already running!"); } checkComponent(); ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void readCursorFile() throws IOException { BufferedReader fileCursorReader = new BufferedReader(new FileReader(getFileName(fileCursor))); String line; //read the last number while ((line = fileCursorReader.readLine()) != null) { ...
#fixed code private void readCursorFile() throws IOException { BufferedReader fileCursorReader = null; try { new BufferedReader(new FileReader(getFileName(fileCursor))); String line; //read the last number while ((line = fil...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected Page handleResponse(Request request, String charset, HttpResponse httpResponse, Task task) throws IOException { String content = IOUtils.toString(httpResponse.getEntity().getContent(), charset); Page page = new Page(); p...
#fixed code protected Page handleResponse(Request request, String charset, HttpResponse httpResponse, Task task) throws IOException { String content = EntityUtils.toString(httpResponse.getEntity(), charset); Page page = new Page(); page.setHtml(new Html(UrlUtils.f...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public int getThreadAlive() { return threadAlive; } #location 2 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code public int getThreadAlive() { return threadAlive.get(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void run() { if (!stat.compareAndSet(STAT_INIT, STAT_RUNNING)) { throw new IllegalStateException("Spider is already running!"); } checkComponent(); if (startUrls != null) { for (String startUrl...
#fixed code @Override public void run() { if (!stat.compareAndSet(STAT_INIT, STAT_RUNNING)) { throw new IllegalStateException("Spider is already running!"); } checkComponent(); if (startUrls != null) { for (String startUrl : sta...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } int retryTimes = 0; Set<Integer> acceptStatCode; String charset = null; Ma...
#fixed code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } Set<Integer> acceptStatCode; String charset = null; Map<String, String> headers = null; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void run() { checkRunningStat(); initComponent(); logger.info("Spider " + getUUID() + " started!"); final AtomicInteger threadAlive = new AtomicInteger(0); while (!Thread.currentThread().isInterrupted() && sta...
#fixed code @Override public void run() { checkRunningStat(); initComponent(); logger.info("Spider " + getUUID() + " started!"); final AtomicInteger threadAlive = new AtomicInteger(0); while (!Thread.currentThread().isInterrupted() && stat.get(...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public Spider thread(int threadNum) { checkIfNotRunning(); if (threadNum <= 0) { throw new IllegalArgumentException("threadNum should be more than one!"); } if (downloader==null || downloader instanceof HttpClientDownloader){ ...
#fixed code public Spider thread(int threadNum) { checkIfNotRunning(); this.threadNum = threadNum; if (threadNum <= 0) { throw new IllegalArgumentException("threadNum should be more than one!"); } if (threadNum == 1) { retur...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } Set<Integer> acceptStatCode; String charset = null; Map<String, String> headers = ...
#fixed code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } Set<Integer> acceptStatCode; String charset = null; Map<String, String> headers = null; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } Set<Integer> acceptStatCode; String charset = null; Map<String, String> headers = ...
#fixed code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } Set<Integer> acceptStatCode; String charset = null; Map<String, String> headers = null; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } Set<Integer> acceptStatCode; String charset = null; Map<String, String> headers = ...
#fixed code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } Set<Integer> acceptStatCode; String charset = null; Map<String, String> headers = null; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override protected void pushWhenNoDuplicate(Request request, Task task) { if (!inited.get()) { init(task); } if(urls.contains(request.getUrl())) //已存在此URL 表示已抓取过 跳过 return; queue.add(request); fileUrlW...
#fixed code @Override protected void pushWhenNoDuplicate(Request request, Task task) { if (!inited.get()) { init(task); } queue.add(request); fileUrlWriter.println(request.getUrl()); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void run() { checkRunningStat(); initComponent(); logger.info("Spider " + getUUID() + " started!"); final AtomicInteger threadAlive = new AtomicInteger(0); while (!Thread.currentThread().isInterrupted() && sta...
#fixed code @Override public void run() { checkRunningStat(); initComponent(); logger.info("Spider " + getUUID() + " started!"); final AtomicInteger threadAlive = new AtomicInteger(0); while (!Thread.currentThread().isInterrupted() && stat.get(...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } int retryTimes = 0; Set<Integer> acceptStatCode; String charset = null; Ma...
#fixed code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } Set<Integer> acceptStatCode; String charset = null; Map<String, String> headers = null; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Ignore @Test public void testCookie() { Site site = Site.me().setDomain("www.diandian.com").addCookie("t", "yct7q7e6v319wpg4cpxqduu5m77lcgix"); HttpClientDownloader httpClientDownloader = new HttpClientDownloader(); Page download = httpC...
#fixed code @Ignore @Test public void testCookie() { Site site = Site.me().setDomain("www.diandian.com").addCookie("t", "yct7q7e6v319wpg4cpxqduu5m77lcgix"); HttpClientDownloader httpClientDownloader = new HttpClientDownloader(); Page download = httpClientD...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } Set<Integer> acceptStatCode; String charset = null; Map<String, String> headers = ...
#fixed code @Override public Page download(Request request, Task task) { Site site = null; if (task != null) { site = task.getSite(); } Set<Integer> acceptStatCode; String charset = null; Map<String, String> headers = null; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void processRequest(Request request) { Page page = downloader.download(request, this); if (page == null) { sleep(site.getSleepTime()); onError(request); } // for cycle retry if (page.isNeedCycleRe...
#fixed code protected void processRequest(Request request) { Page page = downloader.download(request, this); if (page == null) { sleep(site.getSleepTime()); onError(request); return; } // for cycle retry if (page...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public boolean tryAdvance(Consumer<? super E> action) { Objects.requireNonNull(action); if (!exhausted) { ReentrantLock lock = queueLock; Object p = current; E e = null; lock.lock(); ...
#fixed code @Override public boolean tryAdvance(Consumer<? super E> action) { Objects.requireNonNull(action); if (!exhausted) { E e = null; ReentrantLock lock = queueLock; lock.lock(); try { Object p; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override @SuppressWarnings("unchecked") public void forEachRemaining(Consumer<? super E> action) { Objects.requireNonNull(action); int i, hi; // hoist accesses and checks from loop Vector<E> lst = list; Object[] a; if ((h...
#fixed code @Override @SuppressWarnings("unchecked") public void forEachRemaining(Consumer<? super E> action) { Objects.requireNonNull(action); int hi = getFence(); Object[] a = array; int i; for (i = index, index = hi; i < hi; i++) { ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override @SuppressWarnings("unchecked") public void forEachRemaining(Consumer<? super E> action) { Objects.requireNonNull(action); int i, hi; // hoist accesses and checks from loop Vector<E> lst = list; Object[] a; if ((h...
#fixed code @Override @SuppressWarnings("unchecked") public void forEachRemaining(Consumer<? super E> action) { Objects.requireNonNull(action); int hi = getFence(); Object[] a = array; int i; for (i = index, index = hi; i < hi; i++) { ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public boolean tryAdvance(Consumer<? super E> action) { Objects.requireNonNull(action); LinkedBlockingDeque<E> q = queue; ReentrantLock lock = queueLock; if (!exhausted) { E e = null; lock.lock(); ...
#fixed code @Override public boolean tryAdvance(Consumer<? super E> action) { Objects.requireNonNull(action); if (exhausted) return false; LinkedBlockingDeque<E> q = queue; ReentrantLock lock = queueLock; Object p = current; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public boolean tryAdvance(Consumer<? super E> action) { Objects.requireNonNull(action); if (!exhausted) { ReentrantLock lock = queueLock; Object p = current; E e = null; lock.lock(); ...
#fixed code @Override public boolean tryAdvance(Consumer<? super E> action) { Objects.requireNonNull(action); if (!exhausted) { E e = null; ReentrantLock lock = queueLock; lock.lock(); try { Object p; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override @SuppressWarnings("unchecked") public void forEachRemaining(Consumer<? super E> action) { Objects.requireNonNull(action); int i, hi; // hoist accesses and checks from loop Vector<E> lst = list; Object[] a; if ((h...
#fixed code @Override @SuppressWarnings("unchecked") public void forEachRemaining(Consumer<? super E> action) { Objects.requireNonNull(action); int hi = getFence(); Object[] a = array; int i; for (i = index, index = hi; i < hi; i++) { ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void forEachRemaining(Consumer<? super E> action) { Objects.requireNonNull(action); if (!exhausted) { exhausted = true; ReentrantLock lock = queueLock; Object p = current; current = nul...
#fixed code @Override public void forEachRemaining(Consumer<? super E> action) { Objects.requireNonNull(action); if (!exhausted) { exhausted = true; Object p = current; current = null; forEachFrom(action, p); } ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void forEachRemaining(Consumer<? super E> action) { Objects.requireNonNull(action); if (!exhausted) { exhausted = true; ReentrantLock lock = queueLock; Object p = current; current = nul...
#fixed code @Override public void forEachRemaining(Consumer<? super E> action) { Objects.requireNonNull(action); if (!exhausted) { exhausted = true; Object p = current; current = null; forEachFrom(action, p); } ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void forEachRemaining(Consumer<? super E> action) { Objects.requireNonNull(action); if (!exhausted) { exhausted = true; ReentrantLock lock = queueLock; Object p = current; current = nul...
#fixed code @Override public void forEachRemaining(Consumer<? super E> action) { Objects.requireNonNull(action); if (!exhausted) { exhausted = true; Object p = current; current = null; forEachFrom(action, p); } ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override @SuppressWarnings("unchecked") public void forEachRemaining(Consumer<? super E> action) { Objects.requireNonNull(action); int i, hi; // hoist accesses and checks from loop Vector<E> lst = list; Object[] a; if ((h...
#fixed code @Override @SuppressWarnings("unchecked") public void forEachRemaining(Consumer<? super E> action) { Objects.requireNonNull(action); int hi = getFence(); Object[] a = array; int i; for (i = index, index = hi; i < hi; i++) { ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void forEachRemaining(Consumer<? super E> action) { Objects.requireNonNull(action); if (!exhausted) { exhausted = true; ReentrantLock lock = queueLock; Object p = current; current = nul...
#fixed code @Override public void forEachRemaining(Consumer<? super E> action) { Objects.requireNonNull(action); if (!exhausted) { exhausted = true; Object p = current; current = null; forEachFrom(action, p); } ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public boolean tryAdvance(Consumer<? super E> action) { Objects.requireNonNull(action); LinkedBlockingDeque<E> q = queue; ReentrantLock lock = queueLock; if (!exhausted) { E e = null; lock.lock(); ...
#fixed code @Override public boolean tryAdvance(Consumer<? super E> action) { Objects.requireNonNull(action); if (exhausted) return false; LinkedBlockingDeque<E> q = queue; ReentrantLock lock = queueLock; Object p = current; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private static Map<Integer, String> listProcessByJps(boolean v) { Map<Integer, String> result = new LinkedHashMap<Integer, String>(); String jps = "jps"; File jpsFile = findJps(); if (jpsFile != null) { jps = jpsFile.getAbsol...
#fixed code private static Map<Integer, String> listProcessByJps(boolean v) { Map<Integer, String> result = new LinkedHashMap<Integer, String>(); String jps = "jps"; File jpsFile = findJps(); if (jpsFile != null) { jps = jpsFile.getAbsolutePat...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void process(final CommandProcess process) { int exitCode = 0; RowAffect affect = new RowAffect(); try { Instrumentation inst = process.session().getInstrumentation(); ClassLoader classloader = null; ...
#fixed code @Override public void process(final CommandProcess process) { int exitCode = 0; RowAffect affect = new RowAffect(); try { Instrumentation inst = process.session().getInstrumentation(); ClassLoader classloader = null; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private static Map<Integer, String> listProcessByJps(boolean v) { Map<Integer, String> result = new LinkedHashMap<Integer, String>(); File jps = findJps(); if (jps == null) { return result; } String[] command = null;...
#fixed code private static Map<Integer, String> listProcessByJps(boolean v) { Map<Integer, String> result = new LinkedHashMap<Integer, String>(); String jps = "jps"; File jpsFile = findJps(); if (jpsFile != null) { jps = jpsFile.getAbsolutePat...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private static List<String> listNames(File dir) { List<String> names = new ArrayList<String>(); for (File file : dir.listFiles()) { String name = file.getName(); if (name.startsWith(".") || file.isFile()) { continu...
#fixed code private static List<String> listNames(File dir) { List<String> names = new ArrayList<String>(); if (!dir.exists()) { return names; } File[] files = dir.listFiles(); if (files == null) { return names; } ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void process(final CommandProcess process) { int exitCode = 0; RowAffect affect = new RowAffect(); try { Instrumentation inst = process.session().getInstrumentation(); ClassLoader classloader = null; ...
#fixed code @Override public void process(final CommandProcess process) { int exitCode = 0; RowAffect affect = new RowAffect(); try { Instrumentation inst = process.session().getInstrumentation(); ClassLoader classloader = null; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private static Map<Integer, String> listProcessByJps(boolean v) { Map<Integer, String> result = new LinkedHashMap<Integer, String>(); File jps = findJps(); if (jps == null) { return result; } String[] command = null;...
#fixed code private static Map<Integer, String> listProcessByJps(boolean v) { Map<Integer, String> result = new LinkedHashMap<Integer, String>(); String jps = "jps"; File jpsFile = findJps(); if (jpsFile != null) { jps = jpsFile.getAbsolutePat...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testExplicitevaluate() { ExpressionFlipStrategy efs = new ExpressionFlipStrategy(); Assert.assertTrue(efs.evaluate("D", ff4j.getStore(), null)); Assert.assertTrue(efs.evaluate("TOTO", ff4j.getStore(), null)); Flippi...
#fixed code @Test public void testExplicitevaluate() { ExpressionFlipStrategy efs = new ExpressionFlipStrategy(); Assert.assertTrue(efs.evaluate("D", ff4j.getStore(), null)); Assert.assertTrue(efs.evaluate("TOTO", ff4j.getStore(), null)); FlippingExe...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void write(String content, File output) throws IOException { FileOutputStream out = new FileOutputStream(output); OutputStreamWriter w = new OutputStreamWriter(out); try { w.write(content); w.flush(); } finally { out.close(); } } ...
#fixed code public static void write(String content, File output) throws IOException { try (final FileOutputStream out = new FileOutputStream(output); final OutputStreamWriter w = new OutputStreamWriter(out)) { w.write(content); w.flush(); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void removeExecutable(Distribution distribution, File executable) { FileWithCounter fileWithCounter; synchronized (_lock) { fileWithCounter = _distributionFiles.get(distribution); } fileWithCounter.free(executable); //_delegate.removeExecutab...
#fixed code @Override public void removeExecutable(Distribution distribution, File executable) { FileWithCounter fileWithCounter; synchronized (_lock) { fileWithCounter = _distributionFiles.get(distribution); } if (fileWithCounter!=null) { fileWithCounter.free(executable); ...
Below is the vulnerable code, please generate the patch based on the following information.