auphong2707/dl4se-code-review-dataset huggingface dataset:
Source:
public SnapshotImpl saveSnapshot(String namespace, String workspaceId, String machineId) throws ServerException, ConflictException, NotFoundException { EnvironmentHolder environmentHolder; try (StripedLocks.ReadLock lock = stripedLocks.acquireReadLock(workspaceId)) { environmentHolder = environments.get(workspaceId); if (environmentHolder == null || environmentHolder.status != EnvStatus.RUNNING) { throw new ConflictException(format("Environment '%s' is not running", workspaceId)); } } for (Instance machine : environmentHolder.machines) { if (machine.getId().equals(machineId)) { final SnapshotImpl snapshot = SnapshotImpl.builder() .generateId() .setType(machine.getConfig().getType()) .setNamespace(namespace) .setWorkspaceId(machine.getWorkspaceId()) .setDescription(machine.getEnvName()) .setDev(machine.getConfig().isDev()) .setEnvName(machine.getEnvName()) .setMachineName(machine.getConfig().getName()) .useCurrentCreationDate() .build(); try { MachineSource machineSource = machine.saveToSnapshot(); snapshot.setMachineSource(machineSource); return snapshot; } catch (ServerException e) { try { machine.getLogger().writeLine("Snapshot storing failed. " + e.getLocalizedMessage()); } catch (IOException ignore) { } throw e; } } } throw new NotFoundException(format("Machine with id '%s' is not found in environment of workspace '%s'", machineId, workspaceId)); }

Target:
public SnapshotImpl saveSnapshot(String namespace, String workspaceId, String machineId) throws ServerException, NotFoundException { EnvironmentHolder environmentHolder; SnapshotImpl snapshot = null; Instance instance = null; try (StripedLocks.ReadLock lock = stripedLocks.acquireReadLock(workspaceId)) { environmentHolder = environments.get(workspaceId); if (environmentHolder == null || environmentHolder.status != EnvStatus.RUNNING) { throw new EnvironmentNotRunningException(format("Environment '%s' is not running", workspaceId)); } for (Instance machine : environmentHolder.machines) { if (machine.getId().equals(machineId)) { instance = machine; snapshot = SnapshotImpl.builder() .generateId() .setType(machine.getConfig().getType()) .setNamespace(namespace) .setWorkspaceId(machine.getWorkspaceId()) .setDescription(machine.getEnvName()) .setDev(machine.getConfig().isDev()) .setEnvName(machine.getEnvName()) .setMachineName(machine.getConfig().getName()) .useCurrentCreationDate() .build(); } } } if (instance == null) { throw new NotFoundException(format("Machine with id '%s' is not found in environment of workspace '%s'", machineId, workspaceId)); } try { MachineSource machineSource = instance.saveToSnapshot(); snapshot.setMachineSource(machineSource); return snapshot; } catch (ServerException e) { try { instance.getLogger().writeLine("Snapshot storing failed. " + e.getLocalizedMessage()); } catch (IOException ignore) { } throw e; } }
Source:
public void setEnvironment() throws Exception { super.init(); apimTestCaseUtils.loadResource ("/artifacts/AM/synapseconfigs/property/duplicate_transfer_encoding.xml"); int port = 9785; String expectedResponse = "HTTP/1.0 200 OK\r\nServer: testServer\r\n" + "Content-Type: text/html\r\n" + "Transfer-Encoding: chunked\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n" + "<HTML>\n" + "<!DOCTYPE HTML PUBLIC " + "\"- "<HEAD>\n" + " <TITLE>Test Server Results</TITLE>\n" + "</HEAD>\n" + "\n" + "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1 ALIGN=\"CENTER\"> Results</H1>\n" + "Here is the request line and request headers\n" + "sent by your browser:\n" + "<PRE>"; simpleSocketServer = new SimpleSocketServer(port, expectedResponse); simpleSocketServer.start(); Thread.sleep(10000); }

