input
stringlengths
205
73.3k
output
stringlengths
64
73.2k
instruction
stringclasses
1 value
#vulnerable code public boolean connect(SharingPeer peer) { Socket socket = new Socket(); InetSocketAddress address = new InetSocketAddress(peer.getIp(), peer.getPort()); logger.info("Connecting to " + peer + "..."); try { socket.connect(address, 3*1000); } catch (IOExcep...
#fixed code public boolean connect(SharingPeer peer) { Socket socket = new Socket(); InetSocketAddress address = new InetSocketAddress(peer.getIp(), peer.getPort()); logger.info("Connecting to {}...", peer); try { socket.connect(address, 3*1000); } catch (IOException ioe) ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private static String hashPieces(File source) throws NoSuchAlgorithmException, IOException { MessageDigest md = MessageDigest.getInstance("SHA-1"); FileInputStream fis = new FileInputStream(source); StringBuffer pieces = new StringBuffer(); byte[] data = new byte...
#fixed code private static String hashPieces(File source) throws NoSuchAlgorithmException, IOException { long start = System.nanoTime(); long hashTime = 0L; MessageDigest md = MessageDigest.getInstance("SHA-1"); InputStream is = new BufferedInputStream(new FileInputStream(source)...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public MetadataBuilder addDataSource(@NotNull InputStream dataSource, String path, boolean closeAfterBuild) { sources.add(new Source(dataSource, path, closeAfterBuild)); return this; } #location 2 #vulner...
#fixed code public MetadataBuilder addDataSource(@NotNull InputStream dataSource, String path, boolean closeAfterBuild) { checkHashingResultIsNotSet(); filesPaths.add(path); dataSources.add(new StreamBasedHolderImpl(dataSource, closeAfterBuild)); return this; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void run() { // First, analyze the torrent's local data. try { this.torrent.init(); } catch (ClosedByInterruptException cbie) { logger.warn("Client was interrupted during initialization. " + "Aborting right away."); this.setState(Clien...
#fixed code @Override public void run() { // First, analyze the torrent's local data. try { this.torrent.init(); } catch (ClosedByInterruptException cbie) { logger.warn("Client was interrupted during initialization. " + "Aborting right away."); this.setState(ClientState...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void announce(AnnounceRequestMessage.RequestEvent event, boolean inhibitEvents) throws AnnounceException { logger.info("Announcing{} to tracker with {}U/{}D/{}L bytes...", new Object[] { this.formatAnnounceEvent(event), this.torrent.getUplo...
#fixed code @Override public void announce(AnnounceRequestMessage.RequestEvent event, boolean inhibitEvents) throws AnnounceException { logger.info("Announcing{} to tracker with {}U/{}D/{}L bytes...", new Object[] { this.formatAnnounceEvent(event), this.torrent.getUploaded()...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void canAcceptAndReadData() throws IOException, InterruptedException { final AtomicInteger acceptCount = new AtomicInteger(); final AtomicInteger readCount = new AtomicInteger(); final AtomicInteger connectCount = new AtomicInteger(); final ...
#fixed code @Test public void canAcceptAndReadData() throws IOException, InterruptedException { final AtomicInteger acceptCount = new AtomicInteger(); final AtomicInteger readCount = new AtomicInteger(); final AtomicInteger connectCount = new AtomicInteger(); final Atomic...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void downloadUninterruptibly(final String dotTorrentPath, final String downloadDirPath, final long idleTimeoutSec, final int minSeedersCount, ...
#fixed code public void downloadUninterruptibly(final String dotTorrentPath, final String downloadDirPath, final long idleTimeoutSec, final int minSeedersCount, ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void canAcceptAndReadData() throws IOException, InterruptedException { final AtomicInteger acceptCount = new AtomicInteger(); final AtomicInteger readCount = new AtomicInteger(); final AtomicInteger connectCount = new AtomicInteger(); final ...
#fixed code @Test public void canAcceptAndReadData() throws IOException, InterruptedException { final AtomicInteger acceptCount = new AtomicInteger(); final AtomicInteger readCount = new AtomicInteger(); final AtomicInteger connectCount = new AtomicInteger(); final Atomic...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public long getUploaded() { return this.uploaded; } #location 2 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code public long getUploaded() { return myTorrentStatistic.getUploadedBytes(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private HTTPTrackerMessage sendAnnounce(final URL url) throws AnnounceException { HttpURLConnection conn = null; InputStream in = null; try { conn = (HttpURLConnection)url.openConnection(); conn.setConnectTimeout(10000); conn.setReadTimeout(1...
#fixed code private HTTPTrackerMessage sendAnnounce(final URL url) throws AnnounceException { HttpURLConnection conn = null; InputStream in = null; try { conn = (HttpURLConnection)url.openConnection(); conn.setConnectTimeout(10000); conn.setReadTimeout(10000);...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static SharedTorrent fromFile(File source, File parent, boolean multiThreadHash, boolean seeder, boolean leecher, TorrentStatisticProvider torrentStatisticProvider) throws IOException, NoSuchAlgorithmException { ...
#fixed code public static SharedTorrent fromFile(File source, File parent, boolean multiThreadHash, boolean seeder, boolean leecher, TorrentStatisticProvider torrentStatisticProvider) throws IOException, NoSuchAlgorithmException { byte[]...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public boolean connect(SharingPeer peer) { Socket socket = new Socket(); InetSocketAddress address = new InetSocketAddress(peer.getIp(), peer.getPort()); logger.info("Connecting to " + peer + "..."); try { socket.connect(address, 3*1000); } catch (IOExcep...
#fixed code public boolean connect(SharingPeer peer) { Socket socket = new Socket(); InetSocketAddress address = new InetSocketAddress(peer.getIp(), peer.getPort()); logger.info("Connecting to {}...", peer); try { socket.connect(address, 3*1000); } catch (IOException ioe) ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public long getLeft() { return this.left; } #location 2 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code public long getLeft() { return myTorrentStatistic.getLeftBytes(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static Torrent load(File torrent, File parent, boolean seeder) throws IOException { FileInputStream fis = new FileInputStream(torrent); byte[] data = new byte[(int)torrent.length()]; fis.read(data); fis.close(); return new Torrent(data, parent, seeder); ...
#fixed code public static Torrent load(File torrent, File parent, boolean seeder) throws IOException, NoSuchAlgorithmException { FileInputStream fis = null; try { fis = new FileInputStream(torrent); byte[] data = new byte[(int)torrent.length()]; fis.read(data); return new ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void open() throws IOException { this.partial = new File(this.target.getAbsolutePath() + TorrentByteStorage.PARTIAL_FILE_NAME_SUFFIX); if (this.partial.exists()) { logger.debug("Partial download found at {}. Continuing...", this.partial...
#fixed code public void open() throws IOException { try { myLock.writeLock().lock(); this.partial = new File(this.target.getAbsolutePath() + TorrentByteStorage.PARTIAL_FILE_NAME_SUFFIX); if (this.partial.exists()) { logger.debug("Partial download found at {}....
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void canAcceptAndReadData() throws IOException, InterruptedException { final AtomicInteger acceptCount = new AtomicInteger(); final AtomicInteger readCount = new AtomicInteger(); final AtomicInteger connectCount = new AtomicInteger(); final ...
#fixed code @Test public void canAcceptAndReadData() throws IOException, InterruptedException { final AtomicInteger acceptCount = new AtomicInteger(); final AtomicInteger readCount = new AtomicInteger(); final AtomicInteger connectCount = new AtomicInteger(); final Atomic...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void handleIOException(SharingPeer peer, IOException ioe) { logger.error("I/O error while exchanging data with {}, " + "closing connection with it!", peer, ioe.getMessage()); this.stop(); this.setState(ClientState.ERROR); } ...
#fixed code @Override public void handleIOException(SharingPeer peer, IOException ioe) { logger.warn("I/O error while exchanging data with {}, " + "closing connection with it!", peer, ioe.getMessage()); peer.unbind(true); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private HTTPTrackerMessage sendAnnounce(final URL url) throws AnnounceException { HttpURLConnection conn = null; InputStream in = null; try { conn = (HttpURLConnection)url.openConnection(); conn.setConnectTimeout(10000); conn.setReadTimeout(1...
#fixed code private HTTPTrackerMessage sendAnnounce(final URL url) throws AnnounceException { HttpURLConnection conn = null; InputStream in = null; try { conn = (HttpURLConnection)openConnectionCheckRedirects(url); in = conn.getInputStream(); } catch (IOExceptio...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public synchronized void handleMessage(PeerMessage msg) { // logger.trace("Received msg {} from {}", msg.getType(), this); switch (msg.getType()) { case KEEP_ALIVE: // Nothing to do, we're keeping the connection open anyways. break...
#fixed code @Override public synchronized void handleMessage(PeerMessage msg) { // logger.trace("Received msg {} from {}", msg.getType(), this); switch (msg.getType()) { case KEEP_ALIVE: // Nothing to do, we're keeping the connection open anyways. break; ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public synchronized boolean validate(SharedTorrent torrent, Piece piece) throws IOException { if (this.seeder) { logger.trace("Skipping validation of {} (seeder mode).", this); this.valid = true; return true; } logger.trace("Validating {}...", this); thi...
#fixed code public synchronized boolean validate(SharedTorrent torrent, Piece piece) throws IOException { if (this.seeder) { logger.trace("Skipping validation of {} (seeder mode).", this); this.valid = true; return true; } logger.trace("Validating {}...", this); this.vali...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void start(final InetAddress... bindAddresses) throws IOException { start(bindAddresses, Constants.DEFAULT_ANNOUNCE_INTERVAL_SEC, null); } #location 2 #vulnerability type NULL_DEREFERENCE
#fixed code public void start(final InetAddress... bindAddresses) throws IOException { start(bindAddresses, Constants.DEFAULT_ANNOUNCE_INTERVAL_SEC, null, new SelectorFactoryImpl()); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void corrupted_seeder_repair() throws NoSuchAlgorithmException, IOException, URISyntaxException, InterruptedException { this.tracker.setAcceptForeignTorrents(true); final int pieceSize = 48 * 1024; // lower piece size to reduce disk usage final int num...
#fixed code public void corrupted_seeder_repair() throws NoSuchAlgorithmException, IOException, URISyntaxException, InterruptedException { this.tracker.setAcceptForeignTorrents(true); final int pieceSize = 48 * 1024; // lower piece size to reduce disk usage final int numSeeder...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void open() throws IOException { this.partial = new File(this.target.getAbsolutePath() + TorrentByteStorage.PARTIAL_FILE_NAME_SUFFIX); if (this.partial.exists()) { logger.debug("Partial download found at {}. Continuing...", this.partial...
#fixed code public void open() throws IOException { try { myLock.writeLock().lock(); this.partial = new File(this.target.getAbsolutePath() + TorrentByteStorage.PARTIAL_FILE_NAME_SUFFIX); if (this.partial.exists()) { logger.debug("Partial download found at {}....
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public BitSet getCompletedPieces() { synchronized (this.completedPieces) { return (BitSet)this.completedPieces.clone(); } } #location 2 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code public BitSet getCompletedPieces() { if (!this.isInitialized()) { throw new IllegalStateException("Torrent not yet initialized!"); } synchronized (this.completedPieces) { return (BitSet)this.completedPieces.clone(); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void run() { try { init(); Peer self = client.peersStorage.getSelf(); logger.info("BitTorrent client [{}] started and " + "listening at {}:{}...", new Object[]{ self.getSho...
#fixed code @Override public void run() { try { init(); Peer self = peersStorageFactory.getPeersStorage().getSelf(); logger.info("BitTorrent client [{}] started and " + "listening at {}:{}...", new Object[]{ ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void validatePieceAsync(final SharedTorrent torrent, final Piece piece, String torrentHash, SharingPeer peer) { try { synchronized (piece) { if (piece.isValid()) return; piece.validate(torrent, piece); if (piece.isValid()) { ...
#fixed code private void validatePieceAsync(final SharedTorrent torrent, final Piece piece, String torrentHash, SharingPeer peer) { try { synchronized (piece) { if (piece.isValid()) return; piece.validate(torrent, piece); if (piece.isValid()) { ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void run() { logger.info("Starting announce loop..."); while (!this.stop && !Thread.currentThread().isInterrupted()) { logger.debug("Starting announce for {} torrents", torrents.size()); for (SharedTorrent torrent : this.torrents) ...
#fixed code @Override public void run() { logger.info("Starting announce loop..."); while (!this.stop && !Thread.currentThread().isInterrupted()) { logger.debug("Starting announce for {} torrents", torrents.size()); for (SharedTorrent torrent : this.torrents) { ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void announce(AnnounceRequestMessage.RequestEvent event, boolean inhibitEvents, TorrentInfo torrentInfo) throws AnnounceException { logAnnounceRequest(event, torrentInfo); URL target = null; try { HTTPAnnounceRequestMessage re...
#fixed code public void announce(AnnounceRequestMessage.RequestEvent event, boolean inhibitEvents, TorrentInfo torrentInfo) throws AnnounceException { logAnnounceRequest(event, torrentInfo); URL target = null; try { HTTPAnnounceRequestMessage request ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void corrupted_seeder_repair() throws NoSuchAlgorithmException, IOException, URISyntaxException, InterruptedException { this.tracker.setAcceptForeignTorrents(true); final int pieceSize = 48 * 1024; // lower piece size to reduce disk usage final int num...
#fixed code public void corrupted_seeder_repair() throws NoSuchAlgorithmException, IOException, URISyntaxException, InterruptedException { this.tracker.setAcceptForeignTorrents(true); final int pieceSize = 48 * 1024; // lower piece size to reduce disk usage final int numSeeder...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public MetadataBuilder addFile(@NotNull File source) { sources.add(new Source(source)); return this; } #location 2 #vulnerability type RESOURCE_LEAK
#fixed code public MetadataBuilder addFile(@NotNull File source) { return addFile(source, source.getName()); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void open() throws IOException { this.partial = new File(this.target.getAbsolutePath() + TorrentByteStorage.PARTIAL_FILE_NAME_SUFFIX); if (this.partial.exists()) { logger.debug("Partial download found at {}. Continuing...", this.partial...
#fixed code public void open() throws IOException { try { myLock.writeLock().lock(); this.partial = new File(this.target.getAbsolutePath() + TorrentByteStorage.PARTIAL_FILE_NAME_SUFFIX); if (this.partial.exists()) { logger.debug("Partial download found at {}....
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void canAcceptAndReadData() throws IOException, InterruptedException { final AtomicInteger acceptCount = new AtomicInteger(); final AtomicInteger readCount = new AtomicInteger(); final AtomicInteger connectCount = new AtomicInteger(); final ...
#fixed code @Test public void canAcceptAndReadData() throws IOException, InterruptedException { final AtomicInteger acceptCount = new AtomicInteger(); final AtomicInteger readCount = new AtomicInteger(); final AtomicInteger connectCount = new AtomicInteger(); final Atomic...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void handlePieceCompleted(final SharingPeer peer, Piece piece) throws IOException { final SharedTorrent torrent = peer.getTorrent(); synchronized (torrent) { if (piece.isValid()) { // Make sure the piece is marked as comp...
#fixed code @Override public void handlePieceCompleted(final SharingPeer peer, Piece piece) throws IOException { final SharedTorrent torrent = peer.getTorrent(); final String torrentHash; synchronized (torrent) { torrentHash = torrent.getHexInfoHash(); i...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void handlePieceCompleted(final SharingPeer peer, Piece piece) throws IOException { final SharedTorrent torrent = peer.getTorrent(); final String torrentHash = torrent.getHexInfoHash(); if (piece.isValid()) { // Send a HAVE m...
#fixed code @Override public void handlePieceCompleted(final SharingPeer peer, Piece piece) throws IOException { final SharedTorrent torrent = peer.getTorrent(); final String torrentHash = torrent.getHexInfoHash(); if (piece.isValid()) { // Send a HAVE message...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private List<TorrentFile> parseFiles(Map<String, BEValue> infoTable, boolean torrentContainsManyFiles, String name) throws InvalidBEncodingException { if (!torrentContainsManyFiles) { final BEValue md5Sum = infoTable.get(MD5_SUM); return Collections.single...
#fixed code private List<TorrentFile> parseFiles(Map<String, BEValue> infoTable, boolean torrentContainsManyFiles, String name) throws InvalidBEncodingException { if (!torrentContainsManyFiles) { final BEValue md5Sum = infoTable.get(MD5_SUM); return Collections.singletonLis...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void open() throws IOException { this.partial = new File(this.target.getAbsolutePath() + TorrentByteStorage.PARTIAL_FILE_NAME_SUFFIX); if (this.partial.exists()) { logger.debug("Partial download found at {}. Continuing...", this.partial...
#fixed code public void open() throws IOException { try { myLock.writeLock().lock(); this.partial = new File(this.target.getAbsolutePath() + TorrentByteStorage.PARTIAL_FILE_NAME_SUFFIX); if (this.partial.exists()) { logger.debug("Partial download found at {}....
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void save(File output) throws IOException { FileOutputStream fos = new FileOutputStream(output); fos.write(this.getEncoded()); fos.close(); logger.info("Wrote torrent file {}.", output.getAbsolutePath()); } #location 6 ...
#fixed code public void save(File output) throws IOException { FileOutputStream fos = null; try { fos = new FileOutputStream(output); fos.write(this.getEncoded()); logger.info("Wrote torrent file {}.", output.getAbsolutePath()); } finally { if (fos != null) { fos.close...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void canAcceptAndReadData() throws IOException, InterruptedException { final AtomicInteger acceptCount = new AtomicInteger(); final AtomicInteger readCount = new AtomicInteger(); final AtomicInteger connectCount = new AtomicInteger(); final ...
#fixed code @Test public void canAcceptAndReadData() throws IOException, InterruptedException { final AtomicInteger acceptCount = new AtomicInteger(); final AtomicInteger readCount = new AtomicInteger(); final AtomicInteger connectCount = new AtomicInteger(); final Atomic...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void corrupted_seeder_repair() throws NoSuchAlgorithmException, IOException, URISyntaxException, InterruptedException { this.tracker.setAcceptForeignTorrents(true); final int pieceSize = 48 * 1024; // lower piece size to reduce disk usage final int num...
#fixed code public void corrupted_seeder_repair() throws NoSuchAlgorithmException, IOException, URISyntaxException, InterruptedException { this.tracker.setAcceptForeignTorrents(true); final int pieceSize = 48 * 1024; // lower piece size to reduce disk usage final int numSeeder...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void cleanUp() { for (PeerMessage.RequestMessage request : myRequests) { if (System.currentTimeMillis() - request.getSendTime() > MAX_REQUEST_TIMEOUT){ send(request); request.renew(); } } } ...
#fixed code @Override public void cleanUp() { // temporary ignore until I figure out how to handle this in more robust way. /* for (PeerMessage.RequestMessage request : myRequests) { if (System.currentTimeMillis() - request.getSendTime() > MAX_REQUEST_TIMEOUT){ send...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private HTTPTrackerMessage sendAnnounce(final URL url) throws AnnounceException { HttpURLConnection conn = null; InputStream in = null; try { conn = (HttpURLConnection)url.openConnection(); conn.setConnectTimeout(10000); conn.setReadTimeout(1...
#fixed code private HTTPTrackerMessage sendAnnounce(final URL url) throws AnnounceException { HttpURLConnection conn = null; InputStream in = null; try { conn = (HttpURLConnection)url.openConnection(); conn.setConnectTimeout(10000); conn.setReadTimeout(10000);...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public BitSet getAvailablePieces() { BitSet availablePieces = new BitSet(this.pieces.length); synchronized (this.pieces) { for (Piece piece : this.pieces) { if (piece.available()) { availablePieces.set(piece.getIndex()); } } } return availableP...
#fixed code public BitSet getAvailablePieces() { if (!this.isInitialized()) { throw new IllegalStateException("Torrent not yet initialized!"); } BitSet availablePieces = new BitSet(this.pieces.length); synchronized (this.pieces) { for (Piece piece : this.pieces) { if (pi...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public int write(ByteBuffer buffer, long offset) throws IOException { int requested = buffer.remaining(); if (offset + requested > this.size) { throw new IllegalArgumentException("Invalid storage write request!"); } return this.channel.write(buffer,...
#fixed code @Override public int write(ByteBuffer buffer, long offset) throws IOException { try { myLock.writeLock().lock(); int requested = buffer.remaining(); if (offset + requested > this.size) { throw new IllegalArgumentException("Invalid storage write request!");...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void open() throws IOException { this.partial = new File(this.target.getAbsolutePath() + TorrentByteStorage.PARTIAL_FILE_NAME_SUFFIX); if (this.partial.exists()) { logger.debug("Partial download found at {}. Continuing...", this.partial...
#fixed code public void open() throws IOException { try { myLock.writeLock().lock(); this.partial = new File(this.target.getAbsolutePath() + TorrentByteStorage.PARTIAL_FILE_NAME_SUFFIX); if (this.partial.exists()) { logger.debug("Partial download found at {}....
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private static String hashPieces(File source) throws NoSuchAlgorithmException, IOException { long start = System.nanoTime(); long hashTime = 0L; MessageDigest md = MessageDigest.getInstance("SHA-1"); InputStream is = new BufferedInputStream(new FileInputStream(s...
#fixed code private static String hashPieces(File source) throws NoSuchAlgorithmException, InterruptedException, IOException { ExecutorService executor = Executors.newFixedThreadPool( getHashingThreadsCount()); List<Future<String>> results = new LinkedList<Future<String>>(); byt...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void load_torrent_created_by_utorrent() throws IOException, NoSuchAlgorithmException, URISyntaxException { Torrent t = Torrent.load(new File("src/test/resources/torrents/file1.jar.torrent")); assertEquals(new URI("http://localhost:6969/announce"), t.getAnno...
#fixed code public void load_torrent_created_by_utorrent() throws IOException, NoSuchAlgorithmException, URISyntaxException { Torrent t = Torrent.load(new File("src/test/resources/torrents/file1.jar.torrent")); assertEquals("http://localhost:6969/announce", t.getAnnounceList().get(...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void download_multiple_files() throws IOException, NoSuchAlgorithmException, InterruptedException, URISyntaxException { int numFiles = 50; this.tracker.setAcceptForeignTorrents(true); final File srcDir = tempFiles.createTempDir(); final File downlo...
#fixed code public void download_multiple_files() throws IOException, NoSuchAlgorithmException, InterruptedException, URISyntaxException { int numFiles = 50; this.tracker.setAcceptForeignTorrents(true); final File srcDir = tempFiles.createTempDir(); final File downloadDir ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void process(final String uri, final String hostAddress, RequestHandler requestHandler) throws IOException { // Prepare the response headers. /** * Parse the query parameters into an announce request message. * * We need to rely on our own qu...
#fixed code public void process(final String uri, final String hostAddress, RequestHandler requestHandler) throws IOException { // Prepare the response headers. /** * Parse the query parameters into an announce request message. * * We need to rely on our own query pa...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void downloadUninterruptibly(final String dotTorrentPath, final String downloadDirPath, final long idleTimeoutSec, final int minSeedersCount, ...
#fixed code public void downloadUninterruptibly(final String dotTorrentPath, final String downloadDirPath, final long idleTimeoutSec, final int minSeedersCount, ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void removeTorrent(TorrentHash torrentHash) { logger.info("Stopping seeding " + torrentHash.getHexInfoHash()); final TorrentsPair torrentsPair = torrentsStorage.removeActiveAndAnnounceableTorrent(torrentHash.getHexInfoHash()); SharedTorrent torrent = t...
#fixed code public void removeTorrent(TorrentHash torrentHash) { logger.info("Stopping seeding " + torrentHash.getHexInfoHash()); final TorrentsPair torrentsPair = torrentsStorage.removeActiveAndAnnounceableTorrent(torrentHash.getHexInfoHash()); SharedTorrent torrent = torrent...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void initAndRunWorker() throws IOException { myServerSocketChannel = selector.provider().openServerSocketChannel(); myServerSocketChannel.configureBlocking(false); for (int port = PORT_RANGE_START; port < PORT_RANGE_END; port++) { try { I...
#fixed code public void initAndRunWorker() throws IOException { myServerSocketChannel = selector.provider().openServerSocketChannel(); myServerSocketChannel.configureBlocking(false); for (int port = PORT_RANGE_START; port < PORT_RANGE_END; port++) { try { InetSoc...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void handlePeerDisconnected(SharingPeer peer) { final SharedTorrent peerTorrent = peer.getTorrent(); Peer p = new Peer(peer.getIp(), peer.getPort()); p.setPeerId(peer.getPeerId()); p.setTorrentHash(peer.getHexInfoHash()); PeerUID pee...
#fixed code @Override public void handlePeerDisconnected(SharingPeer peer) { final SharedTorrent peerTorrent = peer.getTorrent(); Peer p = new Peer(peer.getIp(), peer.getPort()); p.setPeerId(peer.getPeerId()); p.setTorrentHash(peer.getHexInfoHash()); PeerUID peerUID =...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public MetadataBuilder addFile(@NotNull File source, @NotNull String path) { if (!source.isFile()) { throw new IllegalArgumentException(source + " is not exist"); } sources.add(new Source(source, path)); return this; } ...
#fixed code public MetadataBuilder addFile(@NotNull File source, @NotNull String path) { if (!source.isFile()) { throw new IllegalArgumentException(source + " is not exist"); } checkHashingResultIsNotSet(); filesPaths.add(path); dataSources.add(new FileSourceHolde...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public int read(ByteBuffer buffer, long offset) throws IOException { int requested = buffer.remaining(); if (offset + requested > this.size) { throw new IllegalArgumentException("Invalid storage read request!"); } int bytes = this.channel.read(buffe...
#fixed code @Override public int read(ByteBuffer buffer, long offset) throws IOException { try { myLock.readLock().lock(); int requested = buffer.remaining(); if (offset + requested > this.size) { throw new IllegalArgumentException("Invalid storage read request!"); ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void unbind(boolean force) { if (!force) { // Cancel all outgoing requests, and send a NOT_INTERESTED message to // the peer. this.cancelPendingRequests(); this.send(PeerMessage.NotInterestedMessage.craft()); } PeerExchange exch...
#fixed code public void unbind(boolean force) { if (!force) { // Cancel all outgoing requests, and send a NOT_INTERESTED message to // the peer. this.cancelPendingRequests(); this.send(PeerMessage.NotInterestedMessage.craft()); } PeerExchange exchangeCo...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void accept() throws IOException, SocketTimeoutException { Socket socket = this.socket.accept(); try { logger.debug("New incoming connection ..."); Handshake hs = this.validateHandshake(socket, null); this.sendHandshake(socket); this.fireNewPeerCon...
#fixed code private void accept() throws IOException, SocketTimeoutException { Socket socket = this.socket.accept(); try { logger.debug("New incoming connection ..."); Handshake hs = this.validateHandshake(socket, null); this.sendHandshake(socket); this.fireNewPeerConnectio...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public DataProcessor processAndGetNext(ByteChannel socketChannel) throws IOException { if (pstrLength == -1) { ByteBuffer len = ByteBuffer.allocate(1); int readBytes = -1; try { readBytes = socketChannel.read(len); } catch (...
#fixed code @Override public DataProcessor processAndGetNext(ByteChannel socketChannel) throws IOException { if (pstrLength == -1) { ByteBuffer len = ByteBuffer.allocate(1); int readBytes = -1; try { readBytes = socketChannel.read(len); } catch (IOExce...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void send(PeerMessage message) throws IllegalStateException { logger.trace("Sending msg {} to {}", message.getType(), this); if (this.isConnected()) { ByteBuffer data = message.getData(); data.rewind(); boolean writeTaskAdded = connectionM...
#fixed code public void send(PeerMessage message) throws IllegalStateException { logger.trace("Sending msg {} to {}", message.getType(), this); if (this.isConnected()) { ByteBuffer data = message.getData(); data.rewind(); connectionManager.offerWrite(new WriteTask...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void init(String fileName) throws IOException { cellList.clear(); BufferedReader reader = FileReadUtil.createLineRead(fileName); String line = reader.readLine(); String[] temps; while (line != null) { temps = S...
#fixed code private void init(String fileName) throws IOException { List<WxImgCreateTemplateCell> list = new CopyOnWriteArrayList<>(); BufferedReader reader = FileReadUtil.createLineRead(fileName); String line = reader.readLine(); String[] temps; w...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public final void send() { if (packet == null) { packet = outqueue.poll(); if (packet == null) { return; } } try { for (;;) { while (packet.writeLength < packet.total...
#fixed code public final void send() { if (packet == null) { packet = outqueue.poll(); if (packet == null) { return; } } try { for (;;) { while (packet.writeLength < packet.totalLength...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public final void send() { if (packet == null) { packet = outqueue.poll(); if (packet == null) { return; } } try { for (;;) { while (packet.writeLength < packet.total...
#fixed code public final void send() { if (packet == null) { packet = outqueue.poll(); if (packet == null) { return; } } try { for (;;) { while (packet.writeLength < packet.totalLength...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public final void send() { if (packet == null) { packet = outqueue.poll(); if (packet == null) { return; } } try { for (;;) { while (packet.writeLength < packet.total...
#fixed code public final void send() { if (packet == null) { packet = outqueue.poll(); if (packet == null) { return; } } try { for (;;) { while (packet.writeLength < packet.totalLength...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private Map<String, String> filterInfo(Map<String, String> info) { HashMap<String, String> newInfo = Maps.newHashMap(info); String limit = newInfo.get(PUSH_PROPERTIES_LIMIT); if (Strings.isNullOrEmpty(limit)) { newInfo.remove(PUSH_P...
#fixed code private Map<String, String> filterInfo(Map<String, String> info) { Map<String, String> newInfo = Maps.newHashMap(info); String limitLine = newInfo.remove(PUSH_PROPERTIES_LIMIT); Set<String> limitKeys = getLimitKeys(limitLine); if (limitKeys.isE...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public T blpopObject(int timeout, String key, Class clazz) { this.setSchema(clazz); Jedis jedis = null; try { List<byte[]> bytes = jedis.blpop(timeout, key.getBytes()); if (bytes == null || bytes.size() == 0) { ...
#fixed code public T blpopObject(int timeout, String key, Class clazz) { this.setSchema(clazz); Jedis jedis = null; try { jedis = jedisPool.getResource(); List<byte[]> bytes = jedis.blpop(timeout, key.getBytes()); if (bytes == n...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testPostMultipleFiles() throws JSONException, URISyntaxException { HttpResponse<JsonNode> response = Unirest.post("http://httpbin.org/post").field("param3", "wot").field("file1", new File(getClass().getResource("/test").toURI())).field("fil...
#fixed code @Test public void testPostMultipleFiles() throws JSONException, URISyntaxException { HttpResponse<JsonNode> response = Unirest.post(MockServer.POST) .field("param3", "wot") .field("file1", new File(getClass().getResource("/test").to...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testCustomUserAgent() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.get("http://httpbin.org/get?name=mark").header("user-agent", "hello-world").asJson(); assertEquals("hello-world", response.getBody().getObject()....
#fixed code @Test public void testCustomUserAgent() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.get(MockServer.GETJSON) .header("user-agent", "hello-world") .asJson(); RequestCapture json = parse(response); ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testAsync() throws JSONException, InterruptedException, ExecutionException { Future<HttpResponse<JsonNode>> future = Unirest.post("http://httpbin.org/post") .header("accept", "application/json") .field("param1", "value1") .field("param2"...
#fixed code @Test public void testAsync() throws JSONException, InterruptedException, ExecutionException { // Future<HttpResponse<JsonNode>> future = Unirest.post("http://httpbin.org/post") // .header("accept", "application/json") // .field("param1", "value1") // .field("param...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testDelete() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.delete("http://httpbin.org/delete").asJson(); assertEquals(200, response.getCode()); response = Unirest.delete("http://httpbin.org/delete").field("n...
#fixed code @Test public void testDelete() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.delete("http://httpbin.org/delete").asJson(); assertEquals(200, response.getCode()); //TODO: Uncomment when https://github.com/Mashape/unirest-java/issues/...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static <T> MashapeResponse<T> doRequest (Class<T> clazz, HttpMethod httpMethod, String url, Map<String, Object> parameters, ContentType contentType, ResponseType responseType, List<Authentication> authenticationHandlers) { if (authenticationHandlers == null) authe...
#fixed code public static <T> MashapeResponse<T> doRequest (Class<T> clazz, HttpMethod httpMethod, String url, Map<String, Object> parameters, ContentType contentType, ResponseType responseType, List<Authentication> authenticationHandlers) { if (authenticationHandlers == null) authenticat...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testPostRawBody() { String sourceString = "'\"@こんにけは-test-123-" + Math.random(); byte[] sentBytes = sourceString.getBytes(); HttpResponse<JsonNode> response = Unirest.post("http://httpbin.org/post").body(sentBytes).asJson(); assertEquals(source...
#fixed code @Test public void testPostRawBody() { String sourceString = "'\"@こんにけは-test-123-" + Math.random(); byte[] sentBytes = sourceString.getBytes(); HttpResponse<JsonNode> response = Unirest.post(MockServer.POST) .body(sentBytes) .asJson(); RequestCapture json = par...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testMultipartAsync() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, UnirestException { Future<HttpResponse<JsonNode>> future = Unirest.post("http://httpbin.org/post") .field("file", new File(getClass().getResource...
#fixed code @Test public void testMultipartAsync() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, UnirestException { Unirest.post("http://httpbin.org/post") .field("name", "Mark") .field("file", new File(getClass().getResource("/test").toURI())).a...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testMultipartInputStreamContentType() throws JSONException, URISyntaxException, FileNotFoundException { FileInputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); MultipartBody request = Unirest.post(MockSer...
#fixed code @Test public void testMultipartInputStreamContentType() throws JSONException, URISyntaxException, FileNotFoundException { FileInputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toURI())); MultipartBody request = Unirest.post(MockServer.HO...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testDeleteBody() throws JSONException, UnirestException { String body = "{\"jsonString\":{\"members\":\"members1\"}}"; HttpResponse<JsonNode> response = Unirest.delete("http://httpbin.org/delete").body(body).asJson(); assertEquals(200, response.get...
#fixed code @Test public void testDeleteBody() throws JSONException, UnirestException { String body = "{\"jsonString\":{\"members\":\"members1\"}}"; HttpResponse<JsonNode> response = Unirest.delete(MockServer.DELETE) .body(body) .asJson(); assertEquals(200, response.getStatu...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testGetMultiple() throws JSONException, UnirestException { for (int i = 1; i <= 20; i++) { HttpResponse<JsonNode> response = Unirest.get("http://httpbin.org/get?try=" + i).asJson(); assertEquals(response.getBody().getObject().getJSONObject("args"...
#fixed code @Test public void testGetMultiple() throws JSONException, UnirestException { for (int i = 1; i <= 20; i++) { HttpResponse<JsonNode> response = Unirest.get(MockServer.GETJSON + "?try=" + i).asJson(); parse(response).assertQuery("try", String.valueOf(i)); } ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testPostCollection() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.post("http://httpbin.org/post").field("name", Arrays.asList("Mark", "Tom")).asJson(); JSONArray names = response.getBody().getO...
#fixed code @Test public void testPostCollection() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.post(MockServer.POST) .field("name", Arrays.asList("Mark", "Tom")) .asJson(); parse(response) ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testGetArray() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.get("http://httpbin.org/get").queryString("name", Arrays.asList("Mark", "Tom")).asJson(); JSONArray names = response.getBody().getObj...
#fixed code @Test public void testGetArray() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.get(MockServer.GET) .queryString("name", Arrays.asList("Mark", "Tom")) .asJson(); parse(response) ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testQueryStringEncoding() throws JSONException, UnirestException { String testKey = "email2=someKey&email"; String testValue = "hello@hello.com"; HttpResponse<JsonNode> response = Unirest.get("http://httpbin.org/get").queryString(testKey, testValue...
#fixed code @Test public void testQueryStringEncoding() throws JSONException, UnirestException { String testKey = "email2=someKey&email"; String testValue = "hello@hello.com"; HttpResponse<JsonNode> response = Unirest.get(MockServer.GETJSON) .queryString(testKey, tes...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testGetUTF8() { HttpResponse<JsonNode> response = Unirest.get("http://httpbin.org/get").queryString("param3", "こんにけは").asJson(); assertEquals(response.getBody().getObject().getJSONObject("args").getString("param3"), "こんにけは"); } ...
#fixed code @Test public void testGetUTF8() { HttpResponse<JsonNode> response = Unirest.get(MockServer.GETJSON) .header("accept", "application/json") .queryString("param3", "こんにけは") .asJson(); FormCapture json = TestUtils.read(response, FormCapture.class); json.assertQue...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testObjectMapperWrite() { Unirest.setObjectMapper(new JacksonObjectMapper()); GetResponse postResponseMock = new GetResponse(); postResponseMock.setUrl("http://httpbin.org/post"); HttpResponse<JsonNode> postRespons...
#fixed code @Test public void testObjectMapperWrite() { Unirest.setObjectMapper(new JacksonObjectMapper()); GetResponse postResponseMock = new GetResponse(); postResponseMock.setUrl(MockServer.POST); HttpResponse<JsonNode> postResponse = Unirest.post...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testGetQuerystringArray() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.get("http://httpbin.org/get").queryString("name", "Mark").queryString("name", "Tom").asJson(); JSONArray names = response....
#fixed code @Test public void testGetQuerystringArray() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.get(MockServer.GET) .queryString("name", "Mark") .queryString("name", "Tom") .asJson(); ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testGetFields() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.get("http://httpbin.org/get").queryString("name", "mark").queryString("nick", "thefosk").asJson(); assertEquals(response.getBody().getObject().getJSONO...
#fixed code @Test public void testGetFields() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.get(MockServer.GETJSON) .queryString("name", "mark") .queryString("nick", "thefosk") .asJson(); Reques...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testDelete() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.delete("http://httpbin.org/delete").asJson(); assertEquals(200, response.getStatus()); response = Unirest.delete("http://httpbin.org/delete").field("na...
#fixed code @Test public void testDelete() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.delete(MockServer.DELETE).asJson(); assertEquals(200, response.getStatus()); response = Unirest.delete(MockServer.DELETE) .field("name", "mark") .fie...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testPostBinaryUTF8() throws URISyntaxException { HttpResponse<JsonNode> response = Unirest.post("http://httpbin.org/post").field("param3", "こんにけは").field("file", new File(getClass().getResource("/test").toURI())).asJson(); assertEquals("This is a te...
#fixed code @Test public void testPostBinaryUTF8() throws URISyntaxException { HttpResponse<JsonNode> response = Unirest.post(MockServer.POST) .header("Accept", ContentType.MULTIPART_FORM_DATA.getMimeType()) .field("param3", "こんにけは") .field("file", new File(getClass().getReso...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testCaseInsensitiveHeaders() { GetRequest request = Unirest.get("http://httpbin.org/headers").header("Name", "Marco"); assertEquals(1, request.getHeaders().size()); assertEquals("Marco", request.getHeaders().get("name").get(...
#fixed code @Test public void testCaseInsensitiveHeaders() { GetRequest request = Unirest.get(MockServer.GET) .header("Name", "Marco"); assertEquals(1, request.getHeaders().size()); assertEquals("Marco", request.getHeaders().get("name").get(0)...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testMultipartInputStreamContentType() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, UnirestException, FileNotFoundException { HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post").field("nam...
#fixed code @Test public void testMultipartInputStreamContentType() throws JSONException, InterruptedException, ExecutionException, URISyntaxException, UnirestException, FileNotFoundException { FileInputStream stream = new FileInputStream(new File(getClass().getResource("/image.jpg").toU...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testAsync() throws JSONException, InterruptedException, ExecutionException { Future<HttpResponse<JsonNode>> future = Unirest.post("http://httpbin.org/post").header("accept", "application/json").field("param1", "value1").field("param2", "bye").asJsonAsy...
#fixed code @Test public void testAsync() throws JSONException, InterruptedException, ExecutionException { Future<HttpResponse<JsonNode>> future = Unirest.post(MockServer.POST) .header("accept", "application/json") .field("param1", "value1") .field("param2", "bye") .asJso...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testGetFields2() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.get("http://httpbin.org/get").queryString("email", "hello@hello.com").asJson(); assertEquals("hello@hello.com", response.getBody().getObject().getJSON...
#fixed code @Test public void testGetFields2() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.get(MockServer.GETJSON) .queryString("email", "hello@hello.com") .asJson(); parse(response).assertQuery("email", "hel...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testPostUTF8() { HttpResponse<JsonNode> response = Unirest.post("http://httpbin.org/post").field("param3", "こんにけは").asJson(); assertEquals(response.getBody().getObject().getJSONObject("form").getString("param3"), "こんにけは"); } ...
#fixed code @Test public void testPostUTF8() { HttpResponse response = Unirest.post(MockServer.POSTJSON) .header("accept", "application/json") .field("param3", "こんにけは") .asJson(); FormCapture json = TestUtils.read(response, FormCapture.class); json.assertQuery("param3", ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testBasicAuth() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.get("http://httpbin.org/headers").basicAuth("user", "test").asJson(); assertEquals("Basic dXNlcjp0ZXN0", response.getBody().getObject().getJSONObject("...
#fixed code @Test public void testBasicAuth() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.get(MockServer.GETJSON) .basicAuth("user", "test") .asJson(); parse(response).assertHeader("Authorization", "Basic dXNlcjp0ZXN0"); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testPostArray() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.post("http://httpbin.org/post").field("name", "Mark").field("name", "Tom").asJson(); JSONArray names = response.getBody().getObject(...
#fixed code @Test public void testPostArray() throws JSONException, UnirestException { HttpResponse<JsonNode> response = Unirest.post(MockServer.POST) .field("name", "Mark") .field("name", "Tom") .asJson(); parse(respon...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testRequests() throws Exception { HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post") .header("accept", "application/json") .field("param1", "value1") .field("param2","bye") ...
#fixed code @Test public void testRequests() throws JSONException { HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post") .header("accept", "application/json") .field("param1", "value1") .field("param2","bye") ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public boolean isStarted() { return client.getState() == CuratorFrameworkState.STARTED; } #location 2 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code public boolean isStarted() { try { lock.lock(); return client.getState() == CuratorFrameworkState.STARTED; } finally { lock.unlock(); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void postEvent(ApplicationType applicationType, ActionType actionType, ProtocolType protocolType, ProtocolMessage message) { if (message.getException() == null) { return; } ProtocolEvent protocolEvent = new ProtocolEven...
#fixed code public static void postEvent(ApplicationType applicationType, ActionType actionType, ProtocolType protocolType, ProtocolMessage message) { if (message.getException() == null) { return; } ProtocolEvent protocolEvent = new ProtocolEvent(appl...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void onEvent(PathChildrenCacheEvent event, InstanceEventType instanceEventType) throws Exception { String childPath = event.getData().getPath(); String applicationJson = childPath.substring(childPath.lastIndexOf("/") + 1); ApplicationEnti...
#fixed code private void onEvent(PathChildrenCacheEvent event, InstanceEventType instanceEventType) throws Exception { String childPath = event.getData().getPath(); String applicationJson = childPath.substring(childPath.lastIndexOf("/") + 1); ApplicationEntity app...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testSourceSinkStartResumeRollingEverySecond() throws Exception { //This is the config that is required to make the VanillaChronicle roll every second final String sourceBasePath = getVanillaTestPath("-source"); final String...
#fixed code @Test public void testSourceSinkStartResumeRollingEverySecond() throws Exception { //This is the config that is required to make the VanillaChronicle roll every second final String sourceBasePath = getVanillaTestPath("-source"); final String sinkB...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testPricePublishing1() throws IOException, InterruptedException { final String basePathSource = getIndexedTestPath("-source"); final String basePathSink = getIndexedTestPath("-sink"); final Chronicle source = new ChronicleS...
#fixed code @Test public void testPricePublishing1() throws IOException, InterruptedException { final String basePathSource = getIndexedTestPath("-source"); final String basePathSink = getIndexedTestPath("-sink"); final Chronicle source = ChronicleQueueBuilde...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testOverTCP() throws IOException, InterruptedException { String baseDir = System.getProperty("java.io.tmpdir"); String srcBasePath = baseDir + "/IPCT.testOverTCP.source"; ChronicleTools.deleteOnExit(srcBasePath); // ...
#fixed code @Test public void testOverTCP() throws IOException, InterruptedException { String baseDir = System.getProperty("java.io.tmpdir"); String srcBasePath = baseDir + "/IPCT.testOverTCP.source"; ChronicleTools.deleteOnExit(srcBasePath); // NOTE: ...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testReplication1() throws IOException { final int RUNS = 100; final String sourceBasePath = getVanillaTestPath("-source"); final String sinkBasePath = getVanillaTestPath("-sink"); final ChronicleSource source = new ...
#fixed code @Test public void testReplication1() throws Exception { final int RUNS = 100; final String sourceBasePath = getVanillaTestPath("-source"); final String sinkBasePath = getVanillaTestPath("-sink"); final ChronicleSource source = new Chronic...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(String... ignored) throws IOException { String basePath = TMP + "/ExampleCacheMain"; ChronicleTools.deleteOnExit(basePath); CachePerfMain map = new CachePerfMain(basePath, 32); long start = System.nanoTime(); ...
#fixed code public static void main(String... ignored) throws IOException { String basePath = TMP + "/ExampleCacheMain"; ChronicleTools.deleteOnExit(basePath); CachePerfMain map = new CachePerfMain(basePath, 64); buildkeylist(keys); long duration; for (int i = 0; i < 2; i++) {...
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testPricePublishing1() throws IOException, InterruptedException { final String basePathSource = getIndexedTestPath("-source"); final String basePathSink = getIndexedTestPath("-sink"); final Chronicle source = new ChronicleS...
#fixed code @Test public void testPricePublishing1() throws IOException, InterruptedException { final String basePathSource = getIndexedTestPath("-source"); final String basePathSink = getIndexedTestPath("-sink"); final Chronicle source = ChronicleQueueBuilde...
Below is the vulnerable code, please generate the patch based on the following information.