input
stringlengths
205
73.3k
output
stringlengths
64
73.2k
instruction
stringclasses
1 value
#vulnerable code @Override public List<BxDocument> getDocuments() throws TransformationException { List<BxDocument> documents = new ArrayList<BxDocument>(); TrueVizToBxDocumentReader tvReader = new TrueVizToBxDocumentReader(); Enumeration<? extends ZipEntry>...
#fixed code @Override public List<BxDocument> getDocuments() throws TransformationException { List<BxDocument> documents = new ArrayList<BxDocument>(); TrueVizToBxDocumentReader tvReader = new TrueVizToBxDocumentReader(); Enumeration<? extends ZipEntry> entri...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void loadModelFromFile(String modelFilePath, String rangeFilePath) throws IOException { BufferedReader modelFile = new BufferedReader(new InputStreamReader(new FileInputStream(modelFilePath))); BufferedReader rangeFile = null; if (rangeFil...
#fixed code public void loadModelFromFile(String modelFilePath, String rangeFilePath) throws IOException { BufferedReader modelFile = new BufferedReader(new InputStreamReader(new FileInputStream(modelFilePath), "UTF-8")); BufferedReader rangeFile = null; if (range...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(String[] args) throws JDOMException, IOException, AnalysisException { if (args.length != 3) { System.err.println("USAGE: ReferenceParsingEvaluator <foldness> <model_path> <test_path>"); System.exit(1); } ...
#fixed code public static void main(String[] args) throws JDOMException, IOException, AnalysisException { if (args.length != 3) { System.err.println("USAGE: ReferenceParsingEvaluator <foldness> <model_path> <test_path>"); System.exit(1); } ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void deepCloneTest() throws TransformationException { InputStream stream = BxModelUtilsTest.class.getResourceAsStream(EXP_STR_LAB_1); TrueVizToBxDocumentReader reader = new TrueVizToBxDocumentReader(); BxDocument doc = new BxDocu...
#fixed code @Test public void deepCloneTest() throws TransformationException, UnsupportedEncodingException { InputStream stream = BxModelUtilsTest.class.getResourceAsStream(EXP_STR_LAB_1); TrueVizToBxDocumentReader reader = new TrueVizToBxDocumentReader(); BxD...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void loadModelFromResources(String modelFilePath, String rangeFilePath) throws IOException { InputStreamReader modelISR = new InputStreamReader(SVMClassifier.class .getResourceAsStream(modelFilePath)); BufferedReader modelFile = new BufferedReader(modelISR)...
#fixed code public void loadModelFromResources(String modelFilePath, String rangeFilePath) throws IOException { InputStreamReader modelISR = new InputStreamReader(this.getClass().getResourceAsStream(modelFilePath)); BufferedReader modelFile = new BufferedReader(modelISR); InputStr...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static List<TrainingSample<BxZoneLabel>> loadProblem(File file, FeatureVectorBuilder<BxZone, BxPage> fvb) throws IOException { List<TrainingSample<BxZoneLabel>> ret = new ArrayList<TrainingSample<BxZoneLabel>>(); BufferedReader br = new BufferedRe...
#fixed code public static List<TrainingSample<BxZoneLabel>> loadProblem(File file, FeatureVectorBuilder<BxZone, BxPage> fvb) throws IOException { List<TrainingSample<BxZoneLabel>> ret = new ArrayList<TrainingSample<BxZoneLabel>>(); BufferedReader br = new BufferedReader(n...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void loadModelFromResources(String modelFilePath, String rangeFilePath) throws IOException { InputStreamReader modelISR = new InputStreamReader(SVMClassifier.class.getResourceAsStream(modelFilePath)); BufferedReader modelFile = new BufferedReader(...
#fixed code public void loadModelFromResources(String modelFilePath, String rangeFilePath) throws IOException { InputStreamReader modelISR = new InputStreamReader(SVMClassifier.class.getResourceAsStream(modelFilePath), "UTF-8"); BufferedReader modelFile = new BufferedRead...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(String[] args) { if (args.length != 1) { System.err.println("Usage: <pubmed directory>"); System.exit(1); } File dir = new File(args[0]); for (File pdfFile : FileUtils.listFiles(dir, new S...
#fixed code public static void main(String[] args) { if (args.length != 1) { System.err.println("Usage: <pubmed directory>"); System.exit(1); } File dir = new File(args[0]); for (File pdfFile : FileUtils.listFiles(dir, new String[...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void loadModelFromFile(String modelFilePath, String rangeFilePath) throws IOException { BufferedReader modelFile = new BufferedReader(new InputStreamReader(new FileInputStream(modelFilePath))); BufferedReader rangeFile = null; if (rangeFil...
#fixed code public void loadModelFromFile(String modelFilePath, String rangeFilePath) throws IOException { BufferedReader modelFile = new BufferedReader(new InputStreamReader(new FileInputStream(modelFilePath), "UTF-8")); BufferedReader rangeFile = null; if (range...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private BxDocument getDocumentFromZip(String filename) throws TransformationException, IOException { TrueVizToBxDocumentReader tvReader = new TrueVizToBxDocumentReader(); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries...
#fixed code private BxDocument getDocumentFromZip(String filename) throws TransformationException, IOException { TrueVizToBxDocumentReader tvReader = new TrueVizToBxDocumentReader(); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMo...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(String[] args) throws AnalysisException, TransformationException, IOException { // args[0] path to xml directory if(args.length != 1) { System.err.println("Source directory needed!"); System.exit(1); } InputStreamReader modelISR = new ...
#fixed code public static void main(String[] args) throws AnalysisException, TransformationException, IOException { // args[0] path to xml directory if(args.length != 1) { System.err.println("Source directory needed!"); System.exit(1); } SVMInitialZoneClassifier classifier ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static String getFileSha1(File file) { if (!file.isFile()) { return null; } MessageDigest digest = null; FileInputStream in = null; byte buffer[] = new byte[8192]; int len; try { dige...
#fixed code public static String getFileSha1(File file) { if (!file.isFile()) { return null; } MessageDigest digest = null; FileInputStream in = null; byte[] buffer = new byte[8192]; int len; try { digest = M...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void writeToXml() throws Exception { // 排版缩进的格式 OutputFormat format = OutputFormat.createPrettyPrint(); // 设置编码 format.setEncoding("UTF-8"); // 创建XMLWriter对象,指定了写出文件及编码格式 XMLWriter writer = null; writer = ne...
#fixed code public void writeToXml() throws Exception { // 排版缩进的格式 OutputFormat format = OutputFormat.createPrettyPrint(); // 设置编码 format.setEncoding("UTF-8"); // 创建XMLWriter对象,指定了写出文件及编码格式 XMLWriter writer = null; writer = new XMLW...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void clearDirectiory(String dir) { File dirFile = new File(dir); for (File file : dirFile.listFiles()) { file.delete(); } } #location 3 #vulnerability type N...
#fixed code public static void clearDirectiory(String dir) { File dirFile = new File(dir); for (File file : Objects.requireNonNull(dirFile.listFiles())) { file.delete(); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static String getFileMD5(File file) { if (!file.isFile()) { return null; } MessageDigest digest = null; FileInputStream in = null; byte buffer[] = new byte[8192]; int len; try { diges...
#fixed code public static String getFileMD5(File file) { if (!file.isFile()) { return null; } MessageDigest digest = null; FileInputStream in = null; byte[] buffer = new byte[8192]; int len; try { digest = Me...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code <T extends GHMetaExamples.GHMetaExample> GHMetaExamples.GHMetaExample getMetaExample(Class<T> clazz) throws IOException { return retrieve().to("/meta", clazz); } #location 3 #vulnerability...
#fixed code GitHub(String apiUrl, String login, String oauthAccessToken, String jwtToken, String password, HttpConnector connector, RateLimitHandler rateLimitHandler, AbuseLimitHandler abuseLimitHandler) throws IOException { if (apiUrl.endsWith("/")) ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override protected String getApiRoute() { if (owner == null) { // Issues returned from search to do not have an owner. Attempt to use url. return StringUtils.prependIfMissing(getUrl().toString().replace(root.getApiUrl(), ""), "/"); ...
#fixed code @Override protected String getApiRoute() { if (owner == null) { // Issues returned from search to do not have an owner. Attempt to use url. final URL url = Objects.requireNonNull(getUrl(), "Missing instance URL!"); return String...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public <T> T to(URL url, Class<T> type) throws IOException { HttpURLConnection uc = (HttpURLConnection) url.openConnection(); uc.setDoOutput(true); uc.setRequestProperty("Content-type","application/x-www-form-urlencoded"); uc.setRequestM...
#fixed code public <T> T to(URL url, Class<T> type) throws IOException { HttpURLConnection uc = (HttpURLConnection) url.openConnection(); uc.setDoOutput(true); uc.setRequestProperty("Content-type","application/x-www-form-urlencoded"); uc.setRequestMethod(...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected String getIssuesApiRoute() { if (owner == null) { // Issues returned from search to do not have an owner. Attempt to use url. return StringUtils.prependIfMissing(getUrl().toString().replace(root.getApiUrl(), ""), "/"); }...
#fixed code protected String getIssuesApiRoute() { if (owner == null) { // Issues returned from search to do not have an owner. Attempt to use url. final URL url = Objects.requireNonNull(getUrl(), "Missing instance URL!"); return StringUtils.pr...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code static PagedIterable<GHDiscussion> readAll(GHTeam team) throws IOException { return team.root.createRequest() .setRawUrlPath(team.getUrl().toString() + "/discussions") .toIterable(GHDiscussion[].class, item -> item.wrapUp(team)); ...
#fixed code static PagedIterable<GHDiscussion> readAll(GHTeam team) throws IOException { return team.root.createRequest() .setRawUrlPath(getRawUrlPath(team, null)) .toIterable(GHDiscussion[].class, item -> item.wrapUp(team)); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code static GHDiscussion read(GHTeam team, long discussionNumber) throws IOException { return team.root.createRequest() .setRawUrlPath(team.getUrl().toString() + "/discussions/" + discussionNumber) .fetch(GHDiscussion.class) ...
#fixed code static GHDiscussion read(GHTeam team, long discussionNumber) throws IOException { return team.root.createRequest() .setRawUrlPath(getRawUrlPath(team, discussionNumber)) .fetch(GHDiscussion.class) .wrapUp(team); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void delete() throws IOException { team.root.createRequest() .method("DELETE") .setRawUrlPath(team.getUrl().toString() + "/discussions/" + number) .send(); } #location 4 ...
#fixed code public void delete() throws IOException { team.root.createRequest().method("DELETE").setRawUrlPath(getRawUrlPath(team, number)).send(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public <T> T to(URL url, Class<T> type) throws IOException { HttpURLConnection uc = (HttpURLConnection) url.openConnection(); uc.setDoOutput(true); uc.setRequestProperty("Content-type","application/x-www-form-urlencoded"); uc.setRequestM...
#fixed code public <T> T to(URL url, Class<T> type) throws IOException { HttpURLConnection uc = (HttpURLConnection) url.openConnection(); uc.setDoOutput(true); uc.setRequestProperty("Content-type","application/x-www-form-urlencoded"); uc.setRequestMethod(...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testWindowPeer() throws Exception { if (Platform.isMacOSX() || System.getProperty("java.version)").matches("1\\.6\\..*")) { // Oracle Java and jawt: it's complicated. // See http://forum.lwjgl.org/index.php?topic=4326.0 // O...
#fixed code @Test public void testWindowPeer() throws Exception { if (Platform.isMacOSX() || System.getProperty("java.version").matches("1\\.6\\..*")) { // Oracle Java and jawt: it's complicated. // See http://forum.lwjgl.org/index.php?topic=4326.0 // OpenJDK ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private HttpClient getHttpClient(PrintStream logger) { HttpClient client = null; boolean ignoreUnverifiedSSL = ignoreUnverifiedSSLPeer; String url = stashServerBaseUrl; DescriptorImpl descriptor = getDescriptor(); if ("".equals(url) || url...
#fixed code private HttpClient getHttpClient(PrintStream logger) throws Exception { boolean ignoreUnverifiedSSL = ignoreUnverifiedSSLPeer; String stashServer = stashServerBaseUrl; DescriptorImpl descriptor = getDescriptor(); if ("".equals(stashServer) || stas...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(String[] args) { AppUtil appUtil = new AppUtil(); AService service = (AService) appUtil.getComponentInstance("aService"); AggregateRootA aggregateRootA = service.getAggregateRootA("11"); DomainMessage res = service.commandA("11", aggregateRo...
#fixed code public static void main(String[] args) { AppUtil appUtil = new AppUtil(); AService service = (AService) appUtil.getComponentInstance("aService"); AggregateRootA aggregateRootA = service.getAggregateRootA("11"); DomainMessage res = service.commandA("11", aggregateRootA, 1...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public boolean doExists(String name, Locale locale, String path) throws Exception { return file != null && file.exists() && new ZipFile(file).getEntry(name) != null; } #location 2 #vulnerability type RESOURCE_LEA...
#fixed code public boolean doExists(String name, Locale locale, String path) throws Exception { if (file != null && file.exists()) { ZipFile zipFile = new ZipFile(file); try { return zipFile.getEntry(name) != null; } finally { zipFile.close(); } } return false; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public long getLastModified() { try { JarFile zipFile = new JarFile(file); return zipFile.getEntry(getName()).getTime(); } catch (Throwable e) { return super.getLastModified(); } } #location 4 #vulne...
#fixed code public long getLastModified() { try { JarFile jarFile = new JarFile(file); return jarFile.getEntry(getName()).getTime(); } catch (Throwable e) { return super.getLastModified(); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public Template extend(String name, Locale locale, String encoding) throws IOException, ParseException { if (name == null || name.length() == 0) { throw new IllegalArgumentException("include template name == null"); } String macro = null...
#fixed code public Template extend(String name, Locale locale, String encoding) throws IOException, ParseException { if (name == null || name.length() == 0) { throw new IllegalArgumentException("include template name == null"); } String macro = null; in...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public Template parse(String name, String encoding) throws IOException, ParseException { if (name == null || name.length() == 0) { throw new IllegalArgumentException("include template name == null"); } String macro = null; int i = n...
#fixed code public Template parse(String name, String encoding) throws IOException, ParseException { if (name == null || name.length() == 0) { throw new IllegalArgumentException("include template name == null"); } String macro = null; int i = name.in...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public boolean doExists(String name, Locale locale, String path) throws Exception { return file != null && file.exists() && new JarFile(file).getEntry(name) != null; } #location 2 #vulnerability type RESOURCE_LEA...
#fixed code public boolean doExists(String name, Locale locale, String path) throws Exception { if (file != null && file.exists()) { JarFile jarFile = new JarFile(file); try { return jarFile.getEntry(name) != null; } finally { jarFile.close(); } } return false; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public Template include(String name, Locale locale, String encoding) throws IOException, ParseException { if (name == null || name.length() == 0) { throw new IllegalArgumentException("include template name == null"); } String macro = ...
#fixed code public Template include(String name, Locale locale, String encoding) throws IOException, ParseException { if (name == null || name.length() == 0) { throw new IllegalArgumentException("include template name == null"); } String macro = null; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static Object decodeToObject( String encodedObject, int options, final ClassLoader loader ) throws java.io.IOException, java.lang.ClassNotFoundException { // Decode and gunzip if necessary byte[] objBytes = decode( encodedObject,...
#fixed code public static Object decodeToObject( String encodedObject, int options, final ClassLoader loader ) throws java.io.IOException, java.lang.ClassNotFoundException { // Decode and gunzip if necessary byte[] objBytes = decode( encodedObject, optio...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testException() throws Exception { boolean profile = "true".equals(System.getProperty("profile")); if (! profile) System.out.println("========httl-exception.properties========"); Engine engine = Engine.getEngine("httl-exception.properties"); S...
#fixed code @Test public void testException() throws Exception { boolean profile = "true".equals(System.getProperty("profile")); Engine engine = Engine.getEngine("httl-exception.properties"); String dir = engine.getProperty("template.directory", ""); if (dir.length() > 0 && dir.sta...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public long getLength() { try { JarFile jarFile = new JarFile(file); return jarFile.getEntry(getName()).getSize(); } catch (IOException e) { return super.getLength(); } } #location 4 #vulnerability t...
#fixed code public long getLength() { try { JarFile jarFile = new JarFile(file); try { return jarFile.getEntry(getName()).getSize(); } finally { jarFile.close(); } } catch (IOException e) { return super.getLength(); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void setServletContext(ServletContext servletContext) { if (servletContext == null) { return; } if (ServletLoader.getServletContext() == null) { ServletLoader.setServletContext(servletContext); } if (ENGINE == null) { synchronized (WebEngin...
#fixed code public static void setServletContext(ServletContext servletContext) { if (servletContext == null) { return; } if (ServletLoader.getServletContext() == null) { ServletLoader.setServletContext(servletContext); } if (ENGINE == null) { synchronized (WebEngine.clas...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static String encodeObject( java.io.Serializable serializableObject, int options ) throws java.io.IOException { if( serializableObject == null ){ throw new NullPointerException( "Cannot serialize a null object." ); } // end if: ...
#fixed code public static String encodeObject( java.io.Serializable serializableObject, int options ) throws java.io.IOException { if( serializableObject == null ){ throw new NullPointerException( "Cannot serialize a null object." ); } // end if: null ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private static String getRefValue(Properties result, String v) { if (v != null) { while (v.startsWith(REF)) { String ref = v.substring(1); v = result.getProperty(ref); if (v == null) { v = System.getProperty(ref); } } } return v == null ? "...
#fixed code private static String getRefValue(Properties result, String v) { while (v != null && v.startsWith(REF)) { String ref = v.substring(1); v = result.getProperty(ref); if (v == null) { v = System.getProperty(ref); } } return v == null ? "" : v; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public long getLength() { try { ZipFile zipFile = new ZipFile(file); return zipFile.getEntry(getName()).getSize(); } catch (IOException e) { return super.getLength(); } } #location 4 #vulnerability t...
#fixed code public long getLength() { try { ZipFile zipFile = new ZipFile(file); try { return zipFile.getEntry(getName()).getSize(); } finally { zipFile.close(); } } catch (IOException e) { return super.getLength(); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void setServletContext(ServletContext servletContext) { if (servletContext == null) { return; } if (ServletLoader.getServletContext() == null) { ServletLoader.setServletContext(servletContext); } if (ENGINE == null) { synchronized (WebEngin...
#fixed code public static void setServletContext(ServletContext servletContext) { if (servletContext == null) { return; } if (ServletLoader.getServletContext() == null) { ServletLoader.setServletContext(servletContext); } if (ENGINE == null) { synchronized (WebEngine.clas...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static byte[] decode( String s, int options ) throws java.io.IOException { if( s == null ){ throw new NullPointerException( "Input string was null." ); } // end if byte[] bytes; try { byt...
#fixed code public static byte[] decode( String s, int options ) throws java.io.IOException { if( s == null ){ throw new NullPointerException( "Input string was null." ); } // end if byte[] bytes; try { bytes = s...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public boolean doExists(String name, Locale locale, String path) throws Exception { InputStream in = new URL(path).openStream(); try { return in != null; } finally { in.close(); } } #location 6 #vulne...
#fixed code public boolean doExists(String name, Locale locale, String path) throws Exception { InputStream in = new URL(path).openStream(); try { return in != null; } finally { if (in != null) in.close(); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void init() { defaultFilterVariable = "$" + filterVariable; defaultFormatterVariable = "$" + formatterVariable; if (importVariables != null && importVariables.length > 0) { this.importTypes = new HashMap<String, Class<?>>(); for (String var : importVaria...
#fixed code public void init() { defaultFilterVariable = "$" + filterVariable; defaultFormatterVariable = "$" + formatterVariable; if (importVariables != null && importVariables.length > 0) { this.importTypes = new HashMap<String, Class<?>>(); for (String var : importVariables) ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static Object parseXbean(String xml) { if (xml == null) { return null; } ByteArrayInputStream bi = new ByteArrayInputStream(xml.getBytes()); XMLDecoder xd = new XMLDecoder(bi); return xd.readObject(); } #location 7 ...
#fixed code public static Object parseXbean(String xml) { if (xml == null) { return null; } ByteArrayInputStream bi = new ByteArrayInputStream(xml.getBytes()); XMLDecoder xd = new XMLDecoder(bi); try { return xd.readObject(); } finally { xd.close(); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static byte[] encodeBytesToBytes( byte[] source, int off, int len, int options ) throws java.io.IOException { if( source == null ){ throw new NullPointerException( "Cannot serialize a null array." ); } // end if: null if( o...
#fixed code public static byte[] encodeBytesToBytes( byte[] source, int off, int len, int options ) throws java.io.IOException { if( source == null ){ throw new NullPointerException( "Cannot serialize a null array." ); } // end if: null if( off < 0...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void init() { if (importVariables != null && importVariables.length > 0) { this.importTypes = new HashMap<String, Class<?>>(); for (String var : importVariables) { int i = var.lastIndexOf(' '); if (i < 0) { throw new IllegalArgumentException("Il...
#fixed code public void init() { if (importVariables != null && importVariables.length > 0) { this.importTypes = new HashMap<String, Class<?>>(); for (String var : importVariables) { int i = var.lastIndexOf(' '); if (i < 0) { throw new IllegalArgumentException("Illegal ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public InputStream getInputStream() throws IOException { // 注:JarFile与File的设计是不一样的,File相当于C#的FileInfo,只持有信息, // 而JarFile构造时即打开流,所以每次读取数据时,重新new新的实例,而不作为属性字段持有。 JarFile zipFile = new JarFile(file); return zipFile.getInputStream(zipFile.getEntry(getName())); } ...
#fixed code public InputStream getInputStream() throws IOException { // 注:JarFile与File的设计是不一样的,File相当于C#的FileInfo,只持有信息, // 而JarFile构造时即打开流,所以每次读取数据时,重新new新的实例,而不作为属性字段持有。 JarFile jarFile = new JarFile(file); return jarFile.getInputStream(jarFile.getEntry(getName())); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testNoProcessorWroManagerFactory() throws IOException { final WroManagerFactory factory = new ServletContextAwareWroManagerFactory(); manager = factory.getInstance(); manager.setModelFactory(getValidModelFactory()); final HttpServletReq...
#fixed code @Test public void testNoProcessorWroManagerFactory() throws IOException { final WroManagerFactory factory = new ServletContextAwareWroManagerFactory(); manager = factory.getInstance(); manager.setModelFactory(getValidModelFactory()); final HttpServletRequest r...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void process(final Resource resource, final Reader reader, final Writer writer) throws IOException { try { System.out.println("BOM:"); // using ReaderInputStream instead of ByteArrayInputStream, cause processing to freeze final InputStre...
#fixed code public void process(final Resource resource, final Reader reader, final Writer writer) throws IOException { try { // using ReaderInputStream instead of ByteArrayInputStream, cause processing to freeze final String encoding = Context.get().getConfig().getEn...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void destroy() { //kill running threads executorService.shutdownNow(); } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code public void destroy() { //kill running threads scheduler.shutdownNow(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws IOException, ServletException { final HttpServletRequest request = (HttpServletRequest) req; final HttpServletResponse response = (HttpServletResponse) ...
#fixed code public void doFilter(final ServletRequest req, final ServletResponse res, final FilterChain chain) throws IOException, ServletException { final HttpServletRequest request = (HttpServletRequest) req; final HttpServletResponse response = (HttpServletResponse) res; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testNoProcessorWroManagerFactory() throws IOException { final WroManagerFactory factory = new ServletContextAwareWroManagerFactory(); manager = factory.getInstance(); manager.setModelFactory(getValidModelFactory()); final HttpServletReq...
#fixed code @Test public void testNoProcessorWroManagerFactory() throws IOException { final WroManagerFactory factory = new ServletContextAwareWroManagerFactory(); manager = factory.getInstance(); manager.setModelFactory(getValidModelFactory()); final HttpServletRequest r...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void onRuntimeException(final RuntimeException e, final HttpServletResponse response, final FilterChain chain) { LOG.debug("RuntimeException occured", e); try { LOG.debug("Cannot process. Proceeding with chain execution."); final OutputSt...
#fixed code protected void onRuntimeException(final RuntimeException e, final HttpServletResponse response, final FilterChain chain) { LOG.debug("RuntimeException occured", e); try { LOG.debug("Cannot process. Proceeding with chain execution."); chain.doFilter(Conte...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private InputStream locateStreamFromJar(final String uri, final File jarPath) throws IOException { LOG.debug("\t\tLocating stream from jar"); String classPath = FilenameUtils.getPath(uri); final String wildcard = FilenameUtils.getName(uri); if (...
#fixed code private InputStream locateStreamFromJar(final String uri, final File jarPath) throws IOException { LOG.debug("\t\tLocating stream from jar"); String classPath = FilenameUtils.getPath(uri); final String wildcard = FilenameUtils.getName(uri); if (classPath....
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void onRuntimeException(final RuntimeException e, final HttpServletResponse response, final FilterChain chain) { LOG.debug("RuntimeException occured", e); try { LOG.debug("Cannot process. Proceeding with chain execution."); final OutputSt...
#fixed code protected void onRuntimeException(final RuntimeException e, final HttpServletResponse response, final FilterChain chain) { LOG.debug("RuntimeException occured", e); try { LOG.debug("Cannot process. Proceeding with chain execution."); chain.doFilter(Conte...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void process(final Reader reader, final Writer writer) throws IOException { final StopWatch watch = new StopWatch(); watch.start("pack"); final InputStream is = new ByteArrayInputStream(IOUtils.toByteArray(reader)); try { final JavaScriptC...
#fixed code public void process(final Reader reader, final Writer writer) throws IOException { final StopWatch watch = new StopWatch(); watch.start("pack"); final String content = IOUtils.toString(reader); try { final JavaScriptCompressor compressor = new JavaScri...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public InputStream getInputStream(final HttpServletRequest request, final HttpServletResponse response, final String location) throws IOException { Validate.notNull(request); Validate.notNull(response); // where to write the bytes of the stream fin...
#fixed code public InputStream getInputStream(final HttpServletRequest request, final HttpServletResponse response, final String location) throws IOException { Validate.notNull(request); Validate.notNull(response); // where to write the bytes of the stream final Byt...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void onModelPeriodChanged() { //force scheduler to reload initScheduler(); } #location 3 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code public void onModelPeriodChanged() { //force scheduler to reload model = null; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public String getScalarValue(String key) throws ConfiguratorException { return get(key).asScalar().getValue(); } #location 2 #vulnerability type NULL_DEREFERENCE
#fixed code public String getScalarValue(String key) throws ConfiguratorException { return remove(key).asScalar().getValue(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Object configure(Object c) throws Exception { final ExtensionList list = Jenkins.getInstance().getExtensionList(target); if (list.size() != 1) { throw new IllegalStateException(); } final Object o = list.g...
#fixed code @Override public Object configure(Object c) throws Exception { final ExtensionList list = Jenkins.getInstance().getExtensionList(target); if (list.size() != 1) { throw new IllegalStateException(); } final Object o = list.get(0);...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Object configure(Object c) throws Exception { Map config = c instanceof Map ? (Map) c : Collections.EMPTY_MAP; final Constructor constructor = getDataBoundConstructor(target); if (constructor == null) { throw ne...
#fixed code @Override public Object configure(Object c) throws Exception { Map config = c instanceof Map ? (Map) c : Collections.EMPTY_MAP; final Constructor constructor = getDataBoundConstructor(target); if (constructor == null) { throw new Ille...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void configure(Map config, T instance) throws Exception { final Set<Attribute> attributes = describe(); for (Attribute attribute : attributes) { final String name = attribute.getName(); final Object sub = removeIgnoreCa...
#fixed code protected void configure(Map config, T instance) throws Exception { final Set<Attribute> attributes = describe(); for (Attribute attribute : attributes) { final String name = attribute.getName(); final Object sub = removeIgnoreCase(con...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Nonnull private static RoleMap retrieveRoleMap(@Nonnull CNode config, @Nonnull String name, Configurator<RoleDefinition> configurator) throws ConfiguratorException { Mapping map = config.asMapping(); final Sequence c = map.get(name).asSequence(); ...
#fixed code @Nonnull private static RoleMap retrieveRoleMap(@Nonnull CNode config, @Nonnull String name, Configurator<RoleDefinition> configurator) throws ConfiguratorException { Mapping map = config.asMapping(); final CNode c = map.get(name); TreeMap<Role, S...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Describable configure(Object config) throws Exception { String shortname; Object subconfig = null; if (config instanceof String) { shortname = (String) config; } else if (config instanceof Map) { ...
#fixed code @Override public Describable configure(Object config) throws Exception { String shortname; Object subconfig = null; if (config instanceof String) { shortname = (String) config; } else if (config instanceof Map) { Map...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @CheckForNull @Override public CNode describe(T instance) throws Exception { // Here we assume a correctly designed DataBound Object will have required attributes set by DataBoundConstructor // and all others using DataBoundSetters. So construct...
#fixed code @CheckForNull @Override public CNode describe(T instance) throws Exception { // Here we assume a correctly designed DataBound Object will have required attributes set by DataBoundConstructor // and all others using DataBoundSetters. So constructor par...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Nonnull @Override public T configure(CNode c, ConfigurationContext context) throws ConfiguratorException { final Mapping mapping = (c != null ? c.asMapping() : Mapping.EMPTY); final T instance = instance(mapping, context); if (instance i...
#fixed code @Nonnull @Override public T configure(CNode c, ConfigurationContext context) throws ConfiguratorException { final Mapping mapping = (c != null ? c.asMapping() : Mapping.EMPTY); final T instance = instance(mapping, context); if (instance instanc...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public ProjectMatrixAuthorizationStrategy configure(Object config) throws Exception { Map map = (Map) config; Collection o = (Collection<?>)map.get("grantedPermissions"); Configurator<GroupPermissionDefinition> permissionConfigurato...
#fixed code @Override public ProjectMatrixAuthorizationStrategy configure(Object config) throws ConfiguratorException { Map map = (Map) config; Collection o = (Collection<?>)map.get("grantedPermissions"); Configurator<GroupPermissionDefinition> permissionConfi...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @POST public FormValidation doCheckNewSource(@QueryParameter String newSource) { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); String normalizedSource = Util.fixEmptyAndTrim(newSource); File file = new File(Util.fixNull(normalize...
#fixed code @POST public FormValidation doCheckNewSource(@QueryParameter String newSource) { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); String normalizedSource = Util.fixEmptyAndTrim(newSource); File file = new File(Util.fixNull(normalizedSourc...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public boolean equals(O o1, O o2) throws Exception { final Object v1 = getValue(o1); final Object v2 = getValue(o2); if (v1 == null && v2 == null) return true; return (v1.equals(v2)); } #location 5 ...
#fixed code public boolean equals(O o1, O o2) throws Exception { final Object v1 = getValue(o1); final Object v2 = getValue(o2); if (v1 == null && v2 == null) return true; return (v1 != null && v1.equals(v2)); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public GlobalMatrixAuthorizationStrategy configure(Object config) throws Exception { Map map = (Map) config; Collection o = (Collection<?>)map.get("grantedPermissions"); Configurator<GroupPermissionDefinition> permissionConfigurator...
#fixed code @Override public GlobalMatrixAuthorizationStrategy configure(Object config) throws ConfiguratorException { Map map = (Map) config; Collection o = (Collection<?>)map.get("grantedPermissions"); Configurator<GroupPermissionDefinition> permissionConfig...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @CheckForNull @Override public CNode describe(T instance) throws Exception { // Here we assume a correctly designed DataBound Object will have required attributes set by DataBoundConstructor // and all others using DataBoundSetters. So construct...
#fixed code @CheckForNull @Override public CNode describe(T instance) throws Exception { // Here we assume a correctly designed DataBound Object will have required attributes set by DataBoundConstructor // and all others using DataBoundSetters. So constructor par...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void configure(Map config, T instance) throws Exception { final Set<Attribute> attributes = describe(); for (Attribute attribute : attributes) { final String name = attribute.getName(); final Object sub = removeIgnoreCa...
#fixed code protected void configure(Map config, T instance) throws Exception { final Set<Attribute> attributes = describe(); for (Attribute attribute : attributes) { final String name = attribute.getName(); final Object sub = removeIgnoreCase(con...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public DLegerEntry get(Long index) { PreConditions.check(index <= legerEndIndex, DLegerException.Code.INDEX_OUT_OF_RANGE, String.format("%d should < %d", index, legerEndIndex), memberState.getLeaderId()); SelectMmapBufferResult indexSbr = i...
#fixed code @Override public DLegerEntry get(Long index) { PreConditions.check(index <= legerEndIndex && index >= legerBeginIndex, DLegerException.Code.INDEX_OUT_OF_RANGE, String.format("%d should between %d-%d", index, legerBeginIndex, legerEndIndex), memberState.getLeaderId...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void recover() { final List<MmapFile> mappedFiles = this.dataFileQueue.getMappedFiles(); if (mappedFiles.isEmpty()) { this.indexFileQueue.updateWherePosition(0); this.indexFileQueue.truncateDirtyFiles(0); return...
#fixed code public void recover() { final List<MmapFile> mappedFiles = this.dataFileQueue.getMappedFiles(); if (mappedFiles.isEmpty()) { this.indexFileQueue.updateWherePosition(0); this.indexFileQueue.truncateDirtyFiles(0); return; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void changeRoleToCandidate(long term) { logger.info("[{}][ChangeRoleToCandidate] from term: {} and currterm: {}", memberState.getSelfId(), term, memberState.currTerm()); memberState.changeToCandidate(term); nextTimeToRequestVote = -1; ...
#fixed code public void changeRoleToCandidate(long term) { logger.info("[{}][ChangeRoleToCandidate] from term: {} and currterm: {}", memberState.getSelfId(), term, memberState.currTerm()); memberState.changeToCandidate(term); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void recover() { final List<MmapFile> mappedFiles = this.dataFileQueue.getMappedFiles(); if (mappedFiles.isEmpty()) { this.indexFileQueue.updateWherePosition(0); this.indexFileQueue.truncateDirtyFiles(0); return...
#fixed code public void recover() { final List<MmapFile> mappedFiles = this.dataFileQueue.getMappedFiles(); if (mappedFiles.isEmpty()) { this.indexFileQueue.updateWherePosition(0); this.indexFileQueue.truncateDirtyFiles(0); return; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public long append(byte[] data, int pos, int len, boolean useBlank) { MmapFile mappedFile = getLastMappedFile(); if (null == mappedFile || mappedFile.isFull()) { mappedFile = getLastMappedFile(0); } if (null == mappedFile) { ...
#fixed code public long append(byte[] data, int pos, int len, boolean useBlank) { if (preAppend(len, useBlank) == -1) { return -1; } MmapFile mappedFile = getLastMappedFile(); long currPosition = mappedFile.getFileFromOffset() + mappedFile.getW...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public CompletableFuture<HeartBeatResponse> handleHeartBeat(HeartBeatRequest request) throws Exception { if (request.getTerm() < memberState.currTerm()) { return CompletableFuture.completedFuture((HeartBeatResponse) new HeartBeatResponse().term(membe...
#fixed code public CompletableFuture<HeartBeatResponse> handleHeartBeat(HeartBeatRequest request) throws Exception { if (request.getTerm() < memberState.currTerm()) { return CompletableFuture.completedFuture((HeartBeatResponse) new HeartBeatResponse().term(memberState...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public long append(byte[] data, int pos, int len, boolean useBlank) { MmapFile mappedFile = getLastMappedFile(); if (null == mappedFile || mappedFile.isFull()) { mappedFile = getLastMappedFile(0); } if (null == mappedFile) { ...
#fixed code public long append(byte[] data, int pos, int len, boolean useBlank) { if (preAppend(len, useBlank) == -1) { return -1; } MmapFile mappedFile = getLastMappedFile(); long currPosition = mappedFile.getFileFromOffset() + mappedFile.getW...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public DLegerEntry get(Long index) { PreConditions.check(index <= legerEndIndex && index >= legerBeginIndex, DLegerException.Code.INDEX_OUT_OF_RANGE, String.format("%d should between %d-%d", index, legerBeginIndex, legerEndIndex), memberState.getLe...
#fixed code @Override public DLegerEntry get(Long index) { PreConditions.check(index <= legerEndIndex && index >= legerBeginIndex, DLegerException.Code.INDEX_OUT_OF_RANGE, String.format("%d should between %d-%d", index, legerBeginIndex, legerEndIndex), memberState.getLeaderId...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testThressServer() throws Exception { String group = UUID.randomUUID().toString(); String peers = "n0-localhost:10012;n1-localhost:10013;n2-localhost:10014"; List<DLegerServer> servers = new ArrayList<>(); servers.ad...
#fixed code @Test public void testThressServer() throws Exception { String group = UUID.randomUUID().toString(); String peers = "n0-localhost:10012;n1-localhost:10013;n2-localhost:10014"; List<DLegerServer> servers = new ArrayList<>(); servers.add(laun...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void recover() { final List<MmapFile> mappedFiles = this.dataFileQueue.getMappedFiles(); if (mappedFiles.isEmpty()) { this.indexFileQueue.updateWherePosition(0); this.indexFileQueue.truncateDirtyFiles(0); return...
#fixed code public void recover() { final List<MmapFile> mappedFiles = this.dataFileQueue.getMappedFiles(); if (mappedFiles.isEmpty()) { this.indexFileQueue.updateWherePosition(0); this.indexFileQueue.truncateDirtyFiles(0); return; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private InputStream buildWrappedInputStream(InputStream downloadInputStream) throws TransformerException, IOException { // Pass the download input stream through a transformer that removes the XML // declaration. Transformer omitXmlDeclarationTransforme...
#fixed code private InputStream buildWrappedInputStream(InputStream downloadInputStream) throws TransformerException, IOException { // Pass the download input stream through a Transformer that removes the XML // declaration. Create a new TransformerFactory and Transformer on...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testMarkNotSupported() throws Exception { byte[] plaintext = getRandomBytes(1); final String password = "Testing1234"; JNCryptor cryptor = new AES256JNCryptor(); byte[] data = cryptor.encryptData(plaintext, password.toCharArray()); ...
#fixed code @Test public void testMarkNotSupported() throws Exception { byte[] plaintext = getRandomBytes(1); final String password = "Testing1234"; JNCryptor cryptor = new AES256JNCryptor(); byte[] data = cryptor.encryptData(plaintext, password.toCharArray()); ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private static String getLine(File file, int line) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(file)); String msg = ""; for (int i = 0; i <= line; i++) msg = reader.readLine(); reader.close(); return msg; } ...
#fixed code private static String getLine(File file, int line) throws IOException { BufferedReader reader = Files.newBufferedReader(file.toPath(), Options.encoding); String msg = ""; for (int i = 0; i <= line; i++) msg = reader.readLine(); reader.close(); return msg...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected static ClassInfo guessPackageAndClass(File lexFile) throws FileNotFoundException, IOException { assert lexFile.isAbsolute() : lexFile; LineNumberReader reader = new LineNumberReader(new FileReader(lexFile)); ClassInfo classInfo = new ClassInfo(); whi...
#fixed code protected static ClassInfo guessPackageAndClass(File lexFile) throws FileNotFoundException, IOException { assert lexFile.isAbsolute() : lexFile; LineNumberReader reader = new LineNumberReader(new FileReader(lexFile)); try { ClassInfo classInfo = ne...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private String getPageContent(URL url) throws IOException { InputStreamReader reader = new InputStreamReader(url.openStream(), "UTF-8"); StringBuilder builder = new StringBuilder(); char[] buf = new char[BUF_SIZE]; int charsRead; while ((charsRead = re...
#fixed code private String getPageContent(URL url) throws IOException { try(InputStreamReader reader = new InputStreamReader(url.openStream(), "UTF-8")) { StringBuilder builder = new StringBuilder(); char[] buf = new char[BUF_SIZE]; int charsRead; while ((charsR...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void runNext() throws TestFailException { // Get first file and remove it from vector InputOutput current = inputOutput.remove(0); // Create List with only first input in List<String> param = new ArrayList<String>(); param.add(current.getName(...
#fixed code public void runNext() throws TestFailException, UnsupportedEncodingException { // Get first file and remove it from vector InputOutput current = inputOutput.remove(0); // Create List with only first input in List<String> param = new ArrayList<String>(); pa...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private byte[] loadJarData(String path, String fileName) { ZipFile zipFile; ZipEntry entry; int size; try { zipFile = new ZipFile(new File(path)); entry = zipFile.getEntry(fileName); if (entry == null) return null; size = (int) ent...
#fixed code private byte[] loadJarData(String path, String fileName) { ZipFile zipFile; ZipEntry entry; int size; try { zipFile = new ZipFile(new File(path)); entry = zipFile.getEntry(fileName); if (entry == null) { zipFile.close(); return...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void findPackageAndClass() throws IOException { // find name of the package and class in jflex source file packageName = null; className = null; LineNumberReader reader = new LineNumberReader(new FileReader(inputFile)); while (className == null || packag...
#fixed code public void findPackageAndClass() throws IOException { // find name of the package and class in jflex source file packageName = null; className = null; LineNumberReader reader = new LineNumberReader(new FileReader(inputFile)); try { while (className =...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private byte[] loadJarData(String path, String fileName) { ZipFile zipFile; ZipEntry entry; int size; try { zipFile = new ZipFile(new File(path)); entry = zipFile.getEntry(fileName); if (entry == null) return null; size = (int) ent...
#fixed code private byte[] loadJarData(String path, String fileName) { ZipFile zipFile; ZipEntry entry; int size; try { zipFile = new ZipFile(new File(path)); entry = zipFile.getEntry(fileName); if (entry == null) { zipFile.close(); return...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void read(String skeletonFilename) throws Exception { ClassLoader loader = UnicodePropertiesSkeleton.class.getClassLoader(); URL url = loader.getResource(skeletonFilename); if (null == url) { throw new Exception("Cannot locate '" + skeletonFilen...
#fixed code public void read(String skeletonFilename) throws Exception { ClassLoader loader = UnicodePropertiesSkeleton.class.getClassLoader(); URL url = loader.getResource(skeletonFilename); if (null == url) { throw new Exception("Cannot locate '" + skeletonFilename ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private InputStream getZipEntryStream(String file, String entryName) { try { ZipFile zip = new ZipFile(new File(file)); ZipEntry entry = zip.getEntry(entryName); if (entry == null) return null; return zip.getInputStream(entry); } catc...
#fixed code private InputStream getZipEntryStream(String file, String entryName) { try (ZipFile zip = new ZipFile(new File(file))) { ZipEntry entry = zip.getEntry(entryName); if (entry == null) return null; return zip.getInputStream(entry); } catch (IOExcept...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private String getPageContent(URL url) throws IOException { InputStreamReader reader = new InputStreamReader(url.openStream(), "UTF-8"); StringBuilder builder = new StringBuilder(); char[] buf = new char[BUF_SIZE]; int charsRead; while ((charsRead = re...
#fixed code private String getPageContent(URL url) throws IOException { try(InputStreamReader reader = new InputStreamReader(url.openStream(), "UTF-8")) { StringBuilder builder = new StringBuilder(); char[] buf = new char[BUF_SIZE]; int charsRead; while ((charsR...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private InputStream getZipEntryStream(String file, String entryName) { try { ZipFile zip = new ZipFile(new File(file)); ZipEntry entry = zip.getEntry(entryName); if (entry == null) return null; return zip.getInputStream(entry); } catc...
#fixed code private InputStream getZipEntryStream(String file, String entryName) { try (ZipFile zip = new ZipFile(new File(file))) { ZipEntry entry = zip.getEntry(entryName); if (entry == null) return null; return zip.getInputStream(entry); } catch (IOExcept...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected static ClassInfo guessPackageAndClass(File lexFile) throws FileNotFoundException, IOException { assert lexFile.isAbsolute() : lexFile; LineNumberReader reader = new LineNumberReader(new FileReader(lexFile)); ClassInfo classInfo = new ClassInfo(); whi...
#fixed code protected static ClassInfo guessPackageAndClass(File lexFile) throws FileNotFoundException, IOException { assert lexFile.isAbsolute() : lexFile; LineNumberReader reader = new LineNumberReader(new FileReader(lexFile)); try { ClassInfo classInfo = ne...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void copyTo(Wire wire) { while (bytes.remaining() > 0) { int code = bytes.readUnsignedByte(); switch (code >> 4) { case NUM0: case NUM1: case NUM2: case ...
#fixed code @Override public void copyTo(Wire wire) { while (bytes.remaining() > 0) { int code = bytes.readUnsignedByte(); switch (code >> 4) { case NUM0: case NUM1: case NUM2: case NUM3: ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public boolean readOne() { for (; ; ) { try (DocumentContext context = in.readingDocument()) { if (!context.isPresent()) return false; if (context.isMetaData()) { StringBuilder ...
#fixed code public boolean readOne() { try (DocumentContext context = in.readingDocument()) { if (!context.isPresent()) return false; if (context.isMetaData()) return readOneMetaData(context); assert context.isD...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void setupOrTeardown(DbUnitTestContext testContext, boolean isSetup, Collection<AnnotationAttributes> annotations) throws Exception { IDatabaseConnection connection = testContext.getConnection(); DatabaseOperation lastOperation = null; for (AnnotationAttri...
#fixed code private void setupOrTeardown(DbUnitTestContext testContext, boolean isSetup, Collection<AnnotationAttributes> annotations) throws Exception { IDatabaseConnection connection = testContext.getConnection(); for (AnnotationAttributes annotation : annotations) { List<IDataS...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public ListenableFuture<IBigQueue> queueReadyForDequeue() { futureLock.lock(); if (dequeueFuture == null || dequeueFuture.isDone() || dequeueFuture.isCancelled()) { dequeueFuture = SettableFuture.create(); } futu...
#fixed code @Override public ListenableFuture<IBigQueue> queueReadyForDequeue() { initializeFutureIfNecessary(); return dequeueFuture; }
Below is the vulnerable code, please generate the patch based on the following information.