Target:
public void setEnvironment() throws Exception { super.init(); AuthenticatorClient login = new AuthenticatorClient(gatewayContext.getContextUrls().getBackEndUrl()); String session = login.login("admin", "admin", "localhost"); String file = "artifacts" + File.separator + "AM" + File.separator + "synapseconfigs" + File.separator + "property" + File.separator + "duplicate_transfer_encoding.xml"; OMElement synapseConfig = apimTestCaseUtils.loadResource(file); apimTestCaseUtils.updateSynapseConfiguration(synapseConfig, gatewayContext.getContextUrls().getBackEndUrl(), session); int port = 9785; String expectedResponse = "HTTP/1.0 200 OK\r\nServer: testServer\r\n" + "Content-Type: text/html\r\n" + "Transfer-Encoding: chunked\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n" + "<HTML>\n" + "<!DOCTYPE HTML PUBLIC " + "\"- "<HEAD>\n" + " <TITLE>Test Server Results</TITLE>\n" + "</HEAD>\n" + "\n" + "<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1 ALIGN=\"CENTER\"> Results</H1>\n" + "Here is the request line and request headers\n" + "sent by your browser:\n" + "<PRE>"; simpleSocketServer = new SimpleSocketServer(port, expectedResponse); simpleSocketServer.start(); Thread.sleep(10000); }
Source:
public DataNode<ProjectData> resolveProjectInfo( @NotNull ExternalSystemTaskId id, @NotNull String projectPath, boolean isPreviewMode, @Nullable PantsExecutionSettings settings, @NotNull ExternalSystemTaskNotificationListener listener ) throws ExternalSystemException, IllegalArgumentException, IllegalStateException { if (projectPath.startsWith(".pants.d")) { return null; } checkForDifferentPantsExecutables(id, projectPath); final PantsCompileOptionsExecutor executor = PantsCompileOptionsExecutor.create(projectPath, settings); task2executor.put(id, executor); final DataNode<ProjectData> projectDataNode = resolveProjectInfoImpl(id, executor, listener, isPreviewMode, settings.isEnableIncrementalImport()); if (!settings.isImportSourceDepsAsJars()) { doViewSwitch(id, projectPath); } task2executor.remove(id); return projectDataNode; }

Target:
public DataNode<ProjectData> resolveProjectInfo( @NotNull ExternalSystemTaskId id, @NotNull String projectPath, boolean isPreviewMode, @Nullable PantsExecutionSettings settings, @NotNull ExternalSystemTaskNotificationListener listener ) throws ExternalSystemException, IllegalArgumentException, IllegalStateException { if (projectPath.startsWith(".pants.d")) { return null; } checkForDifferentPantsExecutables(id, projectPath); final PantsCompileOptionsExecutor executor = PantsCompileOptionsExecutor.create(projectPath, settings); task2executor.put(id, executor); final DataNode<ProjectData> projectDataNode = resolveProjectInfoImpl(id, executor, listener, isPreviewMode, settings.isEnableIncrementalImport()); doViewSwitch(id, projectPath); task2executor.remove(id); return projectDataNode; }
Source:
private void handleQosDataCenterLinks(Map<Guid, List<Qos>> qosMap) { if (!qosMap.isEmpty()) { List<StorageQos> list = getBackendCollection( StorageQos.class, QueryType.GetAllQosByType, new QosQueryParameterBase(null, QosType.STORAGE)); for (StorageQos storageQos : list) { List<Qos> qosList = qosMap.get(storageQos.getId()); if (qosList != null) { DataCenter dc = new DataCenter(); for (Qos qos : qosList) { qos.setDataCenter(dc); qos.getDataCenter().setId(storageQos.getStoragePoolId().toString()); } } } } }

Target:
private void handleQosDataCenterLinks(Map<Guid, List<Qos>> qosMap) { if (!qosMap.isEmpty()) { List<StorageQos> list = getBackendCollection( StorageQos.class, QueryType.GetAllQosByType, new QosQueryParameterBase(null, QosType.STORAGE)); for (StorageQos storageQos : list) { List<Qos> qosList = qosMap.get(storageQos.getId()); if (qosList != null) { DataCenter dc = new DataCenter(); dc.setId(storageQos.getStoragePoolId().toString()); for (Qos qos : qosList) { qos.setDataCenter(dc); } } } } }
Source:
protected boolean classpathContainerContains(IJavaProject project, String id, String path) throws JavaModelException { try { return getClasspathEntry(project, id, path) != null; } catch (Exception e) { debug("entry was not found", e); return false; } }

Target:
protected boolean classpathContainerContains(IJavaProject project, String id, String path) throws JavaModelException { IClasspathContainer container = JavaCore.getClasspathContainer(new Path(id), project); for (IClasspathEntry entry : container.getClasspathEntries()) { if (entry.getPath().toOSString().contains(path)) { return true; } } return false; }
Source:
void assertThatExperimentInformationIsTransformedIntoSolrInputDocuments(String accession) throws Exception { Experiment experiment = experimentTrader.getPublicExperiment(accession); Iterable<SolrInputDocument> result = getResults(experiment); int count = 0; for (SolrInputDocument solrInputDocument : result) { count++; assertThat(solrInputDocument.size(), greaterThan(6)); assertThat( experiment.getType().name().toUpperCase(), is(solrInputDocument.getField("experiment_type").getValue())); assertThat( experiment.getSpecies().getReferenceName(), is(solrInputDocument.getField("species").getValue())); } assertThat(count, is(greaterThan(100))); }

Target:
void assertThatExperimentInformationIsTransformedIntoSolrInputDocuments(String accession) throws Exception { Experiment experiment = experimentTrader.getPublicExperiment(accession); Iterable<SolrInputDocument> result = getResults(experiment); int count = 0; for (SolrInputDocument solrInputDocument : result) { count++; assertThat(solrInputDocument.size(), greaterThan(6)); assertThat( experiment.getType().name().toUpperCase(), is(solrInputDocument.getField("experiment_type").getValue())); assertThat( experiment.getSpecies().getReferenceName(), is(solrInputDocument.getField("species").getValue())); } assertThat(count, is(greaterThan(0))); }
Source:
protected boolean canDoAction() { if (getVm() == null) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_NOT_FOUND); } if (getVm().isDeleteProtected()) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_DELETE_PROTECTION_ENABLED); } if (!(super.canDoAction() && canRemoveVm())) { return false; } return true; }

Target:
protected boolean canDoAction() { if (getVm() == null) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_VM_NOT_FOUND); } if (getVm().isDeleteProtected()) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_DELETE_PROTECTION_ENABLED); } return (super.canDoAction() && canRemoveVm()); }
Source:
public CliCommand init(final Arguments args) throws Exception { this.filterParams = args.getFilterParams(); this.bucketName = args.getBucket(); if (Guard.isStringNullOrEmpty(this.bucketName)) { throw new MissingOptionException("The get detailed objects command requires '-b' to be set."); } if (!Guard.isStringNullOrEmpty(args.getPrefix())) { LOG.warn("'-p' prefix is not supported."); } this.prefix = null; return this; }

Target:
public CliCommand init(final Arguments args) throws Exception { this.filterParams = args.getFilterParams(); this.bucketName = args.getBucket(); if (!Guard.isStringNullOrEmpty(args.getPrefix())) { LOG.warn("'-p' prefix is not supported."); } this.prefix = null; return this; }
Source:
public List<GatewayTable> getAll(GATEWAY_TYPE gatewayType, NETWORK_TYPE networkType, Boolean enabled) { try { if (gatewayType == null && networkType == null && enabled == null) { return this.getDao().queryForAll(); } QueryBuilder<GatewayTable, Integer> queryBuilder = this.getDao().queryBuilder(); Where<GatewayTable, Integer> where = queryBuilder.where(); where.gt("id", 0); if (enabled != null) { where.and().eq(GatewayTable.KEY_ENABLED, enabled); } if (gatewayType != null) { where.and().eq(GatewayTable.KEY_TYPE, gatewayType); } if (networkType != null) { where.and().eq(GatewayTable.KEY_NETWORK_TYPE, networkType); } queryBuilder.setWhere(where); List<GatewayTable> gateways = this.getDao().query(queryBuilder.prepare()); return gateways; } catch (SQLException ex) { _logger.error("unable to get all gateways:[type:{}, NetworkType:{}, Enabled:{}]", gatewayType != null ? gatewayType.getText() : "no gateway", networkType, enabled, ex); return null; } }

Target:
public List<GatewayTable> getAll(GATEWAY_TYPE gatewayType, NETWORK_TYPE networkType, Boolean enabled) { try { if (gatewayType == null && networkType == null && enabled == null) { return this.getDao().queryForAll(); } QueryBuilder<GatewayTable, Integer> queryBuilder = this.getDao().queryBuilder(); Where<GatewayTable, Integer> where = queryBuilder.where(); where.gt("id", 0); if (enabled != null) { where.and().eq(GatewayTable.KEY_ENABLED, enabled); } if (gatewayType != null) { where.and().eq(GatewayTable.KEY_TYPE, gatewayType); } if (networkType != null) { where.and().eq(GatewayTable.KEY_NETWORK_TYPE, networkType); } queryBuilder.setWhere(where); List<GatewayTable> gateways = this.getDao().query(queryBuilder.prepare()); return gateways; } catch (SQLException ex) { _logger.error("unable to get all gateways:[type:{}, NetworkType:{}, Enabled:{}]", gatewayType != null ? gatewayType.getText() : null, networkType, enabled, ex); return null; } }
Source:
public BasisFunctionAggregation(final List<Function1D<T, Double>> functions, final double[] weights) { Validate.notEmpty(functions, "no functions"); Validate.notNull(weights, "no weights"); Validate.isTrue(functions.size() == weights.length); _f = functions; _w = weights; }

Target:
public BasisFunctionAggregation(final List<Function1D<T, Double>> functions, final double[] weights) { Validate.notEmpty(functions, "no functions"); Validate.notNull(weights, "no weights"); Validate.isTrue(functions.size() == weights.length); _f = functions; _w = weights.clone(); }
Source:
public Map<String, Object> toBundleFragment() { Map<String, Object> bundleFragment = new HashMap<>(); bundleFragment.put(Bundleable.KIND, this.getClass().getSimpleName()); bundleFragment.put("name", name); bundleFragment.put("signature", signature.toString()); bundleFragment.put("category", category); bundleFragment.put("documentation", documentation); bundleFragment.put("isConstructor", isConstructor); bundleFragment.put("isCommon", isCommon); return bundleFragment; }

Target:
public Map<String, Object> toBundleFragment() { Map<String, Object> bundleFragment = new HashMap<>(); bundleFragment.put(Bundleable.KIND, this.getClass().getSimpleName()); bundleFragment.put("name", name); return bundleFragment; }
Source:
public void shouldRenderStatisticsPageWithTwoMonitors() { JamonTestUtil.startThisManyMonitors(2); wicketTester.startPage(new JamonAdminPage()); wicketTester.assertRenderedPage(JamonAdminPage.class); }

Target:
public void shouldRenderStatisticsPageWithTwoMonitors() { JamonTestUtil.startThisManyMonitors(2); wicketTester.startPage(new JamonAdminPage()); wicketTester.assertRenderedPage(JamonAdminPage.class); Assert.assertEquals(2, wicketTester.getTagsByWicketId("linkText").size()); Assert.assertTrue( wicketTester.getTagsByWicketId("linkText").get(0).getValue().equals("mon0")); Assert.assertTrue( wicketTester.getTagsByWicketId("linkText").get(1).getValue().equals("mon1")); }
Source:
public boolean equals(Object o) { if (o instanceof PermissionSubject) { PermissionSubject other = (PermissionSubject) o; return other.objectId.equals(objectId) && other.ObjectType.equals(ObjectType) && other.actionGroup.equals(actionGroup); } return false; }

Target:
public boolean equals(Object o) { if (o instanceof PermissionSubject) { PermissionSubject other = (PermissionSubject) o; return Objects.equals(other.objectId, objectId) && Objects.equals(other.ObjectType, ObjectType) && Objects.equals(other.actionGroup, actionGroup); } return false; }
Source:
public SAMRecord next() { if (bufferIndex < buffer.size()) { return buffer.get(bufferIndex++); } else { return this.iterator.next(); } }

Target:
public SAMRecord next() { if (bufferIndex < buffer.size()) { return buffer.get(bufferIndex++); } else { buffer.clear(); return this.iterator.next(); } }
Source:
public void test_create_table_with_check_fail_on_insert() { execute("create table t (id integer primary key, qty integer, constraint check_1 check (qty > 0))"); execute("insert into t(id, qty) values(0, null), (1, 1)"); refresh(); execute("select id, qty from t order by id"); assertEquals(2, response.rowCount()); Object [][] rows = response.rows(); assertEquals(0, rows[0][0]); assertNull(rows[0][1]); assertEquals(1, rows[1][0]); assertEquals(1, rows[1][1]); expectedException.expectMessage(containsString("Failed CONSTRAINT check_1 CHECK (\"qty\" > 0) and values")); execute("insert into t(id, qty) values(2, -1)"); }

Target:
public void test_create_table_with_check_fail_on_insert() { execute("create table t (id integer primary key, qty integer, constraint check_1 check (qty > 0))"); execute("insert into t(id, qty) values(0, null), (1, 1)"); refresh(); execute("select id, qty from t order by id"); assertEquals(printedTable(response.rows()), "0| NULL\n" + "1| 1\n"); expectedException.expectMessage(containsString("Failed CONSTRAINT check_1 CHECK (\"qty\" > 0) and values")); execute("insert into t(id, qty) values(2, -1)"); }
Source:
public char[] getPassphrase(byte[] keyFingerprint) throws PGPException { if (passphrase == null) { passphrase = new CharArrayType(JGitText.get().credentialPassphrase, true); } if (credentialsProvider == null) { throw new PGPException(JGitText.get().gpgNoCredentialsProvider); } if (passphrase.getValue() == null && !credentialsProvider .get(createURI(keyFingerprint), passphrase)) { return null; } return passphrase.getValue(); }

Target:
public char[] getPassphrase(byte[] keyFingerprint) throws PGPException, CanceledException { if (passphrase == null) { passphrase = new CharArrayType(JGitText.get().credentialPassphrase, true); } if (credentialsProvider == null) { throw new PGPException(JGitText.get().gpgNoCredentialsProvider); } if (passphrase.getValue() == null && !credentialsProvider.get(createURI(keyFingerprint), new InformationalMessage( MessageFormat.format(JGitText.get().gpgKeyInfo, Hex.toHexString(keyFingerprint))), passphrase)) { throw new CanceledException(JGitText.get().gpgSigningCancelled); } return passphrase.getValue(); }
Source:
public Promise<HttpResponse> execute(HttpUriRequest request, HttpContext context) { final SettableFuture<HttpResponse> future = SettableFuture.create(); client.execute(request, context, new ThreadLocalContextAwareFutureCallback<C, HttpResponse>(threadLocalContextManager) { @Override void doCompleted(final HttpResponse httpResponse) { executor.execute( () -> future.set(httpResponse)); log.info( "Closing in doCompleted()" ); closeClient(); } @Override void doFailed(final Exception ex) { executor.execute(() -> future.setException(ex)); log.info( "Closing in doFailed()" ); closeClient(); } @Override void doCancelled() { final TimeoutException timeoutException = new TimeoutException(); executor.execute(() -> future.setException(timeoutException)); log.info( "Closing in doCancelled()" ); closeClient(); } }); return Promises.forListenableFuture(future); }

Target:
public Promise<HttpResponse> execute(HttpUriRequest request, HttpContext context) { final SettableFuture<HttpResponse> future = SettableFuture.create(); Future<org.apache.http.HttpResponse> clientFuture = client.execute(request, context, new ThreadLocalContextAwareFutureCallback<C, HttpResponse>(threadLocalContextManager) { @Override void doCompleted(final HttpResponse httpResponse) { executor.execute( () -> future.set(httpResponse)); log.info( "Closing in doCompleted()" ); closeClient(); } @Override void doFailed(final Exception ex) { executor.execute(() -> future.setException(ex)); log.info( "Closing in doFailed()" ); closeClient(); } @Override void doCancelled() { final TimeoutException timeoutException = new TimeoutException(); executor.execute(() -> future.setException(timeoutException)); log.info( "Closing in doCancelled()" ); closeClient(); } }); return Promises.forFuture(clientFuture,executor); }
Source:
public String toString() { final List<UUID> recipientIds = _recipients.values() .stream() .map(Recipient::getId) .collect(Collectors.toList()); return MoreObjects.toStringHelper(this) .add("id", _id) .add("name", _name) .add("schedule", _schedule) .add("recipients", recipientIds) .add("source.id", _source.getId()) .toString(); }

Target:
public String toString() { return MoreObjects.toStringHelper(this) .add("id", _id) .add("name", _name) .add("schedule", _schedule) .add("recipients", _recipients) .add("source", _source) .toString(); }
Source:
private RangerCloudIdentitySyncStatus setAzureCloudIdentityMapping(String envCrn, SdxCluster sdxCluster, Map<String, String> azureUserMapping) { String stackCrn = sdxCluster.getStackCrn(); LOGGER.info("Updating azure cloud id mappings for envCrn = {}, datalake stack crn = {}", envCrn, stackCrn); try { if (!clouderaManagerRangerUtil.isCloudIdMappingSupported(sdxCluster.getStackCrn())) { return sucessfulCloudIdSyncStatus("The datalake does not support cloud identity sync. Sync request is ignored."); } Optional<ApiCommand> apiCommand = clouderaManagerRangerUtil.setAzureCloudIdentityMapping(stackCrn, azureUserMapping); if (apiCommand.isEmpty()) { return sucessfulCloudIdSyncStatus("Sucessfully synced, no role refresh required"); } return toRangerCloudIdentitySyncStatus(apiCommand.get()); } catch (ApiException e) { LOGGER.error("Encountered api exception", e); return failedRangerCloudIdentitySyncStatus("Encountered cloudera manager api exception"); } }

Target:
private RangerCloudIdentitySyncStatus setAzureCloudIdentityMapping(String envCrn, SdxCluster sdxCluster, Map<String, String> azureUserMapping) { String stackCrn = sdxCluster.getStackCrn(); LOGGER.info("Updating azure cloud id mappings for envCrn = {}, datalake stack crn = {}", envCrn, stackCrn); try { if (!clouderaManagerRangerUtil.isCloudIdMappingSupported(sdxCluster.getStackCrn())) { return newSyncStatus(RangerCloudIdentitySyncState.NOT_APPLICABLE, "The datalake does not support cloud identity sync. Sync request is ignored."); } Optional<ApiCommand> apiCommand = clouderaManagerRangerUtil.setAzureCloudIdentityMapping(stackCrn, azureUserMapping); if (apiCommand.isEmpty()) { return newSyncStatus(RangerCloudIdentitySyncState.SUCCESS, "Sucessfully synced, no role refresh required"); } return toRangerCloudIdentitySyncStatus(apiCommand.get()); } catch (ApiException e) { LOGGER.error("Encountered api exception", e); return newSyncStatus(RangerCloudIdentitySyncState.FAILED, "Encountered cloudera manager api exception"); } }