input
stringlengths
205
73.3k
output
stringlengths
64
73.2k
instruction
stringclasses
1 value
#vulnerable code private BuildStrategy createBuildStrategy(ImageConfiguration imageConfig, OpenShiftBuildStrategy osBuildStrategy) { if (osBuildStrategy == OpenShiftBuildStrategy.docker) { return new BuildStrategyBuilder().withType("Docker").build(); } else if (osBuildStrategy == OpenShiftBuildStrategy.s2i) { BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration(); Map<String, String> fromExt = buildConfig.getFromExt(); String fromName = getMapValueWithDefault(fromExt, OpenShiftBuildStrategy.SourceStrategy.name, buildConfig.getFrom()); String fromKind = getMapValueWithDefault(fromExt, OpenShiftBuildStrategy.SourceStrategy.kind, "DockerImage"); String fromNamespace = getMapValueWithDefault(fromExt, OpenShiftBuildStrategy.SourceStrategy.namespace, "ImageStreamTag".equals(fromKind) ? "openshift" : null); if (fromNamespace.isEmpty()) { fromNamespace = null; } return new BuildStrategyBuilder() .withType("Source") .withNewSourceStrategy() .withNewFrom() .withKind(fromKind) .withName(fromName) .withNamespace(fromNamespace) .endFrom() .endSourceStrategy() .build(); } else { throw new IllegalArgumentException("Unsupported BuildStrategy " + osBuildStrategy); } } #location 11 #vulnerability type NULL_DEREFERENCE
#fixed code private BuildStrategy createBuildStrategy(ImageConfiguration imageConfig, OpenShiftBuildStrategy osBuildStrategy) { if (osBuildStrategy == OpenShiftBuildStrategy.docker) { return new BuildStrategyBuilder().withType("Docker").build(); } else if (osBuildStrategy == OpenShiftBuildStrategy.s2i) { BuildImageConfiguration buildConfig = imageConfig.getBuildConfiguration(); Map<String, String> fromExt = buildConfig.getFromExt(); String fromName = getMapValueWithDefault(fromExt, OpenShiftBuildStrategy.SourceStrategy.name, buildConfig.getFrom()); String fromKind = getMapValueWithDefault(fromExt, OpenShiftBuildStrategy.SourceStrategy.kind, "DockerImage"); String fromNamespace = getMapValueWithDefault(fromExt, OpenShiftBuildStrategy.SourceStrategy.namespace, "ImageStreamTag".equals(fromKind) ? "openshift" : null); return new BuildStrategyBuilder() .withType("Source") .withNewSourceStrategy() .withNewFrom() .withKind(fromKind) .withName(fromName) .withNamespace(StringUtils.isEmpty(fromNamespace) ? null : fromNamespace) .endFrom() .endSourceStrategy() .build(); } else { throw new IllegalArgumentException("Unsupported BuildStrategy " + osBuildStrategy); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public WatcherContext getWatcherContext() throws MojoExecutionException { try { BuildService.BuildContext buildContext = getBuildContext(); WatchService.WatchContext watchContext = getWatchContext(hub); return new WatcherContext.Builder() .serviceHub(hub) .buildContext(buildContext) .watchContext(watchContext) .config(extractWatcherConfig()) .logger(log) .newPodLogger(createLogger("[[C]][NEW][[C]] ")) .oldPodLogger(createLogger("[[R]][OLD][[R]] ")) .mode(mode) .project(project) .useProjectClasspath(useProjectClasspath) .clusterConfiguration(getClusterConfiguration()) .kubernetesClient(kubernetes) .fabric8ServiceHub(getFabric8ServiceHub()) .build(); } catch(IOException exception) { throw new MojoExecutionException(exception.getMessage()); } } #location 21 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code public WatcherContext getWatcherContext() throws MojoExecutionException { try { BuildService.BuildContext buildContext = getBuildContext(); WatchService.WatchContext watchContext = hub != null ? getWatchContext(hub) : null; return new WatcherContext.Builder() .serviceHub(hub) .buildContext(buildContext) .watchContext(watchContext) .config(extractWatcherConfig()) .logger(log) .newPodLogger(createLogger("[[C]][NEW][[C]] ")) .oldPodLogger(createLogger("[[R]][OLD][[R]] ")) .mode(mode) .project(project) .useProjectClasspath(useProjectClasspath) .clusterConfiguration(getClusterConfiguration()) .kubernetesClient(kubernetes) .fabric8ServiceHub(getFabric8ServiceHub()) .build(); } catch(IOException exception) { throw new MojoExecutionException(exception.getMessage()); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void assertApplicationEndpoint(String key, String value) throws Exception { int nTries = 0; Response readResponse = null; String responseContent = null; Route applicationRoute = getApplicationRouteWithName(testsuiteRepositoryArtifactId); String hostUrl = applicationRoute.getSpec().getHost() + TEST_ENDPOINT; do { Response response = makeHttpRequest(HttpRequestType.GET, "http://" + hostUrl, null); responseContent = new JSONObject(response.body().string()).getString(key); nTries++; TimeUnit.SECONDS.sleep(10); } while(nTries < 3 && readResponse != null && readResponse.code() != HttpStatus.SC_OK); if (!responseContent.equals(value)) throw new AssertionError(String.format("Actual : %s, Expected : %s", responseContent, value)); } #location 9 #vulnerability type NULL_DEREFERENCE
#fixed code private void assertApplicationEndpoint(String key, String value) throws Exception { int nTries = 0; Response readResponse = null; String responseContent = null; Route applicationRoute = getApplicationRouteWithName(testsuiteRepositoryArtifactId); String hostUrl = applicationRoute.getSpec().getHost() + TEST_ENDPOINT; do { readResponse = makeHttpRequest(HttpRequestType.GET, "http://" + hostUrl, null); responseContent = new JSONObject(readResponse.body().string()).getString(key); nTries++; TimeUnit.SECONDS.sleep(10); } while(nTries < 3 && readResponse.code() != HttpStatus.SC_OK); if (!responseContent.equals(value)) throw new AssertionError(String.format("Actual : %s, Expected : %s", responseContent, value)); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void applyEntities(Controller controller, KubernetesClient kubernetes, String namespace, String fileName, Set<HasMetadata> entities) throws Exception { // Apply all items for (HasMetadata entity : entities) { if (entity instanceof Pod) { Pod pod = (Pod) entity; controller.applyPod(pod, fileName); } else if (entity instanceof Service) { Service service = (Service) entity; controller.applyService(service, fileName); } else if (entity instanceof ReplicationController) { ReplicationController replicationController = (ReplicationController) entity; controller.applyReplicationController(replicationController, fileName); } else if (entity != null) { controller.apply(entity, fileName); } } File file = null; try { Fabric8ServiceHub hub = getFabric8ServiceHub(); file = hub.getClientToolsService().getKubeCtlExecutable(controller); } catch (Exception e) { log.warn("%s", e.getMessage()); } if (file != null) { log.info("[[B]]HINT:[[B]] Use the command `%s get pods -w` to watch your pods start up",file.getName()); } Logger serviceLogger = createExternalProcessLogger("[[G]][SVC][[G]] "); long serviceUrlWaitTimeSeconds = this.serviceUrlWaitTimeSeconds; for (HasMetadata entity : entities) { if (entity instanceof Service) { Service service = (Service) entity; String name = getName(service); Resource<Service, DoneableService> serviceResource = kubernetes.services().inNamespace(namespace).withName(name); String url = null; // lets wait a little while until there is a service URL in case the exposecontroller is running slow for (int i = 0; i < serviceUrlWaitTimeSeconds; i++) { if (i > 0) { Thread.sleep(1000); } Service s = serviceResource.get(); if (s != null) { url = getExternalServiceURL(s); if (Strings.isNotBlank(url)) { break; } } if (!isExposeService(service)) { break; } } // lets not wait for other services serviceUrlWaitTimeSeconds = 1; if (Strings.isNotBlank(url) && url.startsWith("http")) { serviceLogger.info("" + name + ": " + url); } } } } #location 21 #vulnerability type RESOURCE_LEAK
#fixed code protected void applyEntities(Controller controller, KubernetesClient kubernetes, String namespace, String fileName, Set<HasMetadata> entities) throws Exception { // Apply all items for (HasMetadata entity : entities) { if (entity instanceof Pod) { Pod pod = (Pod) entity; controller.applyPod(pod, fileName); } else if (entity instanceof Service) { Service service = (Service) entity; controller.applyService(service, fileName); } else if (entity instanceof ReplicationController) { ReplicationController replicationController = (ReplicationController) entity; controller.applyReplicationController(replicationController, fileName); } else if (entity != null) { controller.apply(entity, fileName); } } File file = null; try { Fabric8ServiceHub hub = getFabric8ServiceHub(controller); file = hub.getClientToolsService().getKubeCtlExecutable(); } catch (Exception e) { log.warn("%s", e.getMessage()); } if (file != null) { log.info("[[B]]HINT:[[B]] Use the command `%s get pods -w` to watch your pods start up",file.getName()); } Logger serviceLogger = createExternalProcessLogger("[[G]][SVC][[G]] "); long serviceUrlWaitTimeSeconds = this.serviceUrlWaitTimeSeconds; for (HasMetadata entity : entities) { if (entity instanceof Service) { Service service = (Service) entity; String name = getName(service); Resource<Service, DoneableService> serviceResource = kubernetes.services().inNamespace(namespace).withName(name); String url = null; // lets wait a little while until there is a service URL in case the exposecontroller is running slow for (int i = 0; i < serviceUrlWaitTimeSeconds; i++) { if (i > 0) { Thread.sleep(1000); } Service s = serviceResource.get(); if (s != null) { url = getExternalServiceURL(s); if (Strings.isNotBlank(url)) { break; } } if (!isExposeService(service)) { break; } } // lets not wait for other services serviceUrlWaitTimeSeconds = 1; if (Strings.isNotBlank(url) && url.startsWith("http")) { serviceLogger.info("" + name + ": " + url); } } } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void executeInternal() throws MojoExecutionException, MojoFailureException { if (!basedir.isDirectory() || !basedir.exists()) { throw new MojoExecutionException("No directory for base directory: " + basedir); } // lets check for a git repo String gitRemoteURL = null; Repository repository = null; try { repository = GitUtils.findRepository(basedir); } catch (IOException e) { throw new MojoExecutionException("Failed to find local git repository in current directory: " + e, e); } try { gitRemoteURL = GitUtils.getRemoteURL(repository); } catch (Exception e) { throw new MojoExecutionException("Failed to get the current git branch: " + e, e); } try { clusterAccess = new ClusterAccess(this.namespace); if (Strings.isNullOrBlank(projectName)) { projectName = basedir.getName(); } KubernetesClient kubernetes = clusterAccess.createKubernetesClient(); KubernetesResourceUtil.validateKubernetesMasterUrl(kubernetes.getMasterUrl()); String namespace = clusterAccess.getNamespace(); OpenShiftClient openShiftClient = getOpenShiftClientOrJenkinsShift(kubernetes, namespace); if (gitRemoteURL != null) { // lets check we don't already have this project imported String branch = repository.getBranch(); BuildConfig buildConfig = findBuildConfigForGitRepo(openShiftClient, namespace, gitRemoteURL, branch); if (buildConfig != null) { logBuildConfigLink(kubernetes, namespace, buildConfig, log); throw new MojoExecutionException("Project already imported into build " + getName(buildConfig) + " for URI: " + gitRemoteURL + " and branch: " + branch); } else { Map<String, String> annotations = new HashMap<>(); annotations.put(Annotations.Builds.GIT_CLONE_URL, gitRemoteURL); buildConfig = createBuildConfig(kubernetes, namespace, projectName, gitRemoteURL, annotations); openShiftClient.buildConfigs().inNamespace(namespace).create(buildConfig); ensureExternalGitSecretsAreSetupFor(kubernetes, namespace, gitRemoteURL); logBuildConfigLink(kubernetes, namespace, buildConfig, log); } } else { // lets create an import a new project UserDetails userDetails = createGogsUserDetails(kubernetes, namespace); BuildConfigHelper.CreateGitProjectResults createGitProjectResults; try { createGitProjectResults = BuildConfigHelper.importNewGitProject(kubernetes, userDetails, basedir, namespace, projectName, originBranchName, "Importing project from mvn fabric8:import", false); } catch (WebApplicationException e) { Response response = e.getResponse(); if (response.getStatus() > 400) { String message = getEntityMessage(response); log.warn("Could not create the git repository: %s %s", e, message); log.warn("Are your username and password correct in the Secret %s/%s?", secretNamespace, gogsSecretName); log.warn("To re-enter your password rerun this command with -Dfabric8.passsword.retry=true"); throw new MojoExecutionException("Could not create the git repository. " + "Are your username and password correct in the Secret " + secretNamespace + "/" + gogsSecretName + "?" + e + message, e); } else { throw e; } } BuildConfig buildConfig = createGitProjectResults.getBuildConfig(); openShiftClient.buildConfigs().inNamespace(namespace).create(buildConfig); logBuildConfigLink(kubernetes, namespace, buildConfig, log); } } catch (KubernetesClientException e) { KubernetesResourceUtil.handleKubernetesClientException(e, this.log); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } } #location 38 #vulnerability type RESOURCE_LEAK
#fixed code @Override public void executeInternal() throws MojoExecutionException, MojoFailureException { if (!basedir.isDirectory() || !basedir.exists()) { throw new MojoExecutionException("No directory for base directory: " + basedir); } // lets check for a git repo String gitRemoteURL = null; Repository repository = null; try { repository = GitUtils.findRepository(basedir); } catch (IOException e) { throw new MojoExecutionException("Failed to find local git repository in current directory: " + e, e); } try { gitRemoteURL = GitUtils.getRemoteURL(repository); } catch (Exception e) { throw new MojoExecutionException("Failed to get the current git branch: " + e, e); } try { clusterAccess = new ClusterAccess(this.namespace); if (Strings.isNullOrBlank(projectName)) { projectName = basedir.getName(); } KubernetesClient kubernetes = clusterAccess.createDefaultClient(log); KubernetesResourceUtil.validateKubernetesMasterUrl(kubernetes.getMasterUrl()); String namespace = clusterAccess.getNamespace(); OpenShiftClient openShiftClient = getOpenShiftClientOrJenkinsShift(kubernetes, namespace); if (gitRemoteURL != null) { // lets check we don't already have this project imported String branch = repository.getBranch(); BuildConfig buildConfig = findBuildConfigForGitRepo(openShiftClient, namespace, gitRemoteURL, branch); if (buildConfig != null) { logBuildConfigLink(kubernetes, namespace, buildConfig, log); throw new MojoExecutionException("Project already imported into build " + getName(buildConfig) + " for URI: " + gitRemoteURL + " and branch: " + branch); } else { Map<String, String> annotations = new HashMap<>(); annotations.put(Annotations.Builds.GIT_CLONE_URL, gitRemoteURL); buildConfig = createBuildConfig(kubernetes, namespace, projectName, gitRemoteURL, annotations); openShiftClient.buildConfigs().inNamespace(namespace).create(buildConfig); ensureExternalGitSecretsAreSetupFor(kubernetes, namespace, gitRemoteURL); logBuildConfigLink(kubernetes, namespace, buildConfig, log); } } else { // lets create an import a new project UserDetails userDetails = createGogsUserDetails(kubernetes, namespace); BuildConfigHelper.CreateGitProjectResults createGitProjectResults; try { createGitProjectResults = BuildConfigHelper.importNewGitProject(kubernetes, userDetails, basedir, namespace, projectName, originBranchName, "Importing project from mvn fabric8:import", false); } catch (WebApplicationException e) { Response response = e.getResponse(); if (response.getStatus() > 400) { String message = getEntityMessage(response); log.warn("Could not create the git repository: %s %s", e, message); log.warn("Are your username and password correct in the Secret %s/%s?", secretNamespace, gogsSecretName); log.warn("To re-enter your password rerun this command with -Dfabric8.passsword.retry=true"); throw new MojoExecutionException("Could not create the git repository. " + "Are your username and password correct in the Secret " + secretNamespace + "/" + gogsSecretName + "?" + e + message, e); } else { throw e; } } BuildConfig buildConfig = createGitProjectResults.getBuildConfig(); openShiftClient.buildConfigs().inNamespace(namespace).create(buildConfig); logBuildConfigLink(kubernetes, namespace, buildConfig, log); } } catch (KubernetesClientException e) { KubernetesResourceUtil.handleKubernetesClientException(e, this.log); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected Fabric8ServiceHub getFabric8ServiceHub() { return new Fabric8ServiceHub.Builder() .log(log) .clusterAccess(clusterAccess) .dockerServiceHub(hub) .platformMode(mode) .build(); } #location 4 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code protected Fabric8ServiceHub getFabric8ServiceHub() { return new Fabric8ServiceHub.Builder() .log(log) .clusterAccess(clusterAccess) .dockerServiceHub(hub) .platformMode(mode) .repositorySystem(repositorySystem) .build(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static int runCommand(final Logger log, File command, List<String> args, boolean withShutdownHook) throws IOException { String[] commandWithArgs = prepareCommandArray(command.getAbsolutePath(), args); Process process = Runtime.getRuntime().exec(commandWithArgs); if (withShutdownHook) { addShutdownHook(log, process, command); } List<Thread> threads = startLoggingThreads(process, log, command.getName() + " " + Strings.join(args, " ")); try { int answer = process.waitFor(); joinThreads(threads, log); return answer; } catch (InterruptedException e) { return process.exitValue(); } } #location 11 #vulnerability type RESOURCE_LEAK
#fixed code public static int runCommand(final Logger log, File command, List<String> args, boolean withShutdownHook) throws IOException { return runAsyncCommand(log, command, args, withShutdownHook).await(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void portForward(Controller controller, String podName) throws MojoExecutionException { try { getFabric8ServiceHub().getPortForwardService() .forwardPort(controller, createExternalProcessLogger("[[B]]port-forward[[B]] "), podName, portToInt(remoteDebugPort, "remoteDebugPort"), portToInt(localDebugPort, "localDebugPort")); log.info(""); log.info("Now you can start a Remote debug execution in your IDE by using localhost and the debug port " + localDebugPort); log.info(""); } catch (Fabric8ServiceException e) { throw new MojoExecutionException("Failed to start port forwarding" + e, e); } } #location 3 #vulnerability type RESOURCE_LEAK
#fixed code private void portForward(Controller controller, String podName) throws MojoExecutionException { try { getFabric8ServiceHub(controller).getPortForwardService() .forwardPort(createExternalProcessLogger("[[B]]port-forward[[B]] "), podName, portToInt(remoteDebugPort, "remoteDebugPort"), portToInt(localDebugPort, "localDebugPort")); log.info(""); log.info("Now you can start a Remote debug execution in your IDE by using localhost and the debug port " + localDebugPort); log.info(""); } catch (Fabric8ServiceException e) { throw new MojoExecutionException("Failed to start port forwarding" + e, e); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> withSelector(ClientNonNamespaceOperation<Pod, PodList, DoneablePod, ClientPodResource<Pod, DoneablePod>> pods, LabelSelector selector) { FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> answer = pods; Map<String, String> matchLabels = selector.getMatchLabels(); if (matchLabels != null && !matchLabels.isEmpty()) { answer = answer.withLabels(matchLabels); } List<LabelSelectorRequirement> matchExpressions = selector.getMatchExpressions(); if (matchExpressions != null) { for (LabelSelectorRequirement expression : matchExpressions) { String key = expression.getKey(); List<String> values = expression.getValues(); if (Strings.isNullOrBlank(key)) { log.warn("Ignoring empty key in selector expression %s", expression); continue; } if (values == null && values.isEmpty()) { log.warn("Ignoring empty values in selector expression %s", expression); continue; } String[] valuesArray = values.toArray(new String[values.size()]); String operator = expression.getOperator(); switch (operator) { case "In": answer = answer.withLabelIn(key, valuesArray); break; case "NotIn": answer = answer.withLabelNotIn(key, valuesArray); break; default: log.warn("Ignoring unknown operator %s in selector expression %s", operator, expression); } } } return answer; } #location 16 #vulnerability type NULL_DEREFERENCE
#fixed code protected FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> withSelector(ClientNonNamespaceOperation<Pod, PodList, DoneablePod, ClientPodResource<Pod, DoneablePod>> pods, LabelSelector selector) { FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> answer = pods; Map<String, String> matchLabels = selector.getMatchLabels(); if (matchLabels != null && !matchLabels.isEmpty()) { answer = answer.withLabels(matchLabels); } List<LabelSelectorRequirement> matchExpressions = selector.getMatchExpressions(); if (matchExpressions != null) { for (LabelSelectorRequirement expression : matchExpressions) { String key = expression.getKey(); List<String> values = expression.getValues(); if (Strings.isNullOrBlank(key)) { log.warn("Ignoring empty key in selector expression %s", expression); continue; } if (values == null || values.isEmpty()) { log.warn("Ignoring empty values in selector expression %s", expression); continue; } String[] valuesArray = values.toArray(new String[values.size()]); String operator = expression.getOperator(); switch (operator) { case "In": answer = answer.withLabelIn(key, valuesArray); break; case "NotIn": answer = answer.withLabelNotIn(key, valuesArray); break; default: log.warn("Ignoring unknown operator %s in selector expression %s", operator, expression); } } } return answer; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code Result scan() throws MojoExecutionException { // Scanning is lazy ... if (result == null) { if (!directory.exists()) { // No directory to check found so we return null here ... return null; } String[] jarOrWars = directory.list((dir, name) -> name.endsWith(".war") || name.endsWith(".jar")); if (jarOrWars == null || jarOrWars.length == 0) { return null; } long maxSize = 0; for (String jarOrWar : jarOrWars) { File archiveFile = new File(directory, jarOrWar); try { JarFile archive = new JarFile(archiveFile); Manifest mf = archive.getManifest(); Attributes mainAttributes = mf.getMainAttributes(); if (mainAttributes != null) { String mainClass = mainAttributes.getValue("Main-Class"); if (mainClass != null) { long size = archiveFile.length(); // Take the largest jar / war file found if (size > maxSize) { maxSize = size; result = new Result(archiveFile, mainClass, mainAttributes); } } } } catch (IOException e) { throw new MojoExecutionException("Cannot examine file " + archiveFile + " for the manifest"); } } } return result; } #location 17 #vulnerability type RESOURCE_LEAK
#fixed code FatJarDetector(String dir) { this.directory = new File(dir); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private Probe discoverSpringBootHealthCheck(int initialDelay) { try { if (hasClass(this.getProject(), "org.springframework.boot.actuate.health.HealthIndicator")) { Properties properties = SpringBootUtil.getSpringBootApplicationProperties(this.getProject()); Integer port = getInteger(properties, SpringBootProperties.MANAGEMENT_PORT, getInteger(properties, SpringBootProperties.SERVER_PORT, DEFAULT_MANAGEMENT_PORT)); // lets default to adding a spring boot actuator health check return new ProbeBuilder().withNewHttpGet(). withNewPort(port).withPath("/health").endHttpGet().withInitialDelaySeconds(initialDelay).build(); } } catch (Exception ex) { log.error("Error while reading the spring-boot configuration", ex); } return null; } #location 3 #vulnerability type NULL_DEREFERENCE
#fixed code private Probe discoverSpringBootHealthCheck(int initialDelay) { try { if (hasAllClasses(this.getProject(), REQUIRED_CLASSES)) { Properties properties = SpringBootUtil.getSpringBootApplicationProperties(this.getProject()); Integer port = getInteger(properties, SpringBootProperties.MANAGEMENT_PORT, getInteger(properties, SpringBootProperties.SERVER_PORT, DEFAULT_MANAGEMENT_PORT)); // lets default to adding a spring boot actuator health check return new ProbeBuilder().withNewHttpGet(). withNewPort(port).withPath("/health").endHttpGet().withInitialDelaySeconds(initialDelay).build(); } } catch (Exception ex) { log.error("Error while reading the spring-boot configuration", ex); } return null; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private String getPortForwardUrl(final Set<HasMetadata> resources) throws Exception { LabelSelector selector = KubernetesResourceUtil.getPodLabelSelector(resources); if (selector == null) { log.warn("Unable to determine a selector for application pods"); return null; } PortForwardService portForwardService = getContext().getFabric8ServiceHub().getPortForwardService(); // TODO choose the right ports portForwardService.forwardPortAsync(getContext().getLogger(), selector, 8080, 20000); return "http://localhost:20000"; } #location 10 #vulnerability type RESOURCE_LEAK
#fixed code private String getPortForwardUrl(final Set<HasMetadata> resources) throws Exception { LabelSelector selector = KubernetesResourceUtil.getPodLabelSelector(resources); if (selector == null) { log.warn("Unable to determine a selector for application pods"); return null; } PortForwardService portForwardService = getContext().getFabric8ServiceHub().getPortForwardService(); int port = IoUtil.getFreeRandomPort(); portForwardService.forwardPortAsync(getContext().getLogger(), selector, 8080, port); return "http://localhost:" + port; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void applyEntities(Controller controller, KubernetesClient kubernetes, String namespace, String fileName, Set<HasMetadata> entities) throws Exception { // Apply all items for (HasMetadata entity : entities) { if (entity instanceof Pod) { Pod pod = (Pod) entity; controller.applyPod(pod, fileName); } else if (entity instanceof Service) { Service service = (Service) entity; controller.applyService(service, fileName); } else if (entity instanceof ReplicationController) { ReplicationController replicationController = (ReplicationController) entity; controller.applyReplicationController(replicationController, fileName); } else if (entity != null) { controller.apply(entity, fileName); } } File file = null; try { Fabric8ServiceHub hub = getFabric8ServiceHub(); file = hub.getClientToolsService().getKubeCtlExecutable(controller); } catch (Exception e) { log.warn("%s", e.getMessage()); } if (file != null) { log.info("[[B]]HINT:[[B]] Use the command `%s get pods -w` to watch your pods start up",file.getName()); } Logger serviceLogger = createExternalProcessLogger("[[G]][SVC][[G]] "); long serviceUrlWaitTimeSeconds = this.serviceUrlWaitTimeSeconds; for (HasMetadata entity : entities) { if (entity instanceof Service) { Service service = (Service) entity; String name = getName(service); Resource<Service, DoneableService> serviceResource = kubernetes.services().inNamespace(namespace).withName(name); String url = null; // lets wait a little while until there is a service URL in case the exposecontroller is running slow for (int i = 0; i < serviceUrlWaitTimeSeconds; i++) { if (i > 0) { Thread.sleep(1000); } Service s = serviceResource.get(); if (s != null) { url = getExternalServiceURL(s); if (Strings.isNotBlank(url)) { break; } } if (!isExposeService(service)) { break; } } // lets not wait for other services serviceUrlWaitTimeSeconds = 1; if (Strings.isNotBlank(url) && url.startsWith("http")) { serviceLogger.info("" + name + ": " + url); } } } } #location 21 #vulnerability type RESOURCE_LEAK
#fixed code protected void applyEntities(Controller controller, KubernetesClient kubernetes, String namespace, String fileName, Set<HasMetadata> entities) throws Exception { // Apply all items for (HasMetadata entity : entities) { if (entity instanceof Pod) { Pod pod = (Pod) entity; controller.applyPod(pod, fileName); } else if (entity instanceof Service) { Service service = (Service) entity; controller.applyService(service, fileName); } else if (entity instanceof ReplicationController) { ReplicationController replicationController = (ReplicationController) entity; controller.applyReplicationController(replicationController, fileName); } else if (entity != null) { controller.apply(entity, fileName); } } File file = null; try { Fabric8ServiceHub hub = getFabric8ServiceHub(controller); file = hub.getClientToolsService().getKubeCtlExecutable(); } catch (Exception e) { log.warn("%s", e.getMessage()); } if (file != null) { log.info("[[B]]HINT:[[B]] Use the command `%s get pods -w` to watch your pods start up",file.getName()); } Logger serviceLogger = createExternalProcessLogger("[[G]][SVC][[G]] "); long serviceUrlWaitTimeSeconds = this.serviceUrlWaitTimeSeconds; for (HasMetadata entity : entities) { if (entity instanceof Service) { Service service = (Service) entity; String name = getName(service); Resource<Service, DoneableService> serviceResource = kubernetes.services().inNamespace(namespace).withName(name); String url = null; // lets wait a little while until there is a service URL in case the exposecontroller is running slow for (int i = 0; i < serviceUrlWaitTimeSeconds; i++) { if (i > 0) { Thread.sleep(1000); } Service s = serviceResource.get(); if (s != null) { url = getExternalServiceURL(s); if (Strings.isNotBlank(url)) { break; } } if (!isExposeService(service)) { break; } } // lets not wait for other services serviceUrlWaitTimeSeconds = 1; if (Strings.isNotBlank(url) && url.startsWith("http")) { serviceLogger.info("" + name + ": " + url); } } } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void executeInternal() throws MojoExecutionException, MojoFailureException { if (!basedir.isDirectory() || !basedir.exists()) { throw new MojoExecutionException("No directory for base directory: " + basedir); } // lets check for a git repo String gitRemoteURL = null; Repository repository = null; try { repository = GitUtils.findRepository(basedir); } catch (IOException e) { throw new MojoExecutionException("Failed to find local git repository in current directory: " + e, e); } try { gitRemoteURL = GitUtils.getRemoteURL(repository); } catch (Exception e) { throw new MojoExecutionException("Failed to get the current git branch: " + e, e); } try { clusterAccess = new ClusterAccess(this.namespace); if (Strings.isNullOrBlank(projectName)) { projectName = basedir.getName(); } KubernetesClient kubernetes = clusterAccess.createKubernetesClient(); KubernetesResourceUtil.validateKubernetesMasterUrl(kubernetes.getMasterUrl()); String namespace = clusterAccess.getNamespace(); OpenShiftClient openShiftClient = getOpenShiftClientOrJenkinsShift(kubernetes, namespace); if (gitRemoteURL != null) { // lets check we don't already have this project imported String branch = repository.getBranch(); BuildConfig buildConfig = findBuildConfigForGitRepo(openShiftClient, namespace, gitRemoteURL, branch); if (buildConfig != null) { logBuildConfigLink(kubernetes, namespace, buildConfig, log); throw new MojoExecutionException("Project already imported into build " + getName(buildConfig) + " for URI: " + gitRemoteURL + " and branch: " + branch); } else { Map<String, String> annotations = new HashMap<>(); annotations.put(Annotations.Builds.GIT_CLONE_URL, gitRemoteURL); buildConfig = createBuildConfig(kubernetes, namespace, projectName, gitRemoteURL, annotations); openShiftClient.buildConfigs().inNamespace(namespace).create(buildConfig); ensureExternalGitSecretsAreSetupFor(kubernetes, namespace, gitRemoteURL); logBuildConfigLink(kubernetes, namespace, buildConfig, log); } } else { // lets create an import a new project UserDetails userDetails = createGogsUserDetails(kubernetes, namespace); BuildConfigHelper.CreateGitProjectResults createGitProjectResults; try { createGitProjectResults = BuildConfigHelper.importNewGitProject(kubernetes, userDetails, basedir, namespace, projectName, originBranchName, "Importing project from mvn fabric8:import", false); } catch (WebApplicationException e) { Response response = e.getResponse(); if (response.getStatus() > 400) { String message = getEntityMessage(response); log.warn("Could not create the git repository: %s %s", e, message); log.warn("Are your username and password correct in the Secret %s/%s?", secretNamespace, gogsSecretName); log.warn("To re-enter your password rerun this command with -Dfabric8.passsword.retry=true"); throw new MojoExecutionException("Could not create the git repository. " + "Are your username and password correct in the Secret " + secretNamespace + "/" + gogsSecretName + "?" + e + message, e); } else { throw e; } } BuildConfig buildConfig = createGitProjectResults.getBuildConfig(); openShiftClient.buildConfigs().inNamespace(namespace).create(buildConfig); logBuildConfigLink(kubernetes, namespace, buildConfig, log); } } catch (KubernetesClientException e) { KubernetesResourceUtil.handleKubernetesClientException(e, this.log); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } } #location 79 #vulnerability type RESOURCE_LEAK
#fixed code @Override public void executeInternal() throws MojoExecutionException, MojoFailureException { if (!basedir.isDirectory() || !basedir.exists()) { throw new MojoExecutionException("No directory for base directory: " + basedir); } // lets check for a git repo String gitRemoteURL = null; Repository repository = null; try { repository = GitUtils.findRepository(basedir); } catch (IOException e) { throw new MojoExecutionException("Failed to find local git repository in current directory: " + e, e); } try { gitRemoteURL = GitUtils.getRemoteURL(repository); } catch (Exception e) { throw new MojoExecutionException("Failed to get the current git branch: " + e, e); } try { clusterAccess = new ClusterAccess(this.namespace); if (Strings.isNullOrBlank(projectName)) { projectName = basedir.getName(); } KubernetesClient kubernetes = clusterAccess.createDefaultClient(log); KubernetesResourceUtil.validateKubernetesMasterUrl(kubernetes.getMasterUrl()); String namespace = clusterAccess.getNamespace(); OpenShiftClient openShiftClient = getOpenShiftClientOrJenkinsShift(kubernetes, namespace); if (gitRemoteURL != null) { // lets check we don't already have this project imported String branch = repository.getBranch(); BuildConfig buildConfig = findBuildConfigForGitRepo(openShiftClient, namespace, gitRemoteURL, branch); if (buildConfig != null) { logBuildConfigLink(kubernetes, namespace, buildConfig, log); throw new MojoExecutionException("Project already imported into build " + getName(buildConfig) + " for URI: " + gitRemoteURL + " and branch: " + branch); } else { Map<String, String> annotations = new HashMap<>(); annotations.put(Annotations.Builds.GIT_CLONE_URL, gitRemoteURL); buildConfig = createBuildConfig(kubernetes, namespace, projectName, gitRemoteURL, annotations); openShiftClient.buildConfigs().inNamespace(namespace).create(buildConfig); ensureExternalGitSecretsAreSetupFor(kubernetes, namespace, gitRemoteURL); logBuildConfigLink(kubernetes, namespace, buildConfig, log); } } else { // lets create an import a new project UserDetails userDetails = createGogsUserDetails(kubernetes, namespace); BuildConfigHelper.CreateGitProjectResults createGitProjectResults; try { createGitProjectResults = BuildConfigHelper.importNewGitProject(kubernetes, userDetails, basedir, namespace, projectName, originBranchName, "Importing project from mvn fabric8:import", false); } catch (WebApplicationException e) { Response response = e.getResponse(); if (response.getStatus() > 400) { String message = getEntityMessage(response); log.warn("Could not create the git repository: %s %s", e, message); log.warn("Are your username and password correct in the Secret %s/%s?", secretNamespace, gogsSecretName); log.warn("To re-enter your password rerun this command with -Dfabric8.passsword.retry=true"); throw new MojoExecutionException("Could not create the git repository. " + "Are your username and password correct in the Secret " + secretNamespace + "/" + gogsSecretName + "?" + e + message, e); } else { throw e; } } BuildConfig buildConfig = createGitProjectResults.getBuildConfig(); openShiftClient.buildConfigs().inNamespace(namespace).create(buildConfig); logBuildConfigLink(kubernetes, namespace, buildConfig, log); } } catch (KubernetesClientException e) { KubernetesResourceUtil.handleKubernetesClientException(e, this.log); } catch (Exception e) { throw new MojoExecutionException(e.getMessage(), e); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void watch(List<ImageConfiguration> configs, Set<HasMetadata> resources, PlatformMode mode) throws Exception { KubernetesClient kubernetes = getContext().getKubernetesClient(); PodLogService.PodLogServiceContext logContext = new PodLogService.PodLogServiceContext.Builder() .log(log) .newPodLog(getContext().getNewPodLogger()) .oldPodLog(getContext().getOldPodLogger()) .build(); new PodLogService(logContext).tailAppPodsLogs(kubernetes, getContext().getNamespace(), resources, false, null, true, null, false); long serviceUrlWaitTimeSeconds = Configs.asInt(getConfig(Config.serviceUrlWaitTimeSeconds)); boolean serviceFound = false; for (HasMetadata entity : resources) { if (entity instanceof Service) { Service service = (Service) entity; String name = KubernetesHelper.getName(service); Resource<Service, DoneableService> serviceResource = kubernetes.services().inNamespace(getContext().getNamespace()).withName(name); String url = null; // lets wait a little while until there is a service URL in case the exposecontroller is running slow for (int i = 0; i < serviceUrlWaitTimeSeconds; i++) { if (i > 0) { Thread.sleep(1000); } Service s = serviceResource.get(); if (s != null) { url = KubernetesHelper.getOrCreateAnnotations(s).get(Annotations.Service.EXPOSE_URL); if (Strings.isNotBlank(url)) { break; } } if (!isExposeService(service)) { break; } } // lets not wait for other services serviceUrlWaitTimeSeconds = 1; if (Strings.isNotBlank(url) && url.startsWith("http")) { serviceFound = true; runRemoteSpringApplication(url); } } } if (!serviceFound) { throw new IllegalStateException("No external service found for this application! So cannot watch a remote container!"); } } #location 40 #vulnerability type NULL_DEREFERENCE
#fixed code @Override public void watch(List<ImageConfiguration> configs, Set<HasMetadata> resources, PlatformMode mode) throws Exception { KubernetesClient kubernetes = getContext().getKubernetesClient(); PodLogService.PodLogServiceContext logContext = new PodLogService.PodLogServiceContext.Builder() .log(log) .newPodLog(getContext().getNewPodLogger()) .oldPodLog(getContext().getOldPodLogger()) .build(); new PodLogService(logContext).tailAppPodsLogs(kubernetes, getContext().getNamespace(), resources, false, null, true, null, false); String url = getServiceExposeUrl(kubernetes, resources); if (url == null) { url = getPortForwardUrl(resources); } if (url != null) { runRemoteSpringApplication(url); } else { throw new IllegalStateException("Unable to open a channel to the remote pod."); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public WatcherContext getWatcherContext() throws MojoExecutionException { try { BuildService.BuildContext buildContext = getBuildContext(); WatchService.WatchContext watchContext = getWatchContext(hub); return new WatcherContext.Builder() .serviceHub(hub) .buildContext(buildContext) .watchContext(watchContext) .config(extractWatcherConfig()) .logger(log) .newPodLogger(createLogger("[[C]][NEW][[C]] ")) .oldPodLogger(createLogger("[[R]][OLD][[R]] ")) .mode(mode) .project(project) .useProjectClasspath(useProjectClasspath) .clusterConfiguration(getClusterConfiguration()) .kubernetesClient(kubernetes) .fabric8ServiceHub(getFabric8ServiceHub()) .build(); } catch(IOException exception) { throw new MojoExecutionException(exception.getMessage()); } } #location 14 #vulnerability type THREAD_SAFETY_VIOLATION
#fixed code public WatcherContext getWatcherContext() throws MojoExecutionException { try { BuildService.BuildContext buildContext = getBuildContext(); WatchService.WatchContext watchContext = hub != null ? getWatchContext(hub) : null; return new WatcherContext.Builder() .serviceHub(hub) .buildContext(buildContext) .watchContext(watchContext) .config(extractWatcherConfig()) .logger(log) .newPodLogger(createLogger("[[C]][NEW][[C]] ")) .oldPodLogger(createLogger("[[R]][OLD][[R]] ")) .mode(mode) .project(project) .useProjectClasspath(useProjectClasspath) .clusterConfiguration(getClusterConfiguration()) .kubernetesClient(kubernetes) .fabric8ServiceHub(getFabric8ServiceHub()) .build(); } catch(IOException exception) { throw new MojoExecutionException(exception.getMessage()); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void enrich(KubernetesListBuilder builder) { final ServiceConfiguration defaultServiceConfig = extractDefaultServiceConfig(); final Service defaultService = serviceHandler.getService(defaultServiceConfig,null); if (hasServices(builder)) { builder.accept(new Visitor<ServiceBuilder>() { @Override public void visit(ServiceBuilder service) { mergeServices(service, defaultService); } }); } else { log.info("Adding a default Service with ports [%s]", formatPortsAsList(defaultService.getSpec().getPorts())); builder.addToServiceItems(defaultService); } } #location 14 #vulnerability type NULL_DEREFERENCE
#fixed code @Override public void enrich(KubernetesListBuilder builder) { final ServiceConfiguration defaultServiceConfig = extractDefaultServiceConfig(); final Service defaultService = serviceHandler.getService(defaultServiceConfig,null); if (hasServices(builder)) { builder.accept(new Visitor<ServiceBuilder>() { @Override public void visit(ServiceBuilder service) { mergeServices(service, defaultService); } }); } else { if (defaultService != null) { ServiceSpec spec = defaultService.getSpec(); if (spec != null) { List<ServicePort> ports = spec.getPorts(); if (ports != null) { log.info("Adding a default Service with ports [%s]", formatPortsAsList(ports)); builder.addToServiceItems(defaultService); } } } } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void triggerJob(String jobKey, JobDataMap data) throws SchedulerException { validateState(); OperableTrigger operableTrigger = TriggerBuilder.newTriggerBuilder().withIdentity(jobKey + "-trigger").forJob(jobKey) .withTriggerImplementation(SimpleScheduleBuilder.simpleScheduleBuilderBuilder().build()).startAt(new Date()).build(); // TODO what does this accomplish??? Seems to sets it's next fire time internally operableTrigger.computeFirstFireTime(null); if (data != null) { operableTrigger.setJobDataMap(data); } boolean collision = true; while (collision) { try { quartzSchedulerResources.getJobStore().storeTrigger(operableTrigger, false); collision = false; } catch (ObjectAlreadyExistsException oaee) { operableTrigger.setName(newTriggerId()); } } notifySchedulerThread(operableTrigger.getNextFireTime().getTime()); notifySchedulerListenersScheduled(operableTrigger); } #location 26 #vulnerability type NULL_DEREFERENCE
#fixed code @Override public void triggerJob(String jobKey, JobDataMap data) throws SchedulerException { validateState(); OperableTrigger operableTrigger = simpleScheduleBuilderBuilder().withIdentity(jobKey + "-trigger").forJob(jobKey).startAt(new Date()).build(); // OperableTrigger operableTrigger = TriggerBuilder.newTriggerBuilder().withIdentity(jobKey + "-trigger").forJob(jobKey) // .withTriggerImplementation(SimpleScheduleBuilder.simpleScheduleBuilderBuilder().instantiate()).startAt(new Date()).build(); // TODO what does this accomplish??? Seems to sets it's next fire time internally operableTrigger.computeFirstFireTime(null); if (data != null) { operableTrigger.setJobDataMap(data); } boolean collision = true; while (collision) { try { quartzSchedulerResources.getJobStore().storeTrigger(operableTrigger, false); collision = false; } catch (ObjectAlreadyExistsException oaee) { operableTrigger.setName(newTriggerId()); } } notifySchedulerThread(operableTrigger.getNextFireTime().getTime()); notifySchedulerListenersScheduled(operableTrigger); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public Job findByJobClass(Long appId, String clazz) { return findById(findIdByJobClass(appId, clazz)); } #location 3 #vulnerability type NULL_DEREFERENCE
#fixed code @Override public Job findByJobClass(Long appId, String clazz) { Long jobId = findIdByJobClass(appId, clazz); return jobId == null ? null : findById(jobId); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public void execute(final JobDetail jobDetail, JobTriggerType triggerType, JobExecutionContext context) { final String appName = jobDetail.getApp().getAppName(); final String jobClass = jobDetail.getJob().getClazz(); JobInstance instance = null; try { Logs.info("The job({}/{}) is fired.", appName, jobClass); if (triggerType == JobTriggerType.DEFAULT){ // refresh the job fire time if triggered by scheduler asyncExecutor.submit(new RefreshJobFireTimeTask(appName, jobClass, context)); } if (!canRunJobInstance(appName, jobClass)){ return; } // job is running jobSupport.updateJobStateDirectly(appName, jobClass, JobState.RUNNING); // create the job instance and shards instance = createInstanceAndShards(jobDetail, triggerType); // trigger the clients to pull shards jobSupport.triggerJobInstance(appName, jobClass, instance); // blocking until all shards to be finished or timeout Long timeout = jobDetail.getConfig().getTimeout(); timeout = timeout == null ? 0L : timeout; JobInstanceWaitResp finishResp = jobSupport.waitingJobInstanceFinish(appName, jobClass, timeout, instance.getId()); if (finishResp.isSuccess()){ // job instance is finished successfully // publish job finish event eventDispatcher.publish(new JobFinishedEvent(instance.getJobId(), instance.getId())); } else if (finishResp.isTimeout()){ // job instance is timeout eventDispatcher.publish(new JobTimeoutEvent(instance.getJobId(), instance.getId(), buildJobTimeoutDetail(instance))); } // maybe now the job is paused, stopped, ..., so need to expect the job state jobSupport.updateJobStateSafely(appName, jobClass, JobState.WAITING); // job has finished } catch (JobStateTransferInvalidException e){ // job state transfer error Logs.warn("failed to update job state(instances={}), cause: {}.", instance, e.toString()); } catch (JobInstanceCreateException e){ // handle when job instance create failed String cause = Throwables.getStackTraceAsString(e); Logs.error("failed to create job instance when execute job(jobDetail={}, instance={}), cause: {}", jobDetail, instance, cause); handleJobExecuteFailed(jobDetail, instance, appName, jobClass, cause); } catch (Exception e){ // handle other exceptions String cause = Throwables.getStackTraceAsString(e); Logs.error("failed to execute job(jobDetail={}, instance={}), cause: {}", jobDetail, instance, cause); handleJobExecuteFailed(jobDetail, instance, appName, jobClass, cause); } } #location 33 #vulnerability type NULL_DEREFERENCE
#fixed code @Override public void execute(final JobDetail jobDetail, JobTriggerType triggerType, JobExecutionContext context) { final String appName = jobDetail.getApp().getAppName(); final String jobClass = jobDetail.getJob().getClazz(); JobInstance instance = null; try { Logs.info("The job({}/{}) is fired.", appName, jobClass); if (triggerType == JobTriggerType.DEFAULT){ // refresh the job fire time if triggered by scheduler asyncExecutor.submit(new RefreshJobFireTimeTask(appName, jobClass, context)); } if (!canRunJobInstance(appName, jobClass)){ return; } // job is running jobSupport.updateJobStateDirectly(appName, jobClass, JobState.RUNNING); // create the job instance and shards instance = createInstanceAndShards(jobDetail, triggerType); // trigger the clients to pull shards jobSupport.triggerJobInstance(appName, jobClass, instance); // blocking until all shards to be finished or timeout Long timeout = jobDetail.getConfig().getTimeout(); timeout = timeout == null ? 0L : timeout; JobInstanceWaitResp finishResp = jobSupport.waitingJobInstanceFinish(appName, jobClass, instance.getId(), timeout); if (finishResp.isSuccess()){ // job instance is finished successfully // publish job finish event eventDispatcher.publish(new JobFinishedEvent(instance.getJobId(), instance.getId())); } else if (finishResp.isTimeout()){ // job instance is timeout eventDispatcher.publish(new JobTimeoutEvent(instance.getJobId(), instance.getId(), buildJobTimeoutDetail(instance))); } // maybe now the job is paused, stopped, ..., so need to expect the job state jobSupport.updateJobStateSafely(appName, jobClass, JobState.WAITING); // job has finished } catch (JobStateTransferInvalidException e){ // job state transfer error Logs.warn("failed to update job state(instances={}), cause: {}.", instance, e.toString()); } catch (JobInstanceCreateException e){ // handle when job instance create failed String cause = Throwables.getStackTraceAsString(e); Logs.error("failed to create job instance when execute job(jobDetail={}, instance={}), cause: {}", jobDetail, instance, cause); handleJobExecuteFailed(jobDetail, instance, appName, jobClass, cause); } catch (Exception e){ // handle other exceptions String cause = Throwables.getStackTraceAsString(e); Logs.error("failed to execute job(jobDetail={}, instance={}), cause: {}", jobDetail, instance, cause); handleJobExecuteFailed(jobDetail, instance, appName, jobClass, cause); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected static void denormalizeY(Dataset data, Map<Object, Double> minColumnValues, Map<Object, Double> maxColumnValues) { if(data.isEmpty()) { return; } if(data.getYDataType()==TypeInference.DataType.NUMERICAL) { for(Integer rId : data) { Record r = data.get(rId); //do the same for the response variable Y Double min = minColumnValues.get(Dataset.yColumnName); Double max = maxColumnValues.get(Dataset.yColumnName); Object denormalizedY = null; Object denormalizedYPredicted = null; if(min.equals(max)) { denormalizedY = min; if(r.getYPredicted()!=null) { denormalizedYPredicted = min; } } else { denormalizedY = TypeInference.toDouble(r.getY())*(max-min) + min; Double YPredicted = TypeInference.toDouble(r.getYPredicted()); if(YPredicted!=null) { denormalizedYPredicted = YPredicted*(max-min) + min; } } data.set(rId, new Record(r.getX(), denormalizedY, denormalizedYPredicted, r.getYPredictedProbabilities())); } } } #location 25 #vulnerability type NULL_DEREFERENCE
#fixed code protected static void denormalizeY(Dataset data, Map<Object, Double> minColumnValues, Map<Object, Double> maxColumnValues) { if(data.isEmpty()) { return; } TypeInference.DataType dataType = data.getYDataType(); if(dataType==TypeInference.DataType.NUMERICAL || dataType==null) { for(Integer rId : data) { Record r = data.get(rId); //do the same for the response variable Y Double min = minColumnValues.get(Dataset.yColumnName); Double max = maxColumnValues.get(Dataset.yColumnName); Object denormalizedY = null; Object denormalizedYPredicted = null; if(min.equals(max)) { if(r.getY()!=null) { denormalizedY = min; } if(r.getYPredicted()!=null) { denormalizedYPredicted = min; } } else { if(r.getY()!=null) { denormalizedY = TypeInference.toDouble(r.getY())*(max-min) + min; } Double YPredicted = TypeInference.toDouble(r.getYPredicted()); if(YPredicted!=null) { denormalizedYPredicted = YPredicted*(max-min) + min; } } data.set(rId, new Record(r.getX(), denormalizedY, denormalizedYPredicted, r.getYPredictedProbabilities())); } } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testValidate() { TestUtils.log(this.getClass(), "validate"); /* Example from http://www.inf.u-szeged.hu/~ormandi/ai2/06-naiveBayes-example.pdf FeatureList: - 0: red - 1: yellow - 2: sports - 3: suv - 4: domestic - 5: imported - c1: yes - c2: no */ /* Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, 1)); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 1.0, 0.0}, 0)); */ Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "imported"}, "yes")); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new String[] {"red", "suv", "domestic"}, "no")); String dbName = "JUnitClassifier"; SimpleDummyVariableExtractor df = new SimpleDummyVariableExtractor(dbName, TestUtils.getDBConfig()); df.fit_transform(trainingData, new SimpleDummyVariableExtractor.TrainingParameters()); df.transform(validationData); SupportVectorMachine instance = new SupportVectorMachine(dbName, TestUtils.getDBConfig()); SupportVectorMachine.TrainingParameters param = new SupportVectorMachine.TrainingParameters(); param.getSvmParameter().kernel_type = svm_parameter.RBF; instance.fit(trainingData, param); instance = null; instance = new SupportVectorMachine(dbName, TestUtils.getDBConfig()); instance.validate(validationData); df.denormalize(trainingData); df.denormalize(validationData); df.erase(); Map<Integer, Object> expResult = new HashMap<>(); Map<Integer, Object> result = new HashMap<>(); for(Record r : validationData) { expResult.put(r.getId(), r.getY()); result.put(r.getId(), r.getYPredicted()); } assertEquals(expResult, result); instance.erase(); } #location 53 #vulnerability type NULL_DEREFERENCE
#fixed code @Test public void testValidate() { TestUtils.log(this.getClass(), "validate"); /* Example from http://www.inf.u-szeged.hu/~ormandi/ai2/06-naiveBayes-example.pdf FeatureList: - 0: red - 1: yellow - 2: sports - 3: suv - 4: domestic - 5: imported - c1: yes - c2: no */ /* Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, 1)); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 1.0, 0.0}, 0)); */ Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "imported"}, "yes")); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new String[] {"red", "suv", "domestic"}, "no")); String dbName = "JUnitClassifier"; DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, TestUtils.getDBConfig()); df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters()); df.transform(validationData); SupportVectorMachine instance = new SupportVectorMachine(dbName, TestUtils.getDBConfig()); SupportVectorMachine.TrainingParameters param = new SupportVectorMachine.TrainingParameters(); param.getSvmParameter().kernel_type = svm_parameter.RBF; instance.fit(trainingData, param); instance = null; instance = new SupportVectorMachine(dbName, TestUtils.getDBConfig()); instance.validate(validationData); df.denormalize(trainingData); df.denormalize(validationData); df.erase(); Map<Integer, Object> expResult = new HashMap<>(); Map<Integer, Object> result = new HashMap<>(); for(Record r : validationData) { expResult.put(r.getId(), r.getY()); result.put(r.getId(), r.getYPredicted()); } assertEquals(expResult, result); instance.erase(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testValidate() { TestUtils.log(this.getClass(), "validate"); RandomValue.randomGenerator = new Random(42); /* Example from http://www.inf.u-szeged.hu/~ormandi/ai2/06-naiveBayes-example.pdf FeatureList: - 0: red - 1: yellow - 2: sports - 3: suv - 4: domestic - 5: imported - c1: yes - c2: no */ /* Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, 1)); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 1.0, 0.0}, 0)); */ Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "imported"}, "yes")); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new String[] {"red", "suv", "domestic"}, "no")); String dbName = "JUnitClassifier"; SimpleDummyVariableExtractor df = new SimpleDummyVariableExtractor(dbName, TestUtils.getDBConfig()); df.fit_transform(trainingData, new SimpleDummyVariableExtractor.TrainingParameters()); df.transform(validationData); BootstrapAggregating instance = new BootstrapAggregating(dbName, TestUtils.getDBConfig()); BootstrapAggregating.TrainingParameters param = new BootstrapAggregating.TrainingParameters(); param.setMaxWeakClassifiers(5); param.setWeakClassifierClass(MultinomialNaiveBayes.class); MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters(); trainingParameters.setMultiProbabilityWeighted(true); param.setWeakClassifierTrainingParameters(trainingParameters); instance.fit(trainingData, param); instance = null; instance = new BootstrapAggregating(dbName, TestUtils.getDBConfig()); instance.validate(validationData); df.denormalize(trainingData); df.denormalize(validationData); df.erase(); Map<Integer, Object> expResult = new HashMap<>(); Map<Integer, Object> result = new HashMap<>(); for(Record r : validationData) { expResult.put(r.getId(), r.getY()); result.put(r.getId(), r.getYPredicted()); } assertEquals(expResult, result); instance.erase(); } #location 55 #vulnerability type NULL_DEREFERENCE
#fixed code @Test public void testValidate() { TestUtils.log(this.getClass(), "validate"); RandomValue.randomGenerator = new Random(42); /* Example from http://www.inf.u-szeged.hu/~ormandi/ai2/06-naiveBayes-example.pdf FeatureList: - 0: red - 1: yellow - 2: sports - 3: suv - 4: domestic - 5: imported - c1: yes - c2: no */ /* Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, 1)); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 1.0, 0.0}, 0)); */ Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "imported"}, "yes")); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new String[] {"red", "suv", "domestic"}, "no")); String dbName = "JUnitClassifier"; DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, TestUtils.getDBConfig()); df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters()); df.transform(validationData); BootstrapAggregating instance = new BootstrapAggregating(dbName, TestUtils.getDBConfig()); BootstrapAggregating.TrainingParameters param = new BootstrapAggregating.TrainingParameters(); param.setMaxWeakClassifiers(5); param.setWeakClassifierClass(MultinomialNaiveBayes.class); MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters(); trainingParameters.setMultiProbabilityWeighted(true); param.setWeakClassifierTrainingParameters(trainingParameters); instance.fit(trainingData, param); instance = null; instance = new BootstrapAggregating(dbName, TestUtils.getDBConfig()); instance.validate(validationData); df.denormalize(trainingData); df.denormalize(validationData); df.erase(); Map<Integer, Object> expResult = new HashMap<>(); Map<Integer, Object> result = new HashMap<>(); for(Record r : validationData) { expResult.put(r.getId(), r.getY()); result.put(r.getId(), r.getYPredicted()); } assertEquals(expResult, result); instance.erase(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testValidate() { TestUtils.log(this.getClass(), "validate"); /* Example from http://www.inf.u-szeged.hu/~ormandi/ai2/06-naiveBayes-example.pdf FeatureList: - 0: red - 1: yellow - 2: sports - 3: suv - 4: domestic - 5: imported - c1: yes - c2: no */ /* Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, 1)); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 1.0, 0.0}, 0)); */ Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "imported"}, "yes")); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new String[] {"red", "suv", "domestic"}, "no")); String dbName = "JUnitClassifier"; SimpleDummyVariableExtractor df = new SimpleDummyVariableExtractor(dbName, TestUtils.getDBConfig()); df.fit_transform(trainingData, new SimpleDummyVariableExtractor.TrainingParameters()); df.transform(validationData); MultinomialNaiveBayes instance = new MultinomialNaiveBayes(dbName, TestUtils.getDBConfig()); MultinomialNaiveBayes.TrainingParameters param = new MultinomialNaiveBayes.TrainingParameters(); param.setMultiProbabilityWeighted(true); instance.fit(trainingData, param); instance = null; instance = new MultinomialNaiveBayes(dbName, TestUtils.getDBConfig()); instance.validate(validationData); df.denormalize(trainingData); df.denormalize(validationData); df.erase(); Map<Integer, Object> expResult = new HashMap<>(); Map<Integer, Object> result = new HashMap<>(); for(Record r : validationData) { expResult.put(r.getId(), r.getY()); result.put(r.getId(), r.getYPredicted()); } assertEquals(expResult, result); instance.erase(); } #location 52 #vulnerability type NULL_DEREFERENCE
#fixed code @Test public void testValidate() { TestUtils.log(this.getClass(), "validate"); /* Example from http://www.inf.u-szeged.hu/~ormandi/ai2/06-naiveBayes-example.pdf FeatureList: - 0: red - 1: yellow - 2: sports - 3: suv - 4: domestic - 5: imported - c1: yes - c2: no */ /* Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, 1)); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 1.0, 0.0}, 0)); */ Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "imported"}, "yes")); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new String[] {"red", "suv", "domestic"}, "no")); String dbName = "JUnitClassifier"; DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, TestUtils.getDBConfig()); df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters()); df.transform(validationData); MultinomialNaiveBayes instance = new MultinomialNaiveBayes(dbName, TestUtils.getDBConfig()); MultinomialNaiveBayes.TrainingParameters param = new MultinomialNaiveBayes.TrainingParameters(); param.setMultiProbabilityWeighted(true); instance.fit(trainingData, param); instance = null; instance = new MultinomialNaiveBayes(dbName, TestUtils.getDBConfig()); instance.validate(validationData); df.denormalize(trainingData); df.denormalize(validationData); df.erase(); Map<Integer, Object> expResult = new HashMap<>(); Map<Integer, Object> result = new HashMap<>(); for(Record r : validationData) { expResult.put(r.getId(), r.getY()); result.put(r.getId(), r.getYPredicted()); } assertEquals(expResult, result); instance.erase(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testTrainAndValidate() { TestUtils.log(this.getClass(), "testTrainAndValidate"); RandomValue.setRandomGenerator(new Random(TestConfiguration.RANDOM_SEED)); DatabaseConfiguration dbConf = TestUtils.getDBConfig(); Dataset trainingData = new Dataset(dbConf); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, 1)); Dataset newData = new Dataset(dbConf); newData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 1.0, 0.0}, 0)); String dbName = "JUnit"; Modeler instance = new Modeler(dbName, dbConf); Modeler.TrainingParameters trainingParameters = new Modeler.TrainingParameters(); trainingParameters.setkFolds(5); //Model Configuration trainingParameters.setMLmodelClass(MultinomialNaiveBayes.class); MultinomialNaiveBayes.TrainingParameters modelTrainingParameters = new MultinomialNaiveBayes.TrainingParameters(); modelTrainingParameters.setMultiProbabilityWeighted(true); trainingParameters.setMLmodelTrainingParameters(modelTrainingParameters); /* trainingParameters.setMLmodelClass(Kmeans.class); Kmeans.TrainingParameters modelTrainingParameters = new Kmeans.TrainingParameters(); modelTrainingParameters.setK(2); modelTrainingParameters.setMaxIterations(200); modelTrainingParameters.setInitMethod(Kmeans.TrainingParameters.Initialization.FORGY); modelTrainingParameters.setDistanceMethod(Kmeans.TrainingParameters.Distance.EUCLIDIAN); modelTrainingParameters.setWeighted(false); modelTrainingParameters.setCategoricalGamaMultiplier(1.0); modelTrainingParameters.setSubsetFurthestFirstcValue(2.0); trainingParameters.setMLmodelTrainingParameters(modelTrainingParameters); */ //data transfomation configuration trainingParameters.setDataTransformerClass(DummyXMinMaxNormalizer.class); DummyXMinMaxNormalizer.TrainingParameters dtParams = new DummyXMinMaxNormalizer.TrainingParameters(); trainingParameters.setDataTransformerTrainingParameters(dtParams); //feature selection configuration trainingParameters.setFeatureSelectionClass(null); trainingParameters.setFeatureSelectionTrainingParameters(null); instance.fit(trainingData, trainingParameters); MultinomialNaiveBayes.ValidationMetrics vm = (MultinomialNaiveBayes.ValidationMetrics) instance.validate(trainingData); double expResult2 = 0.8; assertEquals(expResult2, vm.getMacroF1(), TestConfiguration.DOUBLE_ACCURACY_HIGH); instance = null; TestUtils.log(this.getClass(), "validate"); instance = new Modeler(dbName, dbConf); instance.validate(newData); Map<Integer, Object> expResult = new HashMap<>(); Map<Integer, Object> result = new HashMap<>(); for(Integer rId : newData) { Record r = newData.get(rId); expResult.put(rId, r.getY()); result.put(rId, r.getYPredicted()); } assertEquals(expResult, result); instance.erase(); } #location 8 #vulnerability type NULL_DEREFERENCE
#fixed code @Test public void testTrainAndValidate() { TestUtils.log(this.getClass(), "testTrainAndValidate"); RandomValue.setRandomGenerator(new Random(TestConfiguration.RANDOM_SEED)); DatabaseConfiguration dbConf = TestUtils.getDBConfig(); Dataset[] data = Datasets.carsNumeric(dbConf); Dataset trainingData = data[0]; Dataset newData = data[1]; String dbName = "JUnit"; Modeler instance = new Modeler(dbName, dbConf); Modeler.TrainingParameters trainingParameters = new Modeler.TrainingParameters(); trainingParameters.setkFolds(5); //Model Configuration trainingParameters.setMLmodelClass(MultinomialNaiveBayes.class); MultinomialNaiveBayes.TrainingParameters modelTrainingParameters = new MultinomialNaiveBayes.TrainingParameters(); modelTrainingParameters.setMultiProbabilityWeighted(true); trainingParameters.setMLmodelTrainingParameters(modelTrainingParameters); //data transfomation configuration trainingParameters.setDataTransformerClass(DummyXMinMaxNormalizer.class); DummyXMinMaxNormalizer.TrainingParameters dtParams = new DummyXMinMaxNormalizer.TrainingParameters(); trainingParameters.setDataTransformerTrainingParameters(dtParams); //feature selection configuration trainingParameters.setFeatureSelectionClass(null); trainingParameters.setFeatureSelectionTrainingParameters(null); instance.fit(trainingData, trainingParameters); MultinomialNaiveBayes.ValidationMetrics vm = (MultinomialNaiveBayes.ValidationMetrics) instance.validate(trainingData); double expResult2 = 0.8; assertEquals(expResult2, vm.getMacroF1(), TestConfiguration.DOUBLE_ACCURACY_HIGH); instance = null; TestUtils.log(this.getClass(), "validate"); instance = new Modeler(dbName, dbConf); instance.validate(newData); Map<Integer, Object> expResult = new HashMap<>(); Map<Integer, Object> result = new HashMap<>(); for(Integer rId : newData) { Record r = newData.get(rId); expResult.put(rId, r.getY()); result.put(rId, r.getYPredicted()); } assertEquals(expResult, result); instance.erase(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testValidate() { TestUtils.log(this.getClass(), "validate"); RandomValue.randomGenerator = new Random(42); /* Example from http://www.inf.u-szeged.hu/~ormandi/ai2/06-naiveBayes-example.pdf FeatureList: - 0: red - 1: yellow - 2: sports - 3: suv - 4: domestic - 5: imported - c1: yes - c2: no */ /* Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, 1)); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 1.0, 0.0}, 0)); */ Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "imported"}, "yes")); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new String[] {"red", "sports", "imported"}, "yes")); String dbName = "JUnitClassifier"; SimpleDummyVariableExtractor df = new SimpleDummyVariableExtractor(dbName, TestUtils.getDBConfig()); df.fit_transform(trainingData, new SimpleDummyVariableExtractor.TrainingParameters()); df.transform(validationData); Adaboost instance = new Adaboost(dbName, TestUtils.getDBConfig()); Adaboost.TrainingParameters param = new Adaboost.TrainingParameters(); param.setMaxWeakClassifiers(5); param.setWeakClassifierClass(MultinomialNaiveBayes.class); MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters(); trainingParameters.setMultiProbabilityWeighted(true); param.setWeakClassifierTrainingParameters(trainingParameters); instance.fit(trainingData, param); instance = null; instance = new Adaboost(dbName, TestUtils.getDBConfig()); instance.validate(validationData); df.denormalize(trainingData); df.denormalize(validationData); df.erase(); Map<Integer, Object> expResult = new HashMap<>(); Map<Integer, Object> result = new HashMap<>(); for(Record r : validationData) { expResult.put(r.getId(), r.getY()); result.put(r.getId(), r.getYPredicted()); } assertEquals(expResult, result); instance.erase(); } #location 54 #vulnerability type NULL_DEREFERENCE
#fixed code @Test public void testValidate() { TestUtils.log(this.getClass(), "validate"); RandomValue.randomGenerator = new Random(42); /* Example from http://www.inf.u-szeged.hu/~ormandi/ai2/06-naiveBayes-example.pdf FeatureList: - 0: red - 1: yellow - 2: sports - 3: suv - 4: domestic - 5: imported - c1: yes - c2: no */ /* Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, 1)); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 1.0, 0.0}, 0)); */ Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "imported"}, "yes")); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new String[] {"red", "sports", "imported"}, "yes")); String dbName = "JUnitClassifier"; DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, TestUtils.getDBConfig()); df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters()); df.transform(validationData); Adaboost instance = new Adaboost(dbName, TestUtils.getDBConfig()); Adaboost.TrainingParameters param = new Adaboost.TrainingParameters(); param.setMaxWeakClassifiers(5); param.setWeakClassifierClass(MultinomialNaiveBayes.class); MultinomialNaiveBayes.TrainingParameters trainingParameters = new MultinomialNaiveBayes.TrainingParameters(); trainingParameters.setMultiProbabilityWeighted(true); param.setWeakClassifierTrainingParameters(trainingParameters); instance.fit(trainingData, param); instance = null; instance = new Adaboost(dbName, TestUtils.getDBConfig()); instance.validate(validationData); df.denormalize(trainingData); df.denormalize(validationData); df.erase(); Map<Integer, Object> expResult = new HashMap<>(); Map<Integer, Object> result = new HashMap<>(); for(Record r : validationData) { expResult.put(r.getId(), r.getY()); result.put(r.getId(), r.getYPredicted()); } assertEquals(expResult, result); instance.erase(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testSelectFeatures() { TestUtils.log(this.getClass(), "selectFeatures"); RandomValue.setRandomGenerator(new Random(42)); String dbName = "JUnitChisquareFeatureSelection"; TFIDF.TrainingParameters param = new TFIDF.TrainingParameters(); param.setBinarized(false); param.setMaxFeatures(3); Dataset trainingData = new Dataset(); AssociativeArray xData1 = new AssociativeArray(); xData1.put("important1", 2.0); xData1.put("important2", 3.0); xData1.put("stopword1", 10.0); xData1.put("stopword2", 4.0); xData1.put("stopword3", 8.0); trainingData.add(new Record(xData1, null)); AssociativeArray xData2 = new AssociativeArray(); xData2.put("important1", 2.0); xData2.put("important3", 5.0); xData2.put("stopword1", 10.0); xData2.put("stopword2", 2.0); xData2.put("stopword3", 4.0); trainingData.add(new Record(xData2, null)); AssociativeArray xData3 = new AssociativeArray(); xData3.put("important2", 2.0); xData3.put("important3", 5.0); xData3.put("stopword1", 10.0); xData3.put("stopword2", 2.0); xData3.put("stopword3", 4.0); trainingData.add(new Record(xData3, null)); TFIDF instance = new TFIDF(dbName, TestUtils.getDBConfig()); instance.fit(trainingData, param); instance = null; instance = new TFIDF(dbName, TestUtils.getDBConfig()); instance.transform(trainingData); Set<Object> expResult = new HashSet<>(Arrays.asList("important1", "important2", "important3")); Set<Object> result = trainingData.getColumns().keySet(); assertEquals(expResult, result); instance.erase(); } #location 40 #vulnerability type NULL_DEREFERENCE
#fixed code @Test public void testSelectFeatures() { TestUtils.log(this.getClass(), "selectFeatures"); RandomValue.setRandomGenerator(new Random(42)); String dbName = "JUnitChisquareFeatureSelection"; TFIDF.TrainingParameters param = new TFIDF.TrainingParameters(); param.setBinarized(false); param.setMaxFeatures(3); Dataset trainingData = new Dataset(TestUtils.getDBConfig()); AssociativeArray xData1 = new AssociativeArray(); xData1.put("important1", 2.0); xData1.put("important2", 3.0); xData1.put("stopword1", 10.0); xData1.put("stopword2", 4.0); xData1.put("stopword3", 8.0); trainingData.add(new Record(xData1, null)); AssociativeArray xData2 = new AssociativeArray(); xData2.put("important1", 2.0); xData2.put("important3", 5.0); xData2.put("stopword1", 10.0); xData2.put("stopword2", 2.0); xData2.put("stopword3", 4.0); trainingData.add(new Record(xData2, null)); AssociativeArray xData3 = new AssociativeArray(); xData3.put("important2", 2.0); xData3.put("important3", 5.0); xData3.put("stopword1", 10.0); xData3.put("stopword2", 2.0); xData3.put("stopword3", 4.0); trainingData.add(new Record(xData3, null)); TFIDF instance = new TFIDF(dbName, TestUtils.getDBConfig()); instance.fit(trainingData, param); instance = null; instance = new TFIDF(dbName, TestUtils.getDBConfig()); instance.transform(trainingData); Set<Object> expResult = new HashSet<>(Arrays.asList("important1", "important2", "important3")); Set<Object> result = trainingData.getColumns().keySet(); assertEquals(expResult, result); instance.erase(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private double calculateError(Dataframe trainingData, Map<List<Object>, Double> thitas) { //The cost function as described on http://ufldl.stanford.edu/wiki/index.php/Softmax_Regression //It is optimized for speed to reduce the amount of loops double error=0.0; for(Record r : trainingData) { AssociativeArray classProbabilities = hypothesisFunction(r.getX(), thitas); Double score = classProbabilities.getDouble(r.getY()); error+=Math.log(score); //no need to loop through the categories. Just grab the one that we are interested in } return -error/kb().getModelParameters().getN(); } #location 9 #vulnerability type NULL_DEREFERENCE
#fixed code private double calculateError(Dataframe trainingData, Map<List<Object>, Double> thitas) { //The cost function as described on http://ufldl.stanford.edu/wiki/index.php/Softmax_Regression //It is optimized for speed to reduce the amount of loops double error = StreamMethods.stream(trainingData.stream(), isParallelized()).mapToDouble(r -> { AssociativeArray classProbabilities = hypothesisFunction(r.getX(), thitas); Double score = classProbabilities.getDouble(r.getY()); return Math.log(score); //no need to loop through the categories. Just grab the one that we are interested in }).sum(); return -error/kb().getModelParameters().getN(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override protected void predictDataset(Dataframe newData) { Map<List<Object>, Double> similarities = knowledgeBase.getModelParameters().getSimilarities(); //generate recommendation for each record in the list for(Map.Entry<Integer, Record> e : newData.entries()) { Integer rId = e.getKey(); Record r = e.getValue(); Map<Object, Object> recommendations = new HashMap<>(); Map<Object, Double> simSums = new HashMap<>(); for(Map.Entry<Object, Object> entry : r.getX().entrySet()) { Object row = entry.getKey(); Double score = TypeInference.toDouble(entry.getValue()); //Since we can't use 2D Maps due to mongo, we are forced to loop //the whole similarities map which is very inefficient. for(Map.Entry<List<Object>, Double> entry2 : similarities.entrySet()) { List<Object> tpk = entry2.getKey(); if(!tpk.get(0).equals(row)) { continue; //filter the irrelevant two pair key combinations that do not include the row } Object column = tpk.get(1); if(r.getX().containsKey(column)) { continue; // they already rated this } Double previousRecValue = TypeInference.toDouble(recommendations.get(column)); Double previousSimsumValue = simSums.get(column); if(previousRecValue==null) { previousRecValue=0.0; previousSimsumValue=0.0; } Double similarity = entry2.getValue(); recommendations.put(column, previousRecValue+similarity*score); simSums.put(column, previousSimsumValue+similarity); } } for(Map.Entry<Object, Object> entry : recommendations.entrySet()) { Object column = entry.getKey(); Double score = TypeInference.toDouble(entry.getValue()); recommendations.put(column, score/simSums.get(column)); } simSums = null; if(!recommendations.isEmpty()) { //sort recommendation by popularity recommendations = MapFunctions.sortNumberMapByValueDescending(recommendations); newData._unsafe_set(rId, new Record(r.getX(), r.getY(), recommendations.keySet().iterator().next(), new AssociativeArray(recommendations))); } } } #location 12 #vulnerability type NULL_DEREFERENCE
#fixed code @Override protected void predictDataset(Dataframe newData) { _predictDataset(newData, false); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private double calculateError(Dataframe trainingData, Map<Object, Object> previousThitaMapping, Map<Object, Double> weights, Map<Object, Double> thitas) { double error=0.0; for(Record r : trainingData) { double xTw = xTw(r.getX(), weights); Object theClass = r.getY(); Object previousClass = previousThitaMapping.get(theClass); if(previousClass!=null) { error += h(thitas.get(previousClass)-xTw); } error += h(xTw-thitas.get(theClass)); } return error/kb().getModelParameters().getN(); } #location 15 #vulnerability type NULL_DEREFERENCE
#fixed code private double calculateError(Dataframe trainingData, Map<Object, Object> previousThitaMapping, Map<Object, Double> weights, Map<Object, Double> thitas) { double error = StreamMethods.stream(trainingData.stream(), isParallelized()).mapToDouble(r -> { double e=0.0; double xTw = xTw(r.getX(), weights); Object theClass = r.getY(); Object previousClass = previousThitaMapping.get(theClass); if(previousClass!=null) { e += h(thitas.get(previousClass)-xTw); } e += h(xTw-thitas.get(theClass)); return e; }).sum(); return error/kb().getModelParameters().getN(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected static void extractDummies(Dataset data, Map<Object, Object> referenceLevels) { Map<Object, Dataset.ColumnType> columnTypes = data.getColumns(); if(referenceLevels.isEmpty()) { //Training Mode //find the referenceLevels for each categorical variable for(Integer rId: data) { Record r = data.get(rId); for(Map.Entry<Object, Object> entry: r.getX().entrySet()) { Object column = entry.getKey(); if(referenceLevels.containsKey(column)==false) { //already set? if(covert2dummy(columnTypes.get(column))==false) { continue; //only ordinal and categorical are converted into dummyvars } Object value = entry.getValue(); referenceLevels.put(column, value); } } } } //Replace variables with dummy versions for(Integer rId: data) { Record r = data.get(rId); AssociativeArray xData = new AssociativeArray(); xData.putAll(r.getX()); boolean modified = false; for(Object column : r.getX().keySet()) { if(covert2dummy(columnTypes.get(column))==false) { continue; } Object value = xData.get(column); xData.remove(column); //remove the original column modified = true; Object referenceLevel= referenceLevels.get(column); if(referenceLevel != null && //not unknown variable !referenceLevel.equals(value)) { //not equal to reference level //create a new column List<Object> newColumn = Arrays.<Object>asList(column,value); //add a new dummy variable for this column-value combination xData.put(newColumn, true); } } if(modified) { r = new Record(xData, r.getY(), r.getYPredicted(), r.getYPredictedProbabilities()); data.set(rId, r); } } //Reset Meta info data.resetMeta(); } #location 28 #vulnerability type NULL_DEREFERENCE
#fixed code protected static void extractDummies(Dataset data, Map<Object, Object> referenceLevels) { Map<Object, Dataset.ColumnType> columnTypes = data.getColumns(); if(referenceLevels.isEmpty()) { //Training Mode //find the referenceLevels for each categorical variable for(Integer rId: data) { Record r = data.get(rId); for(Map.Entry<Object, Object> entry: r.getX().entrySet()) { Object column = entry.getKey(); if(referenceLevels.containsKey(column)==false) { //already set? if(covert2dummy(columnTypes.get(column))==false) { continue; //only ordinal and categorical are converted into dummyvars } Object value = entry.getValue(); referenceLevels.put(column, value); } } } } //Replace variables with dummy versions for(Integer rId: data) { Record r = data.get(rId); AssociativeArray xData = new AssociativeArray(r.getX()); boolean modified = false; for(Object column : r.getX().keySet()) { if(covert2dummy(columnTypes.get(column))==false) { continue; } Object value = xData.get(column); xData.remove(column); //remove the original column modified = true; Object referenceLevel= referenceLevels.get(column); if(referenceLevel != null && //not unknown variable !referenceLevel.equals(value)) { //not equal to reference level //create a new column List<Object> newColumn = Arrays.<Object>asList(column,value); //add a new dummy variable for this column-value combination xData.put(newColumn, true); } } if(modified) { r = new Record(xData, r.getY(), r.getYPredicted(), r.getYPredictedProbabilities()); data.set(rId, r); } } //Reset Meta info data.resetMeta(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static double median(AssociativeArray2D survivalFunction) { Double ApointTi = null; Double BpointTi = null; int n = survivalFunction.size(); if(n==0) { throw new IllegalArgumentException("The provided collection can't be empty."); } for(Map.Entry<Object, AssociativeArray> entry : survivalFunction.entrySet()) { Object ti = entry.getKey(); AssociativeArray row = entry.getValue(); Double Sti = row.getDouble("Sti"); if(Sti==null) { continue; //skip censored } Double point = Double.valueOf(ti.toString()); if(Sti==0.5) { return point; //we found extactly the point } else if(Sti>0.5) { ApointTi=point; //keep the point just before the 0.5 probability } else { BpointTi=point; //keep the first point after the 0.5 probability and exit loop break; } } if(n==1) { return (ApointTi!=null)?ApointTi:BpointTi; } else if(ApointTi == null || BpointTi == null) { throw new IllegalArgumentException("Invalid A and B points."); //we should never get here } double ApointTiValue = TypeInference.toDouble(survivalFunction.get2d(ApointTi.toString(), "Sti")); double BpointTiValue = TypeInference.toDouble(survivalFunction.get2d(BpointTi.toString(), "Sti")); double median=BpointTi-(BpointTiValue-0.5)*(BpointTi-ApointTi)/(BpointTiValue-ApointTiValue); return median; } #location 34 #vulnerability type NULL_DEREFERENCE
#fixed code public static double median(AssociativeArray2D survivalFunction) { Double ApointTi = null; Double BpointTi = null; int n = survivalFunction.size(); if(n==0) { throw new IllegalArgumentException("The provided collection can't be empty."); } for(Map.Entry<Object, AssociativeArray> entry : survivalFunction.entrySet()) { Object ti = entry.getKey(); AssociativeArray row = entry.getValue(); Double Sti = row.getDouble("Sti"); if(Sti==null) { continue; //skip censored } Double point = Double.valueOf(ti.toString()); if(Math.abs(Sti-0.5) < 0.0000001) { return point; //we found extactly the point } else if(Sti>0.5) { ApointTi=point; //keep the point just before the 0.5 probability } else { BpointTi=point; //keep the first point after the 0.5 probability and exit loop break; } } if(n==1) { return (ApointTi!=null)?ApointTi:BpointTi; } else if(ApointTi == null || BpointTi == null) { throw new IllegalArgumentException("Invalid A and B points."); //we should never get here } double ApointTiValue = TypeInference.toDouble(survivalFunction.get2d(ApointTi.toString(), "Sti")); double BpointTiValue = TypeInference.toDouble(survivalFunction.get2d(BpointTi.toString(), "Sti")); double median=BpointTi-(BpointTiValue-0.5)*(BpointTi-ApointTi)/(BpointTiValue-ApointTiValue); return median; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void batchGradientDescent(Dataframe trainingData, Map<List<Object>, Double> newThitas, double learningRate) { //NOTE! This is not the stochastic gradient descent. It is the batch gradient descent optimized for speed (despite it looks more than the stochastic). //Despite the fact that the loops are inverse, the function still changes the values of Thitas at the end of the function. We use the previous thitas //to estimate the costs and only at the end we update the new thitas. ModelParameters modelParameters = kb().getModelParameters(); double multiplier = learningRate/modelParameters.getN(); Map<List<Object>, Double> thitas = modelParameters.getThitas(); Set<Object> classesSet = modelParameters.getClasses(); for(Record r : trainingData) { //mind the fact that we use the previous thitas to estimate the new ones! this is because the thitas must be updated simultaniously AssociativeArray classProbabilities = hypothesisFunction(r.getX(), thitas); for(Object theClass : classesSet) { double error; double score = classProbabilities.getDouble(theClass); if(r.getY().equals(theClass)) { error = 1 - score; } else { error = - score; } double errorMultiplier = multiplier*error; //update the weight of constant List<Object> featureClassTuple = Arrays.<Object>asList(Dataframe.COLUMN_NAME_CONSTANT, theClass); newThitas.put(featureClassTuple, newThitas.get(featureClassTuple)+errorMultiplier); //update the rest of the weights for(Map.Entry<Object, Object> entry : r.getX().entrySet()) { Double value = TypeInference.toDouble(entry.getValue()); Object feature = entry.getKey(); featureClassTuple = Arrays.<Object>asList(feature, theClass); Double thitaWeight = newThitas.get(featureClassTuple); if(thitaWeight!=null) {//ensure that the feature is in the dictionary newThitas.put(featureClassTuple, thitaWeight+errorMultiplier*value); } } } } } #location 17 #vulnerability type NULL_DEREFERENCE
#fixed code private void batchGradientDescent(Dataframe trainingData, Map<List<Object>, Double> newThitas, double learningRate) { //NOTE! This is not the stochastic gradient descent. It is the batch gradient descent optimized for speed (despite it looks more than the stochastic). //Despite the fact that the loops are inverse, the function still changes the values of Thitas at the end of the function. We use the previous thitas //to estimate the costs and only at the end we update the new thitas. ModelParameters modelParameters = kb().getModelParameters(); double multiplier = learningRate/modelParameters.getN(); Map<List<Object>, Double> thitas = modelParameters.getThitas(); Set<Object> classesSet = modelParameters.getClasses(); StreamMethods.stream(trainingData.stream(), isParallelized()).forEach(r -> { //mind the fact that we use the previous thitas to estimate the new ones! this is because the thitas must be updated simultaniously AssociativeArray classProbabilities = hypothesisFunction(r.getX(), thitas); for(Object theClass : classesSet) { double error; double score = classProbabilities.getDouble(theClass); if(r.getY().equals(theClass)) { error = 1 - score; } else { error = - score; } double errorMultiplier = multiplier*error; synchronized(newThitas) { //update the weight of constant List<Object> featureClassTuple = Arrays.<Object>asList(Dataframe.COLUMN_NAME_CONSTANT, theClass); newThitas.put(featureClassTuple, newThitas.get(featureClassTuple)+errorMultiplier); //update the rest of the weights for(Map.Entry<Object, Object> entry : r.getX().entrySet()) { Double value = TypeInference.toDouble(entry.getValue()); Object feature = entry.getKey(); featureClassTuple = Arrays.<Object>asList(feature, theClass); Double thitaWeight = newThitas.get(featureClassTuple); if(thitaWeight!=null) {//ensure that the feature is in the dictionary newThitas.put(featureClassTuple, thitaWeight+errorMultiplier*value); } } } } }); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected static void denormalizeX(Dataset data, Map<Object, Double> minColumnValues, Map<Object, Double> maxColumnValues) { for(Integer rId : data) { Record r = data.get(rId); for(Object column : minColumnValues.keySet()) { Double value = r.getX().getDouble(column); if(value==null) { //if we have a missing value don't perform any denormalization continue; } Double min = minColumnValues.get(column); Double max = maxColumnValues.get(column); if(min.equals(max)) { r.getX().put(column, min); } else { r.getX().put(column, value*(max-min) + min); } } //do nothing for the response variable Y } } #location 5 #vulnerability type NULL_DEREFERENCE
#fixed code protected static void denormalizeX(Dataset data, Map<Object, Double> minColumnValues, Map<Object, Double> maxColumnValues) { for(Integer rId : data) { Record r = data.get(rId); AssociativeArray xData = new AssociativeArray(r.getX()); for(Object column : minColumnValues.keySet()) { Double value = xData.getDouble(column); if(value==null) { //if we have a missing value don't perform any denormalization continue; } Double min = minColumnValues.get(column); Double max = maxColumnValues.get(column); if(min.equals(max)) { xData.put(column, min); } else { xData.put(column, value*(max-min) + min); } } r = new Record(xData, r.getY(), r.getYPredicted(), r.getYPredictedProbabilities()); data.set(rId, r); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected static void extractDummies(Dataset data, Map<Object, Object> referenceLevels) { Map<Object, Dataset.ColumnType> columnTypes = data.getColumns(); if(referenceLevels.isEmpty()) { //Training Mode //find the referenceLevels for each categorical variable for(Integer rId: data) { Record r = data.get(rId); for(Map.Entry<Object, Object> entry: r.getX().entrySet()) { Object column = entry.getKey(); if(referenceLevels.containsKey(column)==false) { //already set? if(covert2dummy(columnTypes.get(column))==false) { continue; //only ordinal and categorical are converted into dummyvars } Object value = entry.getValue(); referenceLevels.put(column, value); } } } } //Replace variables with dummy versions for(Integer rId: data) { Record r = data.get(rId); Set<Object> columns = new HashSet<>(r.getX().keySet()); //TODO: remove this once we make Record immutable for(Object column : columns) { if(covert2dummy(columnTypes.get(column))==false) { continue; } Object value = r.getX().get(column); r.getX().remove(column); //remove the original column Object referenceLevel= referenceLevels.get(column); if(referenceLevel != null && //not unknown variable !referenceLevel.equals(value)) { //not equal to reference level //create a new column List<Object> newColumn = Arrays.<Object>asList(column,value); //add a new dummy variable for this column-value combination r.getX().put(newColumn, true); } } } //Reset Meta info data.resetMeta(); } #location 26 #vulnerability type NULL_DEREFERENCE
#fixed code protected static void extractDummies(Dataset data, Map<Object, Object> referenceLevels) { Map<Object, Dataset.ColumnType> columnTypes = data.getColumns(); if(referenceLevels.isEmpty()) { //Training Mode //find the referenceLevels for each categorical variable for(Integer rId: data) { Record r = data.get(rId); for(Map.Entry<Object, Object> entry: r.getX().entrySet()) { Object column = entry.getKey(); if(referenceLevels.containsKey(column)==false) { //already set? if(covert2dummy(columnTypes.get(column))==false) { continue; //only ordinal and categorical are converted into dummyvars } Object value = entry.getValue(); referenceLevels.put(column, value); } } } } //Replace variables with dummy versions for(Integer rId: data) { Record r = data.get(rId); AssociativeArray xData = new AssociativeArray(); xData.putAll(r.getX()); boolean modified = false; for(Object column : r.getX().keySet()) { if(covert2dummy(columnTypes.get(column))==false) { continue; } Object value = xData.get(column); xData.remove(column); //remove the original column modified = true; Object referenceLevel= referenceLevels.get(column); if(referenceLevel != null && //not unknown variable !referenceLevel.equals(value)) { //not equal to reference level //create a new column List<Object> newColumn = Arrays.<Object>asList(column,value); //add a new dummy variable for this column-value combination xData.put(newColumn, true); } } if(modified) { r = new Record(xData, r.getY(), r.getYPredicted(), r.getYPredictedProbabilities()); data.set(rId, r); } } //Reset Meta info data.resetMeta(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private double calculateError(Dataframe trainingData, Map<Object, Double> thitas) { //The cost function as described on http://ufldl.stanford.edu/wiki/index.php/Softmax_Regression //It is optimized for speed to reduce the amount of loops double error=0.0; for(Map.Entry<Integer, Record> e : trainingData.entries()) { Integer rId = e.getKey(); Record r = e.getValue(); double yPredicted = hypothesisFunction(r.getX(), thitas); trainingData._unsafe_set(rId, new Record(r.getX(), r.getY(), yPredicted, r.getYPredictedProbabilities())); error+=Math.pow(TypeInference.toDouble(r.getY()) -yPredicted, 2); } return error; } #location 11 #vulnerability type NULL_DEREFERENCE
#fixed code private double calculateError(Dataframe trainingData, Map<Object, Double> thitas) { //The cost function as described on http://ufldl.stanford.edu/wiki/index.php/Softmax_Regression //It is optimized for speed to reduce the amount of loops double error = StreamMethods.stream(trainingData.entries(), isParallelized()).mapToDouble(e -> { Integer rId = e.getKey(); Record r = e.getValue(); double yPredicted = hypothesisFunction(r.getX(), thitas); trainingData._unsafe_set(rId, new Record(r.getX(), r.getY(), yPredicted, r.getYPredictedProbabilities())); return Math.pow(TypeInference.toDouble(r.getY()) -yPredicted, 2); }).sum(); return error; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override protected void filterFeatures(Dataframe newData) { ModelParameters modelParameters = kb().getModelParameters(); //convert data into matrix Map<Object, Integer> featureIds= modelParameters.getFeatureIds(); Map<Integer, Integer> recordIdsReference = new HashMap<>(); MatrixDataframe matrixDataset = MatrixDataframe.parseDataset(newData, recordIdsReference, featureIds); RealMatrix X = matrixDataset.getX(); RealMatrix components = new BlockRealMatrix(modelParameters.getComponents()); //multiplying the data with components X = X.multiply(components); for(Map.Entry<Integer, Record> e : newData.entries()) { Integer rId = e.getKey(); Record r = e.getValue(); int rowId = recordIdsReference.get(rId); AssociativeArray xData = new AssociativeArray(); int componentId=0; for(double value : X.getRow(rowId)) { xData.put(componentId, value); ++componentId; } newData._unsafe_set(rId, new Record(xData, r.getY(), r.getYPredicted(), r.getYPredictedProbabilities())); } //recordIdsReference = null; //matrixDataset = null; newData.recalculateMeta(); //call the recalculate because we used _unsafe_set() } #location 21 #vulnerability type NULL_DEREFERENCE
#fixed code @Override protected void filterFeatures(Dataframe newData) { ModelParameters modelParameters = kb().getModelParameters(); //convert data into matrix Map<Object, Integer> featureIds= modelParameters.getFeatureIds(); Map<Integer, Integer> recordIdsReference = new HashMap<>(); MatrixDataframe matrixDataset = MatrixDataframe.parseDataset(newData, recordIdsReference, featureIds); RealMatrix components = new BlockRealMatrix(modelParameters.getComponents()); //multiplying the data with components final RealMatrix X = matrixDataset.getX().multiply(components); StreamMethods.stream(newData.entries(), true).forEach(e -> { Integer rId = e.getKey(); Record r = e.getValue(); int rowId = recordIdsReference.get(rId); AssociativeArray xData = new AssociativeArray(); int componentId=0; for(double value : X.getRow(rowId)) { xData.put(componentId, value); ++componentId; } Record newR = new Record(xData, r.getY(), r.getYPredicted(), r.getYPredictedProbabilities()); synchronized(newData) { newData._unsafe_set(rId, newR); //we call below the recalculateMeta() } }); //recordIdsReference = null; //matrixDataset = null; newData.recalculateMeta(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected static void normalizeX(Dataset data, Map<Object, Double> minColumnValues, Map<Object, Double> maxColumnValues) { for(Integer rId : data) { Record r = data.get(rId); for(Object column : minColumnValues.keySet()) { Double value = r.getX().getDouble(column); if(value==null) { //if we have a missing value don't perform any normalization continue; } Double min = minColumnValues.get(column); Double max = maxColumnValues.get(column); //it is important how we will handle 0 normalized values because //0-valued features are considered inactive. double normalizedValue; if(min.equals(max)) { normalizedValue = (min>0.0)?1.0:0.0; //set it 0.0 ONLY if the feature is always inactive and 1.0 if it has a non-zero value } else { normalizedValue = (value-min)/(max-min); } r.getX().put(column, normalizedValue); } //do nothing for the response variable Y } } #location 5 #vulnerability type NULL_DEREFERENCE
#fixed code protected static void normalizeX(Dataset data, Map<Object, Double> minColumnValues, Map<Object, Double> maxColumnValues) { for(Integer rId : data) { Record r = data.get(rId); AssociativeArray xData = new AssociativeArray(r.getX()); for(Object column : minColumnValues.keySet()) { Double value = xData.getDouble(column); if(value==null) { //if we have a missing value don't perform any normalization continue; } Double min = minColumnValues.get(column); Double max = maxColumnValues.get(column); //it is important how we will handle 0 normalized values because //0-valued features are considered inactive. double normalizedValue; if(min.equals(max)) { normalizedValue = (min>0.0)?1.0:0.0; //set it 0.0 ONLY if the feature is always inactive and 1.0 if it has a non-zero value } else { normalizedValue = (value-min)/(max-min); } xData.put(column, normalizedValue); } r = new Record(xData, r.getY(), r.getYPredicted(), r.getYPredictedProbabilities()); data.set(rId, r); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private void batchGradientDescent(Dataframe trainingData, Map<Object, Double> newThitas, double learningRate) { //NOTE! This is not the stochastic gradient descent. It is the batch gradient descent optimized for speed (despite it looks more than the stochastic). //Despite the fact that the loops are inverse, the function still changes the values of Thitas at the end of the function. We use the previous thitas //to estimate the costs and only at the end we update the new thitas. ModelParameters modelParameters = kb().getModelParameters(); double multiplier = learningRate/modelParameters.getN(); Map<Object, Double> thitas = modelParameters.getThitas(); for(Record r : trainingData) { //mind the fact that we use the previous thitas to estimate the new ones! this is because the thitas must be updated simultaniously double error = TypeInference.toDouble(r.getY()) - hypothesisFunction(r.getX(), thitas); double errorMultiplier = multiplier*error; //update the weight of constant newThitas.put(Dataframe.COLUMN_NAME_CONSTANT, newThitas.get(Dataframe.COLUMN_NAME_CONSTANT)+errorMultiplier); //update the rest of the weights for(Map.Entry<Object, Object> entry : r.getX().entrySet()) { Object feature = entry.getKey(); Double thitaWeight = newThitas.get(feature); if(thitaWeight!=null) {//ensure that the feature is in the supported features Double value = TypeInference.toDouble(entry.getValue()); newThitas.put(feature, thitaWeight+errorMultiplier*value); } } } } #location 12 #vulnerability type NULL_DEREFERENCE
#fixed code private void batchGradientDescent(Dataframe trainingData, Map<Object, Double> newThitas, double learningRate) { //NOTE! This is not the stochastic gradient descent. It is the batch gradient descent optimized for speed (despite it looks more than the stochastic). //Despite the fact that the loops are inverse, the function still changes the values of Thitas at the end of the function. We use the previous thitas //to estimate the costs and only at the end we update the new thitas. ModelParameters modelParameters = kb().getModelParameters(); double multiplier = learningRate/modelParameters.getN(); Map<Object, Double> thitas = modelParameters.getThitas(); StreamMethods.stream(trainingData.stream(), isParallelized()).forEach(r -> { //mind the fact that we use the previous thitas to estimate the new ones! this is because the thitas must be updated simultaniously double error = TypeInference.toDouble(r.getY()) - hypothesisFunction(r.getX(), thitas); double errorMultiplier = multiplier*error; synchronized(newThitas) { //update the weight of constant newThitas.put(Dataframe.COLUMN_NAME_CONSTANT, newThitas.get(Dataframe.COLUMN_NAME_CONSTANT)+errorMultiplier); //update the rest of the weights for(Map.Entry<Object, Object> entry : r.getX().entrySet()) { Object feature = entry.getKey(); Double thitaWeight = newThitas.get(feature); if(thitaWeight!=null) {//ensure that the feature is in the supported features Double value = TypeInference.toDouble(entry.getValue()); newThitas.put(feature, thitaWeight+errorMultiplier*value); } } } }); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void testValidate() { TestUtils.log(this.getClass(), "validate"); /* Example from http://www.inf.u-szeged.hu/~ormandi/ai2/06-naiveBayes-example.pdf FeatureList: - 0: red - 1: yellow - 2: sports - 3: suv - 4: domestic - 5: imported - c1: yes - c2: no */ /* Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, 1)); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 1.0, 0.0}, 0)); */ Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "imported"}, "yes")); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new String[] {"red", "suv", "domestic"}, "no")); /* Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new Double[] {6.1828706420186,5.7573756868964,3.7194701511967}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0681823226512,5.4994335920427,7.598260774876}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9347712436828,5.4589863647794,4.6587268913845}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1069813629983,5.921115575651,7.665687105599}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9953182795041,5.3813051058212,4.705633227596}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0783760936577,6.6463072076332,5.0109935297025}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0405974863951,6.0172698773085,4.0815091858928}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6689207888614,5.5109381657454,7.0542804625253}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9937187866537,6.4408319103207,4.4046856444854}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9208512689985,6.010370724566,4.6630792826876}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3400826388394,5.7159871205456,3.8901061100606}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8899450177292,6.6335062591025,7.466270407311}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7930848368294,6.121479233098,6.2086612909312}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1546336567077,6.1202193287361,6.411489837199}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.6049539003305,5.314204987812,6.3803367987834}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7630585177414,6.7061362744427,6.4682965635637}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1075418561347,5.0370468593078,6.4286988448471}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3249900751422,6.10105001297,4.7809170319702}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8023484226636,5.578491394307,6.3702530215006}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1091269138412,5.7187388181107,7.3842650329697}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3002649209927,5.0482287873343,4.9422287565555}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6440254101277,5.7301408825515,6.5802913832914}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8322111076176,5.6880138718845,5.0367173880252}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9040807353812,5.6987836817972,5.1847910881081}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0154739271227,5.8667543496933,5.9789148970375}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.4957112084988,5.1045566650393,5.6058409392741}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1096521633466,5.6693184214416,5.892561090601}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6318210701391,5.508236458981,5.0636483859177}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0969689300096,6.3298875290182,6.8710593873}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8069724267443,6.1836366935943,6.1960020303823}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1926806160545,5.2772496094702,6.7375095663349}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1971028628896,5.964413302043,7.7204680342574}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1385034444961,6.6248400313873,5.8391276938938}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1831998628525,6.0325025058058,7.6977185235078}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8951808290057,6.603304711465,6.8180268218985}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3122440238728,6.0531060281343,4.4224365625047}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2783817677307,6.3942150216769,7.2907684783884}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2272471512296,6.6799111991675,4.7843643396355}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6407175103402,5.8888396925871,5.2824895523919}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8139716125053,5.6483224812782,4.568174453531}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2988718195236,7.4590049151238,5.5352445748799}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1404209208418,5.4169881251632,5.5863450541689}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8644652789006,6.3154918376245,5.9551586391955}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8803195543058,6.3435253137372,5.943843701854}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9928311828932,5.3193766880792,5.8220723685143}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1097435672278,5.5006055889569,3.8781608591523}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8846093808686,4.7235401361913,5.0518425036622}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8433602724962,6.0653859037127,7.0191775362714}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.5831131094261,5.3852294478299,4.8961304561915}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.4058666376455,5.2412894268349,7.1455296385635}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0051234324626,5.3213175361626,6.0216861380315}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.5553663137282,6.2669360459472,6.2206402812184}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8340669576998,6.6781182902501,5.8984204269338}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9347791023322,5.4802452909775,6.4653752484524}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8909833072147,5.2623434595991,5.3791755536357}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9400729921549,5.8098196932458,4.0384088731906}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2502523432211,5.9944032961881,5.9418802091115}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0761428761265,6.2474116190755,6.833853785467}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.5468977321358,5.7126124370125,4.3521961691686}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3465647036763,5.8816851860945,4.2502417565705}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1221697358491,6.2144075492655,7.7085089590691}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9030782001172,5.9605898083459,5.9069252426976}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8299523567884,5.7812751109493,7.2043848008754}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6415399114384,6.2329735778127,7.2696481125202}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.5474278882388,6.0858766686968,5.6647159225046}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.191867240968,5.700047924973,5.9459960262113}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2994356011964,5.5751252407037,5.1977489724149}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9291933432574,5.5743697859891,3.7103640660386}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2118368664498,5.6971796394812,4.369908745853}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7380730458964,4.9486846412332,6.1456480530407}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0891988827717,5.9108139127106,7.1274220741528}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6070630019256,5.8977689528125,5.7691084577214}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1486425733106,6.5590527678012,5.2942343293296}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9115156951865,6.0969527087377,5.3866024229252}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.789013168715,5.5712302147498,5.036191782813}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0397918839623,5.3019742025928,7.8718248700932}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6916981665013,5.6814186738611,7.4263300866271}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9887253833225,4.9979431803602,6.6371249564583}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.702541446479,6.1730559167328,5.2498375488818}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8840432282277,6.0655147394396,5.9492353487902}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.999128104203,6.2408033612846,5.558802730703}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.029684376149,5.5470199390301,6.5107059265108}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7567006609793,5.0958044041202,5.6511405582835}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8564519179736,5.6612403134453,6.2968577612391}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.882834295167,6.8625455833395,7.014953370327}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1118680612872,6.3029629744374,7.1214369875147}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0756113578828,5.5799709359878,5.4303064980847}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.5493833631208,5.7088703833507,7.5383393003137}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2998008439962,7.4560311038907,5.7089911905026}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8340429825204,6.1752296607779,7.7407659597863}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2859109164953,6.6250024371568,6.6150090413157}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3679319119898,5.7715316831146,6.6692245327512}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.5823929450998,5.9282858135723,6.1386883402384}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.4501572160856,5.7631819454212,8.7102888680765}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8186496798581,6.7598602800308,4.3015811683092}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3599277297021,5.6726995498914,5.463180358736}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.5867715711378,6.3346173186736,6.7460968843459}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.5979307270642,6.0283171237058,6.3324636077049}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0068781369772,6.4870882319889,4.8625555634725}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9123742767694,6.2728860442697,4.6228889382928}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9114996784735,5.311816555657,5.349968883541}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2019708152264,5.0858882065881,5.0645384922994}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.4977451281981,5.2421209307278,5.8834885057182}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.218393659723,5.7641144165087,7.9382408754377}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6886189314735,5.7636384680466,7.6869779182103}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0382013533523,5.5838638969504,4.9845434877273}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.241114925246,5.0202533818745,5.394465714638}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0079745688169,7.0714791396383,4.6729826100714}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.065388082605,6.4675455220282,6.5427530885523}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9323120960672,5.1925424883669,5.9777126134199}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0112497954156,5.630353235371,5.879007017419}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7216330298751,6.015872937258,6.2180858868519}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8841064478995,5.3182371986901,7.0077629844164}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0039072932317,5.2509687766479,5.3177388935244}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9845910168892,5.8462698378069,4.3522407474802}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3392763224238,6.0829823974468,5.9916928181297}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8279894578288,6.2021408806715,7.5168538869832}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9709498775782,4.8855603277167,6.0681108709628}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8697902055499,6.0304691724585,6.1446911849769}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2742195016883,6.8177109490834,4.5668864479215}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1166839706203,6.0636784820868,5.3813576461848}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9789011837755,5.3650590128098,6.7171722451215}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3770462605033,6.1258750033112,4.5131647681379}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1416863361562,6.2777477626852,6.0573318201718}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1057282373488,6.7621442593252,4.6946998814907}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7716087910999,5.8528952592078,5.2664815893667}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1631456802109,6.6134662203997,6.6074221455997}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3479275903967,5.3771878021529,6.0589389154205}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.284589273002,5.3815614036597,5.5349548445798}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3219977226153,6.0431156092993,5.5896965705638}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3157591364362,6.0237161144292,6.4080285273049}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.903253914899,6.1136224253426,7.48483768296}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8732431773974,5.6082621822996,7.1356497296242}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1209284156388,5.7418264662411,6.5493083929412}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8498086629505,5.5302653154501,5.8644497809675}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0535434666145,5.7610693942611,6.0882413800658}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6107678430768,5.5805928574445,5.4349888759432}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2520368806133,6.263973006074,9.1291759829848}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.3538508179779,5.6590470252712,5.6350659673981}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0255627332664,6.1058653159018,4.4087303845845}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2233362501827,6.3810464197447,8.243766358403}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1660035983978,6.1108399303139,5.3970560226254}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9529740141549,5.9844007652459,6.971027279863}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0716107711744,6.480684651565,5.3907948259231}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7449366070152,5.5811120357275,6.0276934328699}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2933423994012,5.7609306815296,4.8540729742962}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0359442559344,6.2985680023342,6.2591899293071}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7986899863131,5.5002448964418,5.0089636664699}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2556739317501,5.8077089215187,4.710868084551}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7137362513749,5.1314536769177,6.0734427805525}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3323674455519,5.4521026568571,7.055564583806}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.1973087658083,5.1808682261725,4.1617504641194}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0558020757286,5.5040944160827,6.2540014131632}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6758278556418,5.7576603932746,6.1878767076912}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.026529583924,5.9381048330907,6.3734528238166}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7397179399181,5.8048807242009,7.6232821162978}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9567252025995,6.5380638632827,6.7968187561527}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.917441324346,6.5492828529787,5.7641215267497}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.204988820253,6.5065316687643,7.3235119370482}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.151144820668,6.5612941264685,5.7508460685111}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1444531316601,6.5971795041354,5.8875152701362}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1154113962297,5.3586362468038,6.1218898915104}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7243442711899,6.528800002848,5.0945290557719}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.114795770031,5.9138806950629,5.1267607679537}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7256674494548,6.6627314597091,4.9354249759526}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9446433936411,5.920358016829,5.843143978288}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9760647650772,5.3846527347115,6.5798376289934}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.885616024317,4.9611891422007,5.8095125705587}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9880112869102,6.4638481568592,5.9229102640685}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0348961849851,5.172275290377,6.8998946820454}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.252774670359,6.9383727222188,5.1533933137128}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6301285505913,6.1872903420061,5.3161697191432}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0317958955658,6.4574853769548,5.3959769366468}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9830357121264,5.3666220751452,6.6669144751462}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.5493251297613,5.8558541259334,4.706007786359}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9409002641873,5.3635157937432,5.7129744603538}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7580742782088,6.3452162587944,7.1475695465714}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1073507574834,5.8309308150228,6.4021250089886}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7707702344914,6.9674449408074,5.9748708660888}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7813166937868,5.9221068612134,5.5280252603265}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7451663570319,5.3037934902919,5.0185231448734}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7527443303066,5.6713937763568,6.4756665731444}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0887891104275,6.4791634244065,7.3470746377138}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9525388336146,6.0452940067749,6.2052693188136}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9205506930854,6.6160319888675,7.217142374417}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2306647095525,6.1162307552529,6.12577347025}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7915552016885,5.6180003120916,6.321511542843}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0310284555403,5.5265947321296,5.1001195822319}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.5097352342064,5.2119337911055,6.7008795564303}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8171546246184,5.6283114794286,7.4353259803969}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2353270084935,6.0669391305257,6.9022951814932}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9989565452882,6.7814541039146,5.8651181490385}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0410270152145,5.725110222046,6.3060791391789}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8375389348488,5.0826501683452,4.8877741843593}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2930124917027,6.525024971863,7.9377511179385}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8987038186529,5.6459564189317,7.0018764873034}, 1)); trainingData.add(Record.newDataVector(new Double[] {7.2896006325834,6.613446027339,6.6884283725624}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9334650213022,6.8991670973849,7.1712572238222}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8600083136836,7.1417944713949,5.192487684397}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.4658557914101,6.8772799527035,6.1950714420403}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7702012670989,6.3958168085858,5.8572976561662}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3015950653445,6.5828386092335,7.2824769575747}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.4548708315457,7.0803503650719,7.3287603654175}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8402188251516,7.1096293050789,8.2734873211558}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7676335153741,6.773239425057,6.287157860831}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9906101284553,7.1316802041888,7.4936457700492}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.721300152701,6.7177135200203,8.3695987801847}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.5986487124024,6.5672419851869,7.9520270049877}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.223022449159,7.4726916874672,8.1808051524543}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9799514555948,6.7823821998878,6.2986622701316}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9658527808744,6.7957118239179,6.2571362305315}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9236062948693,6.571302080783,7.5682873525745}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8083320084326,6.7452658582997,8.6052823767481}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.6573635864881,7.4658126736232,5.5263204378045}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2298561002332,7.4026686937532,6.5583587996356}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3766023993208,6.3369402520483,7.4206067776467}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7290093783824,7.2867535142376,7.085024841031}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9271580698304,8.0738039777066,8.1150201711546}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.5187115523087,6.8496611609025,6.792565501284}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0906146078397,6.8457566408605,7.4405724822327}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0471785891738,7.6373881259663,7.8799233179614}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.11419953324,8.3533652649336,7.1016602680144}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2227837830402,7.5434045357598,6.5986533016281}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.4562171297792,6.8211126052199,9.0922740891376}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8705642227811,6.9957804000319,7.6438471489112}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9472570837192,6.6385798406144,7.386551323208}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8326312867181,7.0529818279653,7.3737889294438}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2862222216025,6.329804130504,6.5851021317129}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.6310661880962,7.8146022285265,5.9343088187423}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2541184948349,5.9161349716328,7.393869608285}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9015230150315,6.7779959001497,7.9093361779378}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0713916657371,6.793206989946,5.3684337053046}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.5474941171649,6.565322451062,6.8663985355406}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0949913482182,7.749973368659,6.8721171654461}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3328196367468,6.1282439727073,6.4521799384862}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1366953394125,6.2466755935989,6.3387630391252}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1048968060985,7.2625014981352,7.4066676217913}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7465182518317,8.0169138229032,5.9496358703476}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0847169852107,7.7225833346812,6.1085070887808}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2335129782332,8.4635851802424,6.6535008858655}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9408305710561,6.6687306806753,6.3448570113423}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9450087246535,6.5798295054896,6.9247884967934}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.181708481768,7.2680481016058,6.4640108954541}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9010147688928,7.1343244293051,7.4626397562887}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2228600251881,7.6998539591012,7.653065799616}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.5974595995611,6.8322504317493,5.494031225718}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2195099912515,7.659653511505,7.1865021340948}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9958712595384,7.1859568893018,6.7056098526004}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8116233688064,7.4819835466422,6.8589509837962}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1654219510218,7.4165942957925,7.8225227392387}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2062365235067,7.0138966011959,7.9661298844337}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9331811653701,6.3496814393874,5.9859706727744}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7066883117174,6.5522445741856,8.3780808889191}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9082978146261,7.3634935905394,7.9368066055576}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0113230793696,6.509507084335,7.6669413506476}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7913632061301,7.8908361395965,7.1011384912787}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3462311642675,7.665761394854,7.8624592053383}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.17634726034,6.7747192005672,6.8955927936644}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0142850769119,5.78351178564,6.9785511084573}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9080297430644,6.1147140110942,6.6061969181297}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2634841810629,7.0253126387135,8.5121486305935}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8727564529947,6.8812126986379,6.8773549717996}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8414161278773,6.620277903959,8.0210014399498}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1470757555993,6.8123260574424,7.5931925628896}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.4706735102713,7.6852042570664,8.0815493893475}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3673845057894,7.3526702652836,7.4192528994299}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1737277721977,7.479916279499,7.0685166626613}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9812847241814,6.9458320799897,6.9437106707303}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2151207752532,6.5696831136256,7.9559478596965}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7109510092203,6.9979180312258,5.1933095959075}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8979048728244,7.5277150193442,8.098814031602}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0044331780519,7.4700774717316,5.0092706316793}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8242393277675,6.2356914457755,6.9440298925742}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7593965968102,5.773344863615,8.0148227020709}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9593729037005,6.6727766281885,7.8245445072225}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1238773651478,7.1056029646632,6.8867251237268}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1773772220742,7.1603442943468,6.2932350830232}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.5591949889946,7.200472086755,6.5052796712858}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2675834792985,6.9378145097336,6.4642393864829}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.856851862534,6.6879206642625,7.5598392695511}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7442378044998,6.9572938493603,7.3314657522249}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7743792268028,6.2559875489659,6.0585951412072}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7663853015674,6.9362569668765,5.4480824331188}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7953529265457,6.5026954610257,6.8753771303905}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2886423663246,7.3344407936369,4.6012555300578}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9554263843192,6.576790231374,6.1714103443465}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9018838810332,7.4791655510729,6.6263609382478}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.979465490051,6.8840949363326,6.7473600155352}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9498343270199,7.3811101508184,7.5325965050147}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7661188822881,6.4655468197436,5.9585973615145}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.287082962018,6.938072531578,8.1753997531446}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.4697063254591,6.8921534723266,5.4558013904167}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9015421948105,6.6137539013097,7.3997643242373}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2157657110377,7.7907292938193,6.6086030991064}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.5008411057771,7.508548197599,5.8254561494804}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0237431902779,6.2298657516075,6.0527858937763}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.871676695163,6.9827177609153,5.0686852812337}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8645502721111,6.3631527982143,6.4934794915341}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.4595873846283,5.7548219972256,7.8614257739118}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9286173308709,7.0044106831989,8.4333834854732}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0327074220997,6.369318857446,8.0637415094454}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1597733245637,6.8127690450547,5.9299282524951}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0869703229675,7.3740271122189,9.1369860625758}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7290224285792,7.3291511278951,7.5919473260157}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2254200511532,7.8353510611855,6.4672598431374}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2589904096373,6.4091920097451,6.6418139937926}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1723691403703,7.9571211039862,6.5282920943782}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2442274713007,6.7475705793233,8.9055985796543}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9954448559315,6.89001012555,6.4752854891375}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0857949841538,7.0840637324381,6.9500854654671}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.068929233065,6.7201043648976,6.0622728218989}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0926165973559,6.460420800164,7.6663641709327}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0432035900674,8.0375139895743,7.0786128797494}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.4804513343171,7.1889993397575,6.8745839400535}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8601220612974,6.7204503734457,6.900815932675}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8900423160348,7.5594482810607,7.2328402729758}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1456096102673,6.8239536772569,7.1466202666233}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3302756965656,6.8932863930459,6.3529774188226}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8950748143114,7.3104698112884,7.6390778085633}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0135356854966,6.5370129131598,7.4962103964879}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1836111037222,6.9545483448113,7.2597768998531}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.6332911248686,7.4960018677465,6.8312898551732}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3395900983986,6.0268083646009,6.8288635954634}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1334028432661,6.21389527505,7.8379723135553}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8327473061495,6.5011200340223,7.2910806339317}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8969901782385,7.4520196661188,5.4963507277322}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2743163742411,7.9888561644529,6.0027947647849}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3108997759342,6.8684576202789,7.1282313565464}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2749685277847,6.7424394723782,6.1545085888075}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2967934814668,7.5418667328919,6.6095811206768}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.5739087628707,7.0052392064965,8.4072849628318}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2222121155321,6.0431802295395,8.9238364982046}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1794241938967,6.9982254530549,6.7254984931736}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0302289588382,7.14166023243,6.9315762492854}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9820113281022,5.7935034272337,7.0294066523991}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9645455489843,7.6077402844664,7.7968083493993}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9129952539303,6.5967037107394,7.1256008705922}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1552661592661,6.0985394719149,7.3662887909425}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0449754886077,7.3966494773888,8.1256119724722}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7508044100226,7.5830613556037,7.1153048138071}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9156582519863,7.1755070521094,7.0595343718707}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0557415357876,7.9457503377101,4.1419929611612}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7658270016202,7.1419510104112,5.7254670990663}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8532440749758,7.0854973997983,7.3044378655792}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8735667607499,6.0215291905753,5.4568383087515}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.392777897596,6.3045779427488,6.2043167752934}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0624560909791,7.0677656788018,5.4193750304802}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0454701901209,7.1134872806425,7.056233198845}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9090685479094,6.8523251049227,6.711063276564}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.836936668378,7.1243875981276,6.5767978253072}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.6045698553446,7.7009372760785,6.667821627095}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0966179841093,7.598528728132,6.6621161111313}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1989233034711,6.5047392548049,6.8041879194924}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8203644871272,7.2326256102209,5.5137093846463}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0475510394002,6.978241555852,8.3907264106639}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.769548172667,7.2821482314694,6.4560709058966}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.140535552698,6.8167378244357,6.8760526597971}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1517814667777,6.8577870020096,6.9918694735597}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0604140173083,6.5911389813594,6.7979759403414}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2184068607948,6.9209718336592,6.4413049167191}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9792427251683,7.0682018988723,5.91137424889}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3237308867967,6.9959448385859,6.7756286426082}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.840147054239,8.2759969079488,8.1350076831157}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2098615194359,7.0116566694649,7.9821862117688}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.6770860137347,6.6911359333678,6.9119014179053}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8355663655277,7.6270837352341,7.1207596451236}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.426915954485,7.0666191083371,6.5111592475697}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1036830266579,6.9782160702673,5.949446617634}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1693644091968,7.3581959314166,7.0195535298491}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2101014067039,7.3178713813678,8.3503271315687}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9317137780587,6.8251899615829,8.1051544743466}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3220467381151,6.9035221408481,5.541112874475}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8882744376381,7.4704667948249,7.6830426943821}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7756939758976,6.9202388348183,7.1984836565873}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.6459143648116,7.1239915428533,5.9169000884945}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1550236720795,6.4596420482374,8.3290623168938}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2864392398371,7.2023704651749,6.356918926052}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9871722200396,7.0203705440059,6.5284138855011}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0621389733275,6.81004058392,7.1626777026503}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3316010312523,7.2276787986986,6.0781171790599}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3981478695059,7.5324608259959,6.2149791888622}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3146272947654,6.8002341621534,7.0470923601104}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0715209838102,7.2432978438497,6.8430880891686}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0422063475157,6.3853005095173,6.1009543375827}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1134002496492,7.2423239810193,6.856019600325}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.5080260485651,6.6195386943707,8.3122429419782}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.6530382520869,7.2810585686343,6.6380353150473}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7913823688853,7.7335610166713,5.8068947107784}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.988582151521,6.4147156643961,7.4603903567205}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9280770155039,6.6177653632587,5.8912085044338}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8177021840048,6.8015659541425,7.7554347744454}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.5758288937734,7.3815636283995,8.1421632261148}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2026571460398,6.5265981973596,5.659201299106}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8849143180156,7.0228945843155,6.2996161629514}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.9723886996846,8.0204134326864,7.6106019686752}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.193843868628,8.0885741157162,8.1705518568149}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.999535083675,8.3518881127715,7.3845693095375}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0816195918711,7.7655243789205,9.0081471569241}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4117006284112,8.29625469063,8.759152597692}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1079047673344,8.4598791410448,8.837134772682}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1675019534045,7.9081477874529,9.0142986482397}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.5198117488886,7.3127084858516,8.1318164118167}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8448440336379,8.7268151468543,7.8794784076323}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9139549385275,8.3557634461561,8.0351732600164}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0627181350061,7.2969342658271,8.2120920164388}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.506903091062,7.6111726388108,7.5895134379455}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.077177744181,7.9963298115548,7.933107407589}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9863713887083,8.1410610023891,7.4736287889543}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8520313689391,8.4161074306974,7.2681408320002}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.5671301991487,7.8107092267884,8.1749703417822}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.4145812368361,8.2453630612937,7.7471457009706}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0907075865671,7.8122172158147,6.6426285874312}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1752964299273,7.9236582127614,7.2822525459805}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4624564788441,7.6545483916647,8.8239637233552}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8182976349307,7.9880018791502,7.8717048826858}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2512462725928,7.5698166174071,6.668505496049}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2192807831103,7.9348445080335,11.220467543462}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.472011138994,7.984168204423,8.770014934503}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9621987024239,8.1574286566716,8.0623609303045}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1528023063519,8.0296220770355,7.3788837002887}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9286946293727,7.3635641640542,9.0611347250865}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.825746642975,7.4123637406257,7.9783223333258}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2051431800104,7.994398362141,7.2483931735998}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9420559636769,8.1724770741691,6.8134675018193}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7880110976429,7.7164270980249,8.1395011762908}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.5875598525645,8.7860901065389,7.1433161771874}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0719123626076,7.6180059937042,6.8337463291405}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9832799039405,7.7255341138264,7.5525255559623}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0222911483204,6.8324795509634,8.4672355867104}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3718133299761,8.1307628557381,9.4990657488866}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.271458701147,8.0747491776138,6.8545161006567}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7502646779537,8.1231999934856,8.3088657020051}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2719994327591,7.5356049210989,8.6458124837528}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9365998601516,8.2065715506605,9.7402395554283}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9907931070035,8.0700128018982,7.5219237747282}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4946509375458,8.0629946978983,6.6846422346571}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3388911951208,9.1441857788448,9.091444579077}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.6193662832615,7.9022503608835,8.6756303290511}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0544976929278,8.0493009493416,8.230392746744}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7492717724336,8.7660670028935,9.1818661807011}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2096481372834,7.5924158989886,9.547767527544}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3134316533765,7.1853996147827,6.895437327111}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4261111117352,8.1570038091217,7.2039546654305}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2778499471585,8.4768611613506,8.4617506659525}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1316466328784,8.0850456641987,7.0787998345564}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8806349025191,9.0086030444804,7.4698447853491}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1481189239408,7.7395079283074,9.5787912247262}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2487536697102,7.1614867742047,9.1411404468163}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1296067408818,8.0473142035061,7.9004336102559}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8752777905207,8.7428646508438,8.4372883296402}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0733037366566,7.7314922446252,9.9579999616278}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.5687740590708,8.2469268677035,8.603564477605}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3230873007585,7.1154778157046,8.3407205995321}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1650039636336,7.9694338009248,9.5518309260429}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1292091512503,7.5436133854481,7.899657309935}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1420100809803,8.1827462690282,8.136727370514}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3281556221486,8.5583666207422,7.8526505516147}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9947444152282,8.6286084661019,8.5127367563059}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2793097937623,7.6724331417046,8.4416463479586}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8731518546961,8.4575024426546,8.2554533001405}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8688495328623,8.5268911687225,8.9781395829489}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0901087523426,7.9159106142724,5.7536725374879}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3017897766752,8.8116462279158,8.2493426622479}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9889388038907,7.9598700659368,7.2139095248089}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0408229066372,7.6968383084999,9.8661034719709}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7570114771498,8.6194225241094,8.2300373969143}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9739306602973,7.8859169318111,9.2141490476528}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4617285715211,8.0239375203791,8.298602834294}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.6467358631311,8.4064264999763,8.1490181831319}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9480677744568,7.7325204958552,8.5560172093937}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2986818996905,8.0974532928422,7.6774535297997}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8384281490624,8.0076995324654,5.8074823198756}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0449464117542,8.5066219286904,8.8324521715549}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7151109155374,8.1299637097493,6.8103750173971}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.972622221351,8.1886871178258,8.625516370799}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9110538941751,7.4958862167835,7.1595089434679}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.5798125339899,7.1112641845395,7.8443755847766}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7515062590352,7.9393287451403,8.713403289568}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7446631843531,6.7830429462542,7.4133739694283}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2463107324535,7.5394150324116,6.1549597922097}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2476162362818,7.8053552616151,8.1912250266325}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7110233320402,8.5502844819264,7.6860642253745}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8653383685308,8.2236789552747,8.98165525399}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.082293797456,8.0944904460719,7.2064915417135}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3489536145594,7.890515244801,9.2102908056106}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.682370201539,7.5476022156947,8.2522115223243}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.6891807443479,7.6611848675331,6.6401102405233}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1089016083718,7.5037075274979,7.4354046731874}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9213803643339,7.7817454761291,7.2730266275527}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1511262512385,8.2576671031453,8.1776176214216}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1937061428818,7.9369162228622,8.9724716594648}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4321741450853,8.5447298373033,8.4515496382593}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2127297358368,8.1261234648263,7.1630387119843}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8815184211839,7.5893285284446,8.3490934261551}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9477977320436,7.6457012929214,10.207013764623}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9356171844589,7.977989825723,7.344661305385}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7257663301693,7.6932782174709,7.2091664823905}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8782496737532,7.2649337208901,7.9880532205509}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4523275609233,7.5520709442943,8.7012564298143}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.784746829403,7.7736623560565,9.2313465353304}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9113827797734,8.1007919917083,7.7111059021462}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.7472954847321,7.3517050737278,8.0503652937436}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0824168081643,8.1036883810615,7.8860852395807}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.866191772936,8.4927858137158,6.6785368038763}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.101791447859,7.7811225032052,7.2717782644557}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2063851828224,7.4352169117001,8.8423544950304}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1322061693537,7.7642487395609,7.6469452440442}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1194492973571,8.2134152374437,10.10430560278}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9413063231214,7.79161820545,6.0366098539621}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1849479383475,8.0911715803797,6.9261826156551}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9299888394007,7.2484446879071,6.8795832124238}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.147202969752,7.1873867258477,9.4644427785961}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.6321300783343,8.1450678951637,6.5401638187864}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9090752423803,7.7712724949476,9.3456721698573}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2367718562181,8.4032571563061,9.3767463918425}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0835817256082,7.582406878413,8.0915756618119}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1646420746198,7.5482147469401,7.7618329036261}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9095576861373,8.2433163962411,8.4980288596759}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0711931069571,7.530134848026,7.6943011549827}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9987751276247,7.4158548288211,6.4750835408845}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0910780082279,7.4572804711381,7.8240799722108}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1112688951913,7.9705032910958,7.2554372067856}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0515753289697,8.1928137905086,7.4759472433034}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.7153047886352,8.6689186954059,9.6946240506407}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1685132442628,7.8774301404136,6.9731522205175}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.6311115601441,7.5941419910437,9.7145148523024}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9351375056492,7.5462274934744,6.6737001896418}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0889609828249,8.0912600607939,7.8321607983497}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1597364886607,7.9366742049271,10.342782003528}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.923346208187,7.2016457489945,7.7023065233103}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9815464631402,7.8561789251639,8.0946764586651}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4662656037447,7.7895996740698,7.7093248468311}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3224179829047,7.2643479104808,9.8132586727186}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0410823597258,8.6505892929699,7.1920163633085}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2584304478173,7.725375496373,8.9006539082442}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7735170752483,8.1510998670964,7.837781785741}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4056892532954,8.1153278606083,7.4240140401365}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0722081383288,7.8318168048421,6.9569944449399}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2966741913553,8.3005981823115,8.3744672362022}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.421009928787,7.8962742793042,8.5391944176122}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1483108973482,6.9351740674042,7.8086819482273}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.6566414933676,8.0544173254459,7.442816188815}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.2910949320926,8.6628782145729,8.0317337809795}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0983962236663,7.8892866785424,6.6933883917699}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.659121148925,7.7945835409611,8.2055029585253}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0402835136937,7.5310038548664,7.3553442515004}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9685963826727,7.494583181862,7.3539299870935}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.5563720430564,7.8506166155065,7.5366221368295}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.525943542888,6.8627376399596,6.8412357977848}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9647350109685,6.6519708553395,10.323808434413}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8392319818433,7.2463310700812,9.0106120856451}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0721151053279,7.6581027841812,7.2307929505801}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3187333993971,6.9348314495963,5.3388672322072}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9892691054185,7.4330283943974,8.8988707525753}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0496482840834,7.7400244851224,6.2328499008487}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9729868720067,8.9150295296002,5.9858346669359}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.6464924423145,8.7252602820324,7.3025663155915}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3447766957906,8.3035244366488,7.1241103003035}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0954664511006,7.5033284931428,8.8141375054049}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8404251876638,8.4540404594376,7.7371902002214}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.792768199615,7.7502228690206,10.501602347531}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.200738264868,7.8293091221365,8.01653739354}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3320220735711,8.1606690708477,6.383390393029}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1368661781047,8.6844700874318,7.9280871578848}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0583412523245,7.1333732091568,6.7959649469107}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4343812776424,8.1784740547851,7.4450585142654}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.5722310323602,7.2931265419769,9.3401535444179}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7750257408666,7.647074259843,7.5384671094132}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.59972037597,8.5890661256682,10.199241851282}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1432365691796,8.2437436067096,7.3052661523708}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2586708889866,7.8951339101955,7.8437497979855}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1290022593116,8.8765477636939,8.5088695610568}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8811761101025,8.0058725923254,7.7675604765912}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9344024519213,8.6240430189244,8.0938229883623}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2586770653842,8.2261132808173,6.4893051058006}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1658418024318,8.2827424435886,8.1626360192602}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1460721202288,8.6936750520598,8.4212378827247}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7414441989093,7.8499896240054,7.6800349596772}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1750233258425,8.2771328235309,7.1344772529082}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1769271947542,7.8930841367002,9.2388953949076}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0801176973362,7.2683438671279,8.7627502442859}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7856087113423,7.5536791574565,7.5297983810941}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2460269432082,8.0140518094791,7.4481328834547}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8308449159799,8.5044817361924,8.7901830233474}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0162484899457,8.012583475483,8.0957827405008}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2379515843322,7.865996967794,8.8458471985886}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8882830518879,8.1927479954944,7.5850995949985}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9139894964632,7.3082982914122,7.1097251375415}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.130974051665,8.8876275829208,8.2236483466709}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7305016845479,7.5346585277436,7.5448783986455}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8617017276583,8.7009667090353,8.737159946423}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8503617220677,8.2404927576352,8.7381291679246}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8623885395277,8.3614336317246,5.6847052467107}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0681462705452,7.6734454222732,8.3414789681074}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1827031138615,6.8533568619312,7.1188854529688}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.6214685846329,8.0218759456459,9.2140622324487}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8872168038128,6.9977919468999,8.1205596528281}, 3)); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new Double[] {6.34569812276338,6.76262401884614,6.08305530880784}, 1)); validationData.add(Record.newDataVector(new Double[] {5.92085126899850,6.01037072456601,4.66307928268761}, 1)); validationData.add(Record.newDataVector(new Double[] {7.18606367787857,6.64194264491917,4.41233885708698}, 2)); validationData.add(Record.newDataVector(new Double[] {7.83232073356316,8.76007761528955,7.05235518409310}, 3)); */ String dbName = "JUnitClassifier"; SimpleDummyVariableExtractor df = new SimpleDummyVariableExtractor(dbName, TestUtils.getDBConfig()); df.fit_transform(trainingData, new SimpleDummyVariableExtractor.TrainingParameters()); df.transform(validationData); SoftMaxRegression instance = new SoftMaxRegression(dbName, TestUtils.getDBConfig()); SoftMaxRegression.TrainingParameters param = new SoftMaxRegression.TrainingParameters(); param.setTotalIterations(2000); instance.fit(trainingData, param); instance = null; instance = new SoftMaxRegression(dbName, TestUtils.getDBConfig()); instance.validate(validationData); df.denormalize(trainingData); df.denormalize(validationData); df.erase(); Map<Integer, Object> expResult = new HashMap<>(); Map<Integer, Object> result = new HashMap<>(); for(Record r : validationData) { expResult.put(r.getId(), r.getY()); result.put(r.getId(), r.getYPredicted()); } assertEquals(expResult, result); instance.erase(); } #location 661 #vulnerability type NULL_DEREFERENCE
#fixed code @Test public void testValidate() { TestUtils.log(this.getClass(), "validate"); /* Example from http://www.inf.u-szeged.hu/~ormandi/ai2/06-naiveBayes-example.pdf FeatureList: - 0: red - 1: yellow - 2: sports - 3: suv - 4: domestic - 5: imported - c1: yes - c2: no */ /* Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 1.0, 0.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 0.0, 1.0}, 1)); trainingData.add(Record.newDataVector(new Double[] {0.0, 1.0, 0.0, 1.0, 1.0, 0.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 0.0, 1.0}, 0)); trainingData.add(Record.newDataVector(new Double[] {1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, 1)); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new Double[] {1.0, 0.0, 0.0, 1.0, 1.0, 0.0}, 0)); */ Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "domestic"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "sports", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "imported"}, "yes")); trainingData.add(Record.newDataVector(new String[] {"yellow", "suv", "domestic"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "suv", "imported"}, "no")); trainingData.add(Record.newDataVector(new String[] {"red", "sports", "imported"}, "yes")); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new String[] {"red", "suv", "domestic"}, "no")); /* Dataset trainingData = new Dataset(); trainingData.add(Record.newDataVector(new Double[] {6.1828706420186,5.7573756868964,3.7194701511967}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0681823226512,5.4994335920427,7.598260774876}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9347712436828,5.4589863647794,4.6587268913845}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1069813629983,5.921115575651,7.665687105599}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9953182795041,5.3813051058212,4.705633227596}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0783760936577,6.6463072076332,5.0109935297025}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0405974863951,6.0172698773085,4.0815091858928}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6689207888614,5.5109381657454,7.0542804625253}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9937187866537,6.4408319103207,4.4046856444854}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9208512689985,6.010370724566,4.6630792826876}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3400826388394,5.7159871205456,3.8901061100606}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8899450177292,6.6335062591025,7.466270407311}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7930848368294,6.121479233098,6.2086612909312}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1546336567077,6.1202193287361,6.411489837199}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.6049539003305,5.314204987812,6.3803367987834}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7630585177414,6.7061362744427,6.4682965635637}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1075418561347,5.0370468593078,6.4286988448471}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3249900751422,6.10105001297,4.7809170319702}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8023484226636,5.578491394307,6.3702530215006}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1091269138412,5.7187388181107,7.3842650329697}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3002649209927,5.0482287873343,4.9422287565555}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6440254101277,5.7301408825515,6.5802913832914}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8322111076176,5.6880138718845,5.0367173880252}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9040807353812,5.6987836817972,5.1847910881081}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0154739271227,5.8667543496933,5.9789148970375}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.4957112084988,5.1045566650393,5.6058409392741}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1096521633466,5.6693184214416,5.892561090601}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6318210701391,5.508236458981,5.0636483859177}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0969689300096,6.3298875290182,6.8710593873}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8069724267443,6.1836366935943,6.1960020303823}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1926806160545,5.2772496094702,6.7375095663349}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1971028628896,5.964413302043,7.7204680342574}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1385034444961,6.6248400313873,5.8391276938938}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1831998628525,6.0325025058058,7.6977185235078}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8951808290057,6.603304711465,6.8180268218985}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3122440238728,6.0531060281343,4.4224365625047}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2783817677307,6.3942150216769,7.2907684783884}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2272471512296,6.6799111991675,4.7843643396355}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6407175103402,5.8888396925871,5.2824895523919}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8139716125053,5.6483224812782,4.568174453531}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2988718195236,7.4590049151238,5.5352445748799}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1404209208418,5.4169881251632,5.5863450541689}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8644652789006,6.3154918376245,5.9551586391955}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8803195543058,6.3435253137372,5.943843701854}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9928311828932,5.3193766880792,5.8220723685143}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1097435672278,5.5006055889569,3.8781608591523}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8846093808686,4.7235401361913,5.0518425036622}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8433602724962,6.0653859037127,7.0191775362714}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.5831131094261,5.3852294478299,4.8961304561915}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.4058666376455,5.2412894268349,7.1455296385635}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0051234324626,5.3213175361626,6.0216861380315}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.5553663137282,6.2669360459472,6.2206402812184}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8340669576998,6.6781182902501,5.8984204269338}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9347791023322,5.4802452909775,6.4653752484524}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8909833072147,5.2623434595991,5.3791755536357}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9400729921549,5.8098196932458,4.0384088731906}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2502523432211,5.9944032961881,5.9418802091115}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0761428761265,6.2474116190755,6.833853785467}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.5468977321358,5.7126124370125,4.3521961691686}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3465647036763,5.8816851860945,4.2502417565705}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1221697358491,6.2144075492655,7.7085089590691}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9030782001172,5.9605898083459,5.9069252426976}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8299523567884,5.7812751109493,7.2043848008754}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6415399114384,6.2329735778127,7.2696481125202}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.5474278882388,6.0858766686968,5.6647159225046}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.191867240968,5.700047924973,5.9459960262113}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2994356011964,5.5751252407037,5.1977489724149}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9291933432574,5.5743697859891,3.7103640660386}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2118368664498,5.6971796394812,4.369908745853}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7380730458964,4.9486846412332,6.1456480530407}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0891988827717,5.9108139127106,7.1274220741528}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6070630019256,5.8977689528125,5.7691084577214}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1486425733106,6.5590527678012,5.2942343293296}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9115156951865,6.0969527087377,5.3866024229252}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.789013168715,5.5712302147498,5.036191782813}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0397918839623,5.3019742025928,7.8718248700932}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6916981665013,5.6814186738611,7.4263300866271}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9887253833225,4.9979431803602,6.6371249564583}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.702541446479,6.1730559167328,5.2498375488818}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8840432282277,6.0655147394396,5.9492353487902}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.999128104203,6.2408033612846,5.558802730703}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.029684376149,5.5470199390301,6.5107059265108}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7567006609793,5.0958044041202,5.6511405582835}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8564519179736,5.6612403134453,6.2968577612391}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.882834295167,6.8625455833395,7.014953370327}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1118680612872,6.3029629744374,7.1214369875147}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0756113578828,5.5799709359878,5.4303064980847}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.5493833631208,5.7088703833507,7.5383393003137}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2998008439962,7.4560311038907,5.7089911905026}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8340429825204,6.1752296607779,7.7407659597863}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2859109164953,6.6250024371568,6.6150090413157}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3679319119898,5.7715316831146,6.6692245327512}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.5823929450998,5.9282858135723,6.1386883402384}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.4501572160856,5.7631819454212,8.7102888680765}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8186496798581,6.7598602800308,4.3015811683092}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3599277297021,5.6726995498914,5.463180358736}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.5867715711378,6.3346173186736,6.7460968843459}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.5979307270642,6.0283171237058,6.3324636077049}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0068781369772,6.4870882319889,4.8625555634725}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9123742767694,6.2728860442697,4.6228889382928}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9114996784735,5.311816555657,5.349968883541}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2019708152264,5.0858882065881,5.0645384922994}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.4977451281981,5.2421209307278,5.8834885057182}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.218393659723,5.7641144165087,7.9382408754377}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6886189314735,5.7636384680466,7.6869779182103}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0382013533523,5.5838638969504,4.9845434877273}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.241114925246,5.0202533818745,5.394465714638}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0079745688169,7.0714791396383,4.6729826100714}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.065388082605,6.4675455220282,6.5427530885523}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9323120960672,5.1925424883669,5.9777126134199}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0112497954156,5.630353235371,5.879007017419}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7216330298751,6.015872937258,6.2180858868519}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8841064478995,5.3182371986901,7.0077629844164}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0039072932317,5.2509687766479,5.3177388935244}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9845910168892,5.8462698378069,4.3522407474802}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3392763224238,6.0829823974468,5.9916928181297}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8279894578288,6.2021408806715,7.5168538869832}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9709498775782,4.8855603277167,6.0681108709628}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8697902055499,6.0304691724585,6.1446911849769}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2742195016883,6.8177109490834,4.5668864479215}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1166839706203,6.0636784820868,5.3813576461848}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9789011837755,5.3650590128098,6.7171722451215}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3770462605033,6.1258750033112,4.5131647681379}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1416863361562,6.2777477626852,6.0573318201718}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1057282373488,6.7621442593252,4.6946998814907}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7716087910999,5.8528952592078,5.2664815893667}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1631456802109,6.6134662203997,6.6074221455997}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3479275903967,5.3771878021529,6.0589389154205}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.284589273002,5.3815614036597,5.5349548445798}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3219977226153,6.0431156092993,5.5896965705638}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3157591364362,6.0237161144292,6.4080285273049}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.903253914899,6.1136224253426,7.48483768296}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8732431773974,5.6082621822996,7.1356497296242}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1209284156388,5.7418264662411,6.5493083929412}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8498086629505,5.5302653154501,5.8644497809675}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0535434666145,5.7610693942611,6.0882413800658}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6107678430768,5.5805928574445,5.4349888759432}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2520368806133,6.263973006074,9.1291759829848}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.3538508179779,5.6590470252712,5.6350659673981}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0255627332664,6.1058653159018,4.4087303845845}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2233362501827,6.3810464197447,8.243766358403}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1660035983978,6.1108399303139,5.3970560226254}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9529740141549,5.9844007652459,6.971027279863}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0716107711744,6.480684651565,5.3907948259231}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7449366070152,5.5811120357275,6.0276934328699}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2933423994012,5.7609306815296,4.8540729742962}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0359442559344,6.2985680023342,6.2591899293071}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7986899863131,5.5002448964418,5.0089636664699}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2556739317501,5.8077089215187,4.710868084551}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7137362513749,5.1314536769177,6.0734427805525}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.3323674455519,5.4521026568571,7.055564583806}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.1973087658083,5.1808682261725,4.1617504641194}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0558020757286,5.5040944160827,6.2540014131632}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6758278556418,5.7576603932746,6.1878767076912}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.026529583924,5.9381048330907,6.3734528238166}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7397179399181,5.8048807242009,7.6232821162978}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9567252025995,6.5380638632827,6.7968187561527}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.917441324346,6.5492828529787,5.7641215267497}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.204988820253,6.5065316687643,7.3235119370482}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.151144820668,6.5612941264685,5.7508460685111}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1444531316601,6.5971795041354,5.8875152701362}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1154113962297,5.3586362468038,6.1218898915104}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7243442711899,6.528800002848,5.0945290557719}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.114795770031,5.9138806950629,5.1267607679537}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7256674494548,6.6627314597091,4.9354249759526}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9446433936411,5.920358016829,5.843143978288}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9760647650772,5.3846527347115,6.5798376289934}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.885616024317,4.9611891422007,5.8095125705587}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9880112869102,6.4638481568592,5.9229102640685}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0348961849851,5.172275290377,6.8998946820454}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.252774670359,6.9383727222188,5.1533933137128}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.6301285505913,6.1872903420061,5.3161697191432}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0317958955658,6.4574853769548,5.3959769366468}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9830357121264,5.3666220751452,6.6669144751462}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.5493251297613,5.8558541259334,4.706007786359}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9409002641873,5.3635157937432,5.7129744603538}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7580742782088,6.3452162587944,7.1475695465714}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.1073507574834,5.8309308150228,6.4021250089886}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7707702344914,6.9674449408074,5.9748708660888}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7813166937868,5.9221068612134,5.5280252603265}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7451663570319,5.3037934902919,5.0185231448734}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7527443303066,5.6713937763568,6.4756665731444}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0887891104275,6.4791634244065,7.3470746377138}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9525388336146,6.0452940067749,6.2052693188136}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9205506930854,6.6160319888675,7.217142374417}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2306647095525,6.1162307552529,6.12577347025}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.7915552016885,5.6180003120916,6.321511542843}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0310284555403,5.5265947321296,5.1001195822319}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.5097352342064,5.2119337911055,6.7008795564303}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8171546246184,5.6283114794286,7.4353259803969}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2353270084935,6.0669391305257,6.9022951814932}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.9989565452882,6.7814541039146,5.8651181490385}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.0410270152145,5.725110222046,6.3060791391789}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8375389348488,5.0826501683452,4.8877741843593}, 1)); trainingData.add(Record.newDataVector(new Double[] {6.2930124917027,6.525024971863,7.9377511179385}, 1)); trainingData.add(Record.newDataVector(new Double[] {5.8987038186529,5.6459564189317,7.0018764873034}, 1)); trainingData.add(Record.newDataVector(new Double[] {7.2896006325834,6.613446027339,6.6884283725624}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9334650213022,6.8991670973849,7.1712572238222}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8600083136836,7.1417944713949,5.192487684397}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.4658557914101,6.8772799527035,6.1950714420403}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7702012670989,6.3958168085858,5.8572976561662}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3015950653445,6.5828386092335,7.2824769575747}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.4548708315457,7.0803503650719,7.3287603654175}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8402188251516,7.1096293050789,8.2734873211558}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7676335153741,6.773239425057,6.287157860831}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9906101284553,7.1316802041888,7.4936457700492}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.721300152701,6.7177135200203,8.3695987801847}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.5986487124024,6.5672419851869,7.9520270049877}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.223022449159,7.4726916874672,8.1808051524543}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9799514555948,6.7823821998878,6.2986622701316}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9658527808744,6.7957118239179,6.2571362305315}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9236062948693,6.571302080783,7.5682873525745}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8083320084326,6.7452658582997,8.6052823767481}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.6573635864881,7.4658126736232,5.5263204378045}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2298561002332,7.4026686937532,6.5583587996356}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3766023993208,6.3369402520483,7.4206067776467}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7290093783824,7.2867535142376,7.085024841031}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9271580698304,8.0738039777066,8.1150201711546}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.5187115523087,6.8496611609025,6.792565501284}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0906146078397,6.8457566408605,7.4405724822327}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0471785891738,7.6373881259663,7.8799233179614}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.11419953324,8.3533652649336,7.1016602680144}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2227837830402,7.5434045357598,6.5986533016281}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.4562171297792,6.8211126052199,9.0922740891376}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8705642227811,6.9957804000319,7.6438471489112}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9472570837192,6.6385798406144,7.386551323208}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8326312867181,7.0529818279653,7.3737889294438}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2862222216025,6.329804130504,6.5851021317129}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.6310661880962,7.8146022285265,5.9343088187423}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2541184948349,5.9161349716328,7.393869608285}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9015230150315,6.7779959001497,7.9093361779378}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0713916657371,6.793206989946,5.3684337053046}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.5474941171649,6.565322451062,6.8663985355406}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0949913482182,7.749973368659,6.8721171654461}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3328196367468,6.1282439727073,6.4521799384862}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1366953394125,6.2466755935989,6.3387630391252}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1048968060985,7.2625014981352,7.4066676217913}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7465182518317,8.0169138229032,5.9496358703476}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0847169852107,7.7225833346812,6.1085070887808}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2335129782332,8.4635851802424,6.6535008858655}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9408305710561,6.6687306806753,6.3448570113423}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9450087246535,6.5798295054896,6.9247884967934}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.181708481768,7.2680481016058,6.4640108954541}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9010147688928,7.1343244293051,7.4626397562887}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2228600251881,7.6998539591012,7.653065799616}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.5974595995611,6.8322504317493,5.494031225718}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2195099912515,7.659653511505,7.1865021340948}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9958712595384,7.1859568893018,6.7056098526004}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8116233688064,7.4819835466422,6.8589509837962}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1654219510218,7.4165942957925,7.8225227392387}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2062365235067,7.0138966011959,7.9661298844337}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9331811653701,6.3496814393874,5.9859706727744}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7066883117174,6.5522445741856,8.3780808889191}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9082978146261,7.3634935905394,7.9368066055576}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0113230793696,6.509507084335,7.6669413506476}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7913632061301,7.8908361395965,7.1011384912787}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3462311642675,7.665761394854,7.8624592053383}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.17634726034,6.7747192005672,6.8955927936644}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0142850769119,5.78351178564,6.9785511084573}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9080297430644,6.1147140110942,6.6061969181297}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2634841810629,7.0253126387135,8.5121486305935}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8727564529947,6.8812126986379,6.8773549717996}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8414161278773,6.620277903959,8.0210014399498}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1470757555993,6.8123260574424,7.5931925628896}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.4706735102713,7.6852042570664,8.0815493893475}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3673845057894,7.3526702652836,7.4192528994299}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1737277721977,7.479916279499,7.0685166626613}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9812847241814,6.9458320799897,6.9437106707303}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2151207752532,6.5696831136256,7.9559478596965}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7109510092203,6.9979180312258,5.1933095959075}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8979048728244,7.5277150193442,8.098814031602}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0044331780519,7.4700774717316,5.0092706316793}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8242393277675,6.2356914457755,6.9440298925742}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7593965968102,5.773344863615,8.0148227020709}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9593729037005,6.6727766281885,7.8245445072225}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1238773651478,7.1056029646632,6.8867251237268}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1773772220742,7.1603442943468,6.2932350830232}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.5591949889946,7.200472086755,6.5052796712858}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2675834792985,6.9378145097336,6.4642393864829}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.856851862534,6.6879206642625,7.5598392695511}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7442378044998,6.9572938493603,7.3314657522249}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7743792268028,6.2559875489659,6.0585951412072}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7663853015674,6.9362569668765,5.4480824331188}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7953529265457,6.5026954610257,6.8753771303905}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2886423663246,7.3344407936369,4.6012555300578}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9554263843192,6.576790231374,6.1714103443465}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9018838810332,7.4791655510729,6.6263609382478}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.979465490051,6.8840949363326,6.7473600155352}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9498343270199,7.3811101508184,7.5325965050147}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7661188822881,6.4655468197436,5.9585973615145}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.287082962018,6.938072531578,8.1753997531446}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.4697063254591,6.8921534723266,5.4558013904167}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9015421948105,6.6137539013097,7.3997643242373}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2157657110377,7.7907292938193,6.6086030991064}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.5008411057771,7.508548197599,5.8254561494804}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0237431902779,6.2298657516075,6.0527858937763}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.871676695163,6.9827177609153,5.0686852812337}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8645502721111,6.3631527982143,6.4934794915341}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.4595873846283,5.7548219972256,7.8614257739118}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9286173308709,7.0044106831989,8.4333834854732}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0327074220997,6.369318857446,8.0637415094454}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1597733245637,6.8127690450547,5.9299282524951}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0869703229675,7.3740271122189,9.1369860625758}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7290224285792,7.3291511278951,7.5919473260157}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2254200511532,7.8353510611855,6.4672598431374}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2589904096373,6.4091920097451,6.6418139937926}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1723691403703,7.9571211039862,6.5282920943782}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2442274713007,6.7475705793233,8.9055985796543}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9954448559315,6.89001012555,6.4752854891375}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0857949841538,7.0840637324381,6.9500854654671}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.068929233065,6.7201043648976,6.0622728218989}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0926165973559,6.460420800164,7.6663641709327}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0432035900674,8.0375139895743,7.0786128797494}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.4804513343171,7.1889993397575,6.8745839400535}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8601220612974,6.7204503734457,6.900815932675}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8900423160348,7.5594482810607,7.2328402729758}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1456096102673,6.8239536772569,7.1466202666233}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3302756965656,6.8932863930459,6.3529774188226}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8950748143114,7.3104698112884,7.6390778085633}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0135356854966,6.5370129131598,7.4962103964879}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1836111037222,6.9545483448113,7.2597768998531}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.6332911248686,7.4960018677465,6.8312898551732}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3395900983986,6.0268083646009,6.8288635954634}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1334028432661,6.21389527505,7.8379723135553}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8327473061495,6.5011200340223,7.2910806339317}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8969901782385,7.4520196661188,5.4963507277322}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2743163742411,7.9888561644529,6.0027947647849}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3108997759342,6.8684576202789,7.1282313565464}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2749685277847,6.7424394723782,6.1545085888075}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2967934814668,7.5418667328919,6.6095811206768}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.5739087628707,7.0052392064965,8.4072849628318}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2222121155321,6.0431802295395,8.9238364982046}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1794241938967,6.9982254530549,6.7254984931736}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0302289588382,7.14166023243,6.9315762492854}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9820113281022,5.7935034272337,7.0294066523991}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9645455489843,7.6077402844664,7.7968083493993}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9129952539303,6.5967037107394,7.1256008705922}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1552661592661,6.0985394719149,7.3662887909425}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0449754886077,7.3966494773888,8.1256119724722}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7508044100226,7.5830613556037,7.1153048138071}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9156582519863,7.1755070521094,7.0595343718707}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0557415357876,7.9457503377101,4.1419929611612}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7658270016202,7.1419510104112,5.7254670990663}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8532440749758,7.0854973997983,7.3044378655792}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8735667607499,6.0215291905753,5.4568383087515}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.392777897596,6.3045779427488,6.2043167752934}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0624560909791,7.0677656788018,5.4193750304802}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0454701901209,7.1134872806425,7.056233198845}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9090685479094,6.8523251049227,6.711063276564}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.836936668378,7.1243875981276,6.5767978253072}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.6045698553446,7.7009372760785,6.667821627095}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0966179841093,7.598528728132,6.6621161111313}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1989233034711,6.5047392548049,6.8041879194924}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8203644871272,7.2326256102209,5.5137093846463}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0475510394002,6.978241555852,8.3907264106639}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.769548172667,7.2821482314694,6.4560709058966}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.140535552698,6.8167378244357,6.8760526597971}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1517814667777,6.8577870020096,6.9918694735597}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0604140173083,6.5911389813594,6.7979759403414}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2184068607948,6.9209718336592,6.4413049167191}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9792427251683,7.0682018988723,5.91137424889}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3237308867967,6.9959448385859,6.7756286426082}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.840147054239,8.2759969079488,8.1350076831157}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2098615194359,7.0116566694649,7.9821862117688}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.6770860137347,6.6911359333678,6.9119014179053}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8355663655277,7.6270837352341,7.1207596451236}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.426915954485,7.0666191083371,6.5111592475697}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1036830266579,6.9782160702673,5.949446617634}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1693644091968,7.3581959314166,7.0195535298491}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2101014067039,7.3178713813678,8.3503271315687}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9317137780587,6.8251899615829,8.1051544743466}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3220467381151,6.9035221408481,5.541112874475}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8882744376381,7.4704667948249,7.6830426943821}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7756939758976,6.9202388348183,7.1984836565873}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.6459143648116,7.1239915428533,5.9169000884945}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1550236720795,6.4596420482374,8.3290623168938}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2864392398371,7.2023704651749,6.356918926052}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9871722200396,7.0203705440059,6.5284138855011}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0621389733275,6.81004058392,7.1626777026503}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3316010312523,7.2276787986986,6.0781171790599}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3981478695059,7.5324608259959,6.2149791888622}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.3146272947654,6.8002341621534,7.0470923601104}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0715209838102,7.2432978438497,6.8430880891686}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.0422063475157,6.3853005095173,6.1009543375827}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.1134002496492,7.2423239810193,6.856019600325}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.5080260485651,6.6195386943707,8.3122429419782}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.6530382520869,7.2810585686343,6.6380353150473}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.7913823688853,7.7335610166713,5.8068947107784}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.988582151521,6.4147156643961,7.4603903567205}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.9280770155039,6.6177653632587,5.8912085044338}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8177021840048,6.8015659541425,7.7554347744454}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.5758288937734,7.3815636283995,8.1421632261148}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.2026571460398,6.5265981973596,5.659201299106}, 2)); trainingData.add(Record.newDataVector(new Double[] {6.8849143180156,7.0228945843155,6.2996161629514}, 2)); trainingData.add(Record.newDataVector(new Double[] {7.9723886996846,8.0204134326864,7.6106019686752}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.193843868628,8.0885741157162,8.1705518568149}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.999535083675,8.3518881127715,7.3845693095375}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0816195918711,7.7655243789205,9.0081471569241}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4117006284112,8.29625469063,8.759152597692}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1079047673344,8.4598791410448,8.837134772682}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1675019534045,7.9081477874529,9.0142986482397}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.5198117488886,7.3127084858516,8.1318164118167}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8448440336379,8.7268151468543,7.8794784076323}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9139549385275,8.3557634461561,8.0351732600164}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0627181350061,7.2969342658271,8.2120920164388}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.506903091062,7.6111726388108,7.5895134379455}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.077177744181,7.9963298115548,7.933107407589}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9863713887083,8.1410610023891,7.4736287889543}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8520313689391,8.4161074306974,7.2681408320002}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.5671301991487,7.8107092267884,8.1749703417822}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.4145812368361,8.2453630612937,7.7471457009706}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0907075865671,7.8122172158147,6.6426285874312}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1752964299273,7.9236582127614,7.2822525459805}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4624564788441,7.6545483916647,8.8239637233552}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8182976349307,7.9880018791502,7.8717048826858}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2512462725928,7.5698166174071,6.668505496049}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2192807831103,7.9348445080335,11.220467543462}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.472011138994,7.984168204423,8.770014934503}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9621987024239,8.1574286566716,8.0623609303045}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1528023063519,8.0296220770355,7.3788837002887}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9286946293727,7.3635641640542,9.0611347250865}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.825746642975,7.4123637406257,7.9783223333258}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2051431800104,7.994398362141,7.2483931735998}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9420559636769,8.1724770741691,6.8134675018193}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7880110976429,7.7164270980249,8.1395011762908}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.5875598525645,8.7860901065389,7.1433161771874}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0719123626076,7.6180059937042,6.8337463291405}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9832799039405,7.7255341138264,7.5525255559623}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0222911483204,6.8324795509634,8.4672355867104}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3718133299761,8.1307628557381,9.4990657488866}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.271458701147,8.0747491776138,6.8545161006567}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7502646779537,8.1231999934856,8.3088657020051}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2719994327591,7.5356049210989,8.6458124837528}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9365998601516,8.2065715506605,9.7402395554283}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9907931070035,8.0700128018982,7.5219237747282}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4946509375458,8.0629946978983,6.6846422346571}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3388911951208,9.1441857788448,9.091444579077}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.6193662832615,7.9022503608835,8.6756303290511}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0544976929278,8.0493009493416,8.230392746744}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7492717724336,8.7660670028935,9.1818661807011}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2096481372834,7.5924158989886,9.547767527544}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3134316533765,7.1853996147827,6.895437327111}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4261111117352,8.1570038091217,7.2039546654305}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2778499471585,8.4768611613506,8.4617506659525}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1316466328784,8.0850456641987,7.0787998345564}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8806349025191,9.0086030444804,7.4698447853491}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1481189239408,7.7395079283074,9.5787912247262}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2487536697102,7.1614867742047,9.1411404468163}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1296067408818,8.0473142035061,7.9004336102559}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8752777905207,8.7428646508438,8.4372883296402}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0733037366566,7.7314922446252,9.9579999616278}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.5687740590708,8.2469268677035,8.603564477605}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3230873007585,7.1154778157046,8.3407205995321}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1650039636336,7.9694338009248,9.5518309260429}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1292091512503,7.5436133854481,7.899657309935}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1420100809803,8.1827462690282,8.136727370514}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3281556221486,8.5583666207422,7.8526505516147}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9947444152282,8.6286084661019,8.5127367563059}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2793097937623,7.6724331417046,8.4416463479586}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8731518546961,8.4575024426546,8.2554533001405}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8688495328623,8.5268911687225,8.9781395829489}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0901087523426,7.9159106142724,5.7536725374879}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3017897766752,8.8116462279158,8.2493426622479}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9889388038907,7.9598700659368,7.2139095248089}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0408229066372,7.6968383084999,9.8661034719709}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7570114771498,8.6194225241094,8.2300373969143}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9739306602973,7.8859169318111,9.2141490476528}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4617285715211,8.0239375203791,8.298602834294}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.6467358631311,8.4064264999763,8.1490181831319}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9480677744568,7.7325204958552,8.5560172093937}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2986818996905,8.0974532928422,7.6774535297997}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8384281490624,8.0076995324654,5.8074823198756}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0449464117542,8.5066219286904,8.8324521715549}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7151109155374,8.1299637097493,6.8103750173971}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.972622221351,8.1886871178258,8.625516370799}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9110538941751,7.4958862167835,7.1595089434679}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.5798125339899,7.1112641845395,7.8443755847766}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7515062590352,7.9393287451403,8.713403289568}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7446631843531,6.7830429462542,7.4133739694283}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2463107324535,7.5394150324116,6.1549597922097}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2476162362818,7.8053552616151,8.1912250266325}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7110233320402,8.5502844819264,7.6860642253745}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8653383685308,8.2236789552747,8.98165525399}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.082293797456,8.0944904460719,7.2064915417135}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3489536145594,7.890515244801,9.2102908056106}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.682370201539,7.5476022156947,8.2522115223243}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.6891807443479,7.6611848675331,6.6401102405233}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1089016083718,7.5037075274979,7.4354046731874}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9213803643339,7.7817454761291,7.2730266275527}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1511262512385,8.2576671031453,8.1776176214216}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1937061428818,7.9369162228622,8.9724716594648}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4321741450853,8.5447298373033,8.4515496382593}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2127297358368,8.1261234648263,7.1630387119843}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8815184211839,7.5893285284446,8.3490934261551}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9477977320436,7.6457012929214,10.207013764623}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9356171844589,7.977989825723,7.344661305385}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7257663301693,7.6932782174709,7.2091664823905}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8782496737532,7.2649337208901,7.9880532205509}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4523275609233,7.5520709442943,8.7012564298143}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.784746829403,7.7736623560565,9.2313465353304}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9113827797734,8.1007919917083,7.7111059021462}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.7472954847321,7.3517050737278,8.0503652937436}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0824168081643,8.1036883810615,7.8860852395807}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.866191772936,8.4927858137158,6.6785368038763}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.101791447859,7.7811225032052,7.2717782644557}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2063851828224,7.4352169117001,8.8423544950304}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1322061693537,7.7642487395609,7.6469452440442}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1194492973571,8.2134152374437,10.10430560278}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9413063231214,7.79161820545,6.0366098539621}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1849479383475,8.0911715803797,6.9261826156551}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9299888394007,7.2484446879071,6.8795832124238}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.147202969752,7.1873867258477,9.4644427785961}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.6321300783343,8.1450678951637,6.5401638187864}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9090752423803,7.7712724949476,9.3456721698573}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2367718562181,8.4032571563061,9.3767463918425}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0835817256082,7.582406878413,8.0915756618119}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1646420746198,7.5482147469401,7.7618329036261}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9095576861373,8.2433163962411,8.4980288596759}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0711931069571,7.530134848026,7.6943011549827}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9987751276247,7.4158548288211,6.4750835408845}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0910780082279,7.4572804711381,7.8240799722108}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1112688951913,7.9705032910958,7.2554372067856}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0515753289697,8.1928137905086,7.4759472433034}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.7153047886352,8.6689186954059,9.6946240506407}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1685132442628,7.8774301404136,6.9731522205175}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.6311115601441,7.5941419910437,9.7145148523024}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9351375056492,7.5462274934744,6.6737001896418}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0889609828249,8.0912600607939,7.8321607983497}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1597364886607,7.9366742049271,10.342782003528}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.923346208187,7.2016457489945,7.7023065233103}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9815464631402,7.8561789251639,8.0946764586651}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4662656037447,7.7895996740698,7.7093248468311}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3224179829047,7.2643479104808,9.8132586727186}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0410823597258,8.6505892929699,7.1920163633085}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2584304478173,7.725375496373,8.9006539082442}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7735170752483,8.1510998670964,7.837781785741}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4056892532954,8.1153278606083,7.4240140401365}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0722081383288,7.8318168048421,6.9569944449399}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2966741913553,8.3005981823115,8.3744672362022}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.421009928787,7.8962742793042,8.5391944176122}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1483108973482,6.9351740674042,7.8086819482273}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.6566414933676,8.0544173254459,7.442816188815}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.2910949320926,8.6628782145729,8.0317337809795}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0983962236663,7.8892866785424,6.6933883917699}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.659121148925,7.7945835409611,8.2055029585253}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0402835136937,7.5310038548664,7.3553442515004}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9685963826727,7.494583181862,7.3539299870935}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.5563720430564,7.8506166155065,7.5366221368295}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.525943542888,6.8627376399596,6.8412357977848}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9647350109685,6.6519708553395,10.323808434413}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8392319818433,7.2463310700812,9.0106120856451}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0721151053279,7.6581027841812,7.2307929505801}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3187333993971,6.9348314495963,5.3388672322072}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9892691054185,7.4330283943974,8.8988707525753}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0496482840834,7.7400244851224,6.2328499008487}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9729868720067,8.9150295296002,5.9858346669359}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.6464924423145,8.7252602820324,7.3025663155915}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3447766957906,8.3035244366488,7.1241103003035}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0954664511006,7.5033284931428,8.8141375054049}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8404251876638,8.4540404594376,7.7371902002214}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.792768199615,7.7502228690206,10.501602347531}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.200738264868,7.8293091221365,8.01653739354}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.3320220735711,8.1606690708477,6.383390393029}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1368661781047,8.6844700874318,7.9280871578848}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0583412523245,7.1333732091568,6.7959649469107}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.4343812776424,8.1784740547851,7.4450585142654}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.5722310323602,7.2931265419769,9.3401535444179}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7750257408666,7.647074259843,7.5384671094132}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.59972037597,8.5890661256682,10.199241851282}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1432365691796,8.2437436067096,7.3052661523708}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2586708889866,7.8951339101955,7.8437497979855}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1290022593116,8.8765477636939,8.5088695610568}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8811761101025,8.0058725923254,7.7675604765912}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9344024519213,8.6240430189244,8.0938229883623}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2586770653842,8.2261132808173,6.4893051058006}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1658418024318,8.2827424435886,8.1626360192602}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1460721202288,8.6936750520598,8.4212378827247}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7414441989093,7.8499896240054,7.6800349596772}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1750233258425,8.2771328235309,7.1344772529082}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1769271947542,7.8930841367002,9.2388953949076}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0801176973362,7.2683438671279,8.7627502442859}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7856087113423,7.5536791574565,7.5297983810941}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2460269432082,8.0140518094791,7.4481328834547}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8308449159799,8.5044817361924,8.7901830233474}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0162484899457,8.012583475483,8.0957827405008}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.2379515843322,7.865996967794,8.8458471985886}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8882830518879,8.1927479954944,7.5850995949985}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.9139894964632,7.3082982914122,7.1097251375415}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.130974051665,8.8876275829208,8.2236483466709}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.7305016845479,7.5346585277436,7.5448783986455}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8617017276583,8.7009667090353,8.737159946423}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8503617220677,8.2404927576352,8.7381291679246}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8623885395277,8.3614336317246,5.6847052467107}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.0681462705452,7.6734454222732,8.3414789681074}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.1827031138615,6.8533568619312,7.1188854529688}, 3)); trainingData.add(Record.newDataVector(new Double[] {8.6214685846329,8.0218759456459,9.2140622324487}, 3)); trainingData.add(Record.newDataVector(new Double[] {7.8872168038128,6.9977919468999,8.1205596528281}, 3)); Dataset validationData = new Dataset(); validationData.add(Record.newDataVector(new Double[] {6.34569812276338,6.76262401884614,6.08305530880784}, 1)); validationData.add(Record.newDataVector(new Double[] {5.92085126899850,6.01037072456601,4.66307928268761}, 1)); validationData.add(Record.newDataVector(new Double[] {7.18606367787857,6.64194264491917,4.41233885708698}, 2)); validationData.add(Record.newDataVector(new Double[] {7.83232073356316,8.76007761528955,7.05235518409310}, 3)); */ String dbName = "JUnitClassifier"; DummyXYMinMaxNormalizer df = new DummyXYMinMaxNormalizer(dbName, TestUtils.getDBConfig()); df.fit_transform(trainingData, new DummyXYMinMaxNormalizer.TrainingParameters()); df.transform(validationData); SoftMaxRegression instance = new SoftMaxRegression(dbName, TestUtils.getDBConfig()); SoftMaxRegression.TrainingParameters param = new SoftMaxRegression.TrainingParameters(); param.setTotalIterations(2000); instance.fit(trainingData, param); instance = null; instance = new SoftMaxRegression(dbName, TestUtils.getDBConfig()); instance.validate(validationData); df.denormalize(trainingData); df.denormalize(validationData); df.erase(); Map<Integer, Object> expResult = new HashMap<>(); Map<Integer, Object> result = new HashMap<>(); for(Record r : validationData) { expResult.put(r.getId(), r.getY()); result.put(r.getId(), r.getYPredicted()); } assertEquals(expResult, result); instance.erase(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(String[] args) { final JFrame frame = new JFrame(); final Provider provider = Provider.getCurrentProvider(true); if (provider == null) { System.exit(1); } frame.add(new JLabel("Press hotkey combination:"), BorderLayout.NORTH); final JTextField textField = new JTextField(); textField.setFont(textField.getFont().deriveFont(Font.BOLD, 15f)); textField.setEditable(false); textField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (MODIFIERS.contains(e.getKeyCode())) textField.setText(""); else textField.setText(KeyStroke.getKeyStrokeForEvent(e).toString().replaceAll("pressed ", "")); } }); frame.add(textField, BorderLayout.CENTER); JPanel box = new JPanel(); JButton grab = new JButton("Grab"); box.add(grab); final HotKeyListener listener = new HotKeyListener() { public void onHotKey(final HotKey hotKey) { JOptionPane.showMessageDialog(frame, "Hooray: " + hotKey); } }; grab.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String text = textField.getText(); if (text != null && text.length() > 0) { provider.reset(); provider.register(KeyStroke.getKeyStroke(text), listener); } } }); JButton grabMedia = new JButton("Grab media keys"); grabMedia.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { provider.register(MediaKey.MEDIA_NEXT_TRACK, listener); provider.register(MediaKey.MEDIA_PLAY_PAUSE, listener); provider.register(MediaKey.MEDIA_PREV_TRACK, listener); provider.register(MediaKey.MEDIA_STOP, listener); } }); box.add(grabMedia); frame.add(box, BorderLayout.PAGE_END); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { provider.reset(); provider.stop(); System.exit(0); } }); frame.setSize(500, 150); frame.setLocationRelativeTo(null); frame.setVisible(true); } #location 56 #vulnerability type RESOURCE_LEAK
#fixed code public static void main(String[] args) { final JFrame frame = new JFrame(); final Provider provider = Provider.getCurrentProvider(true); if (provider == null) { System.exit(1); } frame.add(new JLabel("Press hotkey combination:"), BorderLayout.NORTH); final JTextField textField = new JTextField(); textField.setFont(textField.getFont().deriveFont(Font.BOLD, 15f)); textField.setEditable(false); textField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (MODIFIERS.contains(e.getKeyCode())) { textField.setText(""); } else { textField.setText(KeyStroke.getKeyStrokeForEvent(e).toString().replaceAll("pressed ", "")); } } }); frame.add(textField, BorderLayout.CENTER); JPanel box = new JPanel(); JButton grab = new JButton("Grab"); JButton ungrab = new JButton("Ungrab"); JButton reset = new JButton("Reset All"); box.add(grab); box.add(ungrab); final HotKeyListener listener = hotKey -> JOptionPane.showMessageDialog(frame, "Hooray: " + hotKey); grab.addActionListener(e -> { String text = textField.getText(); if (text != null && text.length() > 0) { provider.register(KeyStroke.getKeyStroke(text), listener); } }); ungrab.addActionListener(e -> { String text = textField.getText(); if (text != null && text.length() > 0) { provider.unregister(KeyStroke.getKeyStroke(text)); } }); reset.addActionListener(e -> provider.reset()); JButton grabMedia = new JButton("Grab media keys"); grabMedia.addActionListener(e -> { provider.register(MediaKey.MEDIA_NEXT_TRACK, listener); provider.register(MediaKey.MEDIA_PLAY_PAUSE, listener); provider.register(MediaKey.MEDIA_PREV_TRACK, listener); provider.register(MediaKey.MEDIA_STOP, listener); }); box.add(grabMedia); box.add(reset); frame.add(box, BorderLayout.PAGE_END); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { provider.reset(); provider.stop(); System.exit(0); } }); frame.setSize(500, 150); frame.setLocationRelativeTo(null); frame.setVisible(true); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(String[] args) { final JFrame frame = new JFrame(); final Provider provider = Provider.getCurrentProvider(); provider.init(); final JTextField textField = new JTextField(); textField.setEditable(false); textField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (MODIFIERS.contains(e.getKeyCode())) textField.setText(""); else textField.setText(KeyStroke.getKeyStrokeForEvent(e).toString().replaceAll("pressed ", "")); } }); frame.add(textField, BorderLayout.CENTER); JPanel box = new JPanel(new GridLayout(2, 1)); JButton grab = new JButton("Grab"); box.add(grab); final HotKeyListener listener = new HotKeyListener() { public void onHotKey(final HotKey hotKey) { SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(frame, "Hooray: " + hotKey); } }); } }; grab.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String text = textField.getText(); if (text != null && text.length() > 0) { provider.reset(); provider.register(KeyStroke.getKeyStroke(text), listener); } } }); JButton grabMedia = new JButton("Grab media keys"); grabMedia.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { provider.register(MediaKey.MEDIA_NEXT_TRACK, listener); provider.register(MediaKey.MEDIA_PLAY_PAUSE, listener); provider.register(MediaKey.MEDIA_PREV_TRACK, listener); provider.register(MediaKey.MEDIA_STOP, listener); } }); box.add(grabMedia); frame.add(box, BorderLayout.PAGE_END); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { provider.reset(); provider.stop(); System.exit(0); } }); frame.setSize(300, 150); frame.setLocationRelativeTo(null); frame.setVisible(true); } #location 5 #vulnerability type NULL_DEREFERENCE
#fixed code public static void main(String[] args) { final JFrame frame = new JFrame(); final Provider provider = Provider.getCurrentProvider(true); final JTextField textField = new JTextField(); textField.setEditable(false); textField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (MODIFIERS.contains(e.getKeyCode())) textField.setText(""); else textField.setText(KeyStroke.getKeyStrokeForEvent(e).toString().replaceAll("pressed ", "")); } }); frame.add(textField, BorderLayout.CENTER); JPanel box = new JPanel(new GridLayout(2, 1)); JButton grab = new JButton("Grab"); box.add(grab); final HotKeyListener listener = new HotKeyListener() { public void onHotKey(final HotKey hotKey) { JOptionPane.showMessageDialog(frame, "Hooray: " + hotKey); } }; grab.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String text = textField.getText(); if (text != null && text.length() > 0) { provider.reset(); provider.register(KeyStroke.getKeyStroke(text), listener); } } }); JButton grabMedia = new JButton("Grab media keys"); grabMedia.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { provider.register(MediaKey.MEDIA_NEXT_TRACK, listener); provider.register(MediaKey.MEDIA_PLAY_PAUSE, listener); provider.register(MediaKey.MEDIA_PREV_TRACK, listener); provider.register(MediaKey.MEDIA_STOP, listener); } }); box.add(grabMedia); frame.add(box, BorderLayout.PAGE_END); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { provider.reset(); provider.stop(); System.exit(0); } }); frame.setSize(300, 150); frame.setLocationRelativeTo(null); frame.setVisible(true); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(String[] args) { final JFrame frame = new JFrame(); final Provider provider = Provider.getCurrentProvider(true); if (provider == null) { System.exit(1); } frame.add(new JLabel("Press hotkey combination:"), BorderLayout.NORTH); final JTextField textField = new JTextField(); textField.setFont(textField.getFont().deriveFont(Font.BOLD, 15f)); textField.setEditable(false); textField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (MODIFIERS.contains(e.getKeyCode())) textField.setText(""); else textField.setText(KeyStroke.getKeyStrokeForEvent(e).toString().replaceAll("pressed ", "")); } }); frame.add(textField, BorderLayout.CENTER); JPanel box = new JPanel(); JButton grab = new JButton("Grab"); box.add(grab); final HotKeyListener listener = new HotKeyListener() { public void onHotKey(final HotKey hotKey) { JOptionPane.showMessageDialog(frame, "Hooray: " + hotKey); } }; grab.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String text = textField.getText(); if (text != null && text.length() > 0) { provider.reset(); provider.register(KeyStroke.getKeyStroke(text), listener); } } }); JButton grabMedia = new JButton("Grab media keys"); grabMedia.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { provider.register(MediaKey.MEDIA_NEXT_TRACK, listener); provider.register(MediaKey.MEDIA_PLAY_PAUSE, listener); provider.register(MediaKey.MEDIA_PREV_TRACK, listener); provider.register(MediaKey.MEDIA_STOP, listener); } }); box.add(grabMedia); frame.add(box, BorderLayout.PAGE_END); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { provider.reset(); provider.stop(); System.exit(0); } }); frame.setSize(500, 150); frame.setLocationRelativeTo(null); frame.setVisible(true); } #location 56 #vulnerability type RESOURCE_LEAK
#fixed code public static void main(String[] args) { final JFrame frame = new JFrame(); final Provider provider = Provider.getCurrentProvider(true); if (provider == null) { System.exit(1); } frame.add(new JLabel("Press hotkey combination:"), BorderLayout.NORTH); final JTextField textField = new JTextField(); textField.setFont(textField.getFont().deriveFont(Font.BOLD, 15f)); textField.setEditable(false); textField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (MODIFIERS.contains(e.getKeyCode())) { textField.setText(""); } else { textField.setText(KeyStroke.getKeyStrokeForEvent(e).toString().replaceAll("pressed ", "")); } } }); frame.add(textField, BorderLayout.CENTER); JPanel box = new JPanel(); JButton grab = new JButton("Grab"); JButton ungrab = new JButton("Ungrab"); JButton reset = new JButton("Reset All"); box.add(grab); box.add(ungrab); final HotKeyListener listener = hotKey -> JOptionPane.showMessageDialog(frame, "Hooray: " + hotKey); grab.addActionListener(e -> { String text = textField.getText(); if (text != null && text.length() > 0) { provider.register(KeyStroke.getKeyStroke(text), listener); } }); ungrab.addActionListener(e -> { String text = textField.getText(); if (text != null && text.length() > 0) { provider.unregister(KeyStroke.getKeyStroke(text)); } }); reset.addActionListener(e -> provider.reset()); JButton grabMedia = new JButton("Grab media keys"); grabMedia.addActionListener(e -> { provider.register(MediaKey.MEDIA_NEXT_TRACK, listener); provider.register(MediaKey.MEDIA_PLAY_PAUSE, listener); provider.register(MediaKey.MEDIA_PREV_TRACK, listener); provider.register(MediaKey.MEDIA_STOP, listener); }); box.add(grabMedia); box.add(reset); frame.add(box, BorderLayout.PAGE_END); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { provider.reset(); provider.stop(); System.exit(0); } }); frame.setSize(500, 150); frame.setLocationRelativeTo(null); frame.setVisible(true); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(String[] args) { final JFrame frame = new JFrame(); final Provider provider = Provider.getCurrentProvider(true); if (provider == null) { System.exit(1); } frame.add(new JLabel("Press hotkey combination:"), BorderLayout.NORTH); final JTextField textField = new JTextField(); textField.setFont(textField.getFont().deriveFont(Font.BOLD, 15f)); textField.setEditable(false); textField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (MODIFIERS.contains(e.getKeyCode())) textField.setText(""); else textField.setText(KeyStroke.getKeyStrokeForEvent(e).toString().replaceAll("pressed ", "")); } }); frame.add(textField, BorderLayout.CENTER); JPanel box = new JPanel(); JButton grab = new JButton("Grab"); box.add(grab); final HotKeyListener listener = new HotKeyListener() { public void onHotKey(final HotKey hotKey) { JOptionPane.showMessageDialog(frame, "Hooray: " + hotKey); } }; grab.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String text = textField.getText(); if (text != null && text.length() > 0) { provider.reset(); provider.register(KeyStroke.getKeyStroke(text), listener); } } }); JButton grabMedia = new JButton("Grab media keys"); grabMedia.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { provider.register(MediaKey.MEDIA_NEXT_TRACK, listener); provider.register(MediaKey.MEDIA_PLAY_PAUSE, listener); provider.register(MediaKey.MEDIA_PREV_TRACK, listener); provider.register(MediaKey.MEDIA_STOP, listener); } }); box.add(grabMedia); frame.add(box, BorderLayout.PAGE_END); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { provider.reset(); provider.stop(); System.exit(0); } }); frame.setSize(500, 150); frame.setLocationRelativeTo(null); frame.setVisible(true); } #location 56 #vulnerability type RESOURCE_LEAK
#fixed code public static void main(String[] args) { final JFrame frame = new JFrame(); final Provider provider = Provider.getCurrentProvider(true); if (provider == null) { System.exit(1); } frame.add(new JLabel("Press hotkey combination:"), BorderLayout.NORTH); final JTextField textField = new JTextField(); textField.setFont(textField.getFont().deriveFont(Font.BOLD, 15f)); textField.setEditable(false); textField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (MODIFIERS.contains(e.getKeyCode())) { textField.setText(""); } else { textField.setText(KeyStroke.getKeyStrokeForEvent(e).toString().replaceAll("pressed ", "")); } } }); frame.add(textField, BorderLayout.CENTER); JPanel box = new JPanel(); JButton grab = new JButton("Grab"); JButton ungrab = new JButton("Ungrab"); JButton reset = new JButton("Reset All"); box.add(grab); box.add(ungrab); final HotKeyListener listener = hotKey -> JOptionPane.showMessageDialog(frame, "Hooray: " + hotKey); grab.addActionListener(e -> { String text = textField.getText(); if (text != null && text.length() > 0) { provider.register(KeyStroke.getKeyStroke(text), listener); } }); ungrab.addActionListener(e -> { String text = textField.getText(); if (text != null && text.length() > 0) { provider.unregister(KeyStroke.getKeyStroke(text)); } }); reset.addActionListener(e -> provider.reset()); JButton grabMedia = new JButton("Grab media keys"); grabMedia.addActionListener(e -> { provider.register(MediaKey.MEDIA_NEXT_TRACK, listener); provider.register(MediaKey.MEDIA_PLAY_PAUSE, listener); provider.register(MediaKey.MEDIA_PREV_TRACK, listener); provider.register(MediaKey.MEDIA_STOP, listener); }); box.add(grabMedia); box.add(reset); frame.add(box, BorderLayout.PAGE_END); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { provider.reset(); provider.stop(); System.exit(0); } }); frame.setSize(500, 150); frame.setLocationRelativeTo(null); frame.setVisible(true); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code private Node parseASTFilter() { Token token = expect(Filter.class); Filter filterToken = (Filter) token; Attribute attr = (Attribute) accept(Attribute.class); token = expect(Colon.class); FilterNode node = new FilterNode(); node.setValue(filterToken.getValue()); node.setBlock(block()); node.setLineNumber(line()); node.setAttributes(attr.getAttributes()); return node; } #location 12 #vulnerability type NULL_DEREFERENCE
#fixed code private Node parseASTFilter() { Token token = expect(Filter.class); Filter filterToken = (Filter) token; Attribute attr = (Attribute) accept(Attribute.class); token = expect(Colon.class); FilterNode node = new FilterNode(); node.setValue(filterToken.getValue()); node.setBlock(block()); node.setLineNumber(line()); node.setFileName(filename); node.setAttributes(attr.getAttributes()); return node; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void shouldCompileJadeToHtmlWithReaderTemplateLoader() throws Exception { List<String> additionalIgnoredCases = Arrays.asList("52", "74", "100", "104a", "104b", "123", "135"); if (additionalIgnoredCases.contains(file.replace(".jade", ""))) { return; } String issuesResourcePath = TestFileHelper.getIssuesResourcePath(""); FileReader fileReader = new FileReader(issuesResourcePath + File.separator + file); String templateName = file; ReaderTemplateLoader templateLoader = new ReaderTemplateLoader(fileReader, templateName); compareJade(templateLoader, templateName); } #location 12 #vulnerability type RESOURCE_LEAK
#fixed code @Test public void shouldCompileJadeToHtmlWithReaderTemplateLoader() throws Exception { List<String> additionalIgnoredCases = Arrays.asList("52", "74", "100", "104a", "104b", "123", "135"); if (additionalIgnoredCases.contains(file.replace(".jade", ""))) { return; } String issuesResourcePath = TestFileHelper.getIssuesResourcePath(""); String pathToFile = issuesResourcePath + File.separator + file; InputStreamReader reader = new InputStreamReader(new FileInputStream(pathToFile), FILES_ENCODING); String templateName = file; ReaderTemplateLoader templateLoader = new ReaderTemplateLoader(reader, templateName); compareJade(templateLoader, templateName); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public CHConnection connect(String url, Properties info) throws SQLException { logger.info("Creating connection"); return LogProxy.wrap(CHConnection.class, new CHConnectionImpl(url)); } #location 4 #vulnerability type RESOURCE_LEAK
#fixed code @Override public CHConnection connect(String url, Properties info) throws SQLException { logger.info("Creating connection"); return LogProxy.wrap(CHConnection.class, new CHConnectionImpl(url, info)); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public CHConnection connect(String url, CHProperties properties) throws SQLException { logger.info("Creating connection"); return LogProxy.wrap(CHConnection.class, new CHConnectionImpl(url, properties)); } #location 3 #vulnerability type RESOURCE_LEAK
#fixed code public CHConnection connect(String url, CHProperties properties) throws SQLException { logger.info("Creating connection"); CHConnectionImpl connection = new CHConnectionImpl(url, properties); connections.put(connection, true); return LogProxy.wrap(CHConnection.class, connection); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public ResultSet executeQuery(String sql) throws SQLException { String csql = clickhousifySql(sql, "TabSeparatedWithNamesAndTypes"); CountingInputStream is = getInputStream(csql); try { return new HttpResult(properties.isCompress() ? new ClickhouseLZ4Stream(is) : is, is, properties.getBufferSize()); } catch (Exception e) { throw new RuntimeException(e); } } #location 7 #vulnerability type RESOURCE_LEAK
#fixed code @Override public ResultSet executeQuery(String sql) throws SQLException { String csql = clickhousifySql(sql); CountingInputStream is = getInputStream(csql); try { return new CHResultSet(properties.isCompress() ? new ClickhouseLZ4Stream(is) : is, properties.getBufferSize()); } catch (Exception e) { throw new RuntimeException(e); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public CHConnection connect(String url, Properties info) throws SQLException { logger.info("Creating connection"); return LogProxy.wrap(CHConnection.class, new CHConnectionImpl(url, info)); } #location 4 #vulnerability type RESOURCE_LEAK
#fixed code @Override public CHConnection connect(String url, Properties info) throws SQLException { logger.info("Creating connection"); CHConnectionImpl connection = new CHConnectionImpl(url, info); connections.put(connection, true); return LogProxy.wrap(CHConnection.class, connection); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override public ResultSet executeQuery(String sql) throws SQLException { String csql = clickhousifySql(sql, "TabSeparatedWithNamesAndTypes"); CountingInputStream is = getInputStream(csql); try { return new HttpResult(properties.isCompress() ? new ClickhouseLZ4Stream(is) : is, is, properties.getBufferSize()); } catch (Exception e) { throw new RuntimeException(e); } } #location 7 #vulnerability type RESOURCE_LEAK
#fixed code @Override public ResultSet executeQuery(String sql) throws SQLException { String csql = clickhousifySql(sql); CountingInputStream is = getInputStream(csql); try { return new CHResultSet(properties.isCompress() ? new ClickhouseLZ4Stream(is) : is, properties.getBufferSize()); } catch (Exception e) { throw new RuntimeException(e); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public byte[] downloadObject(DownloadInstructions downloadInstructions) { return new DownloadObjectAsByteArrayCommand(getAccount(), getClient(), getAccess(), this, downloadInstructions).call(); } #location 2 #vulnerability type RESOURCE_LEAK
#fixed code public byte[] downloadObject(DownloadInstructions downloadInstructions) { return commandFactory.createDownloadObjectAsByteArrayCommand(getAccount(), getClient(), getAccess(), this, downloadInstructions).call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override protected void saveMetadata() { new ContainerMetadataCommand(getAccount(), getClient(), getAccess(), this, info.getMetadata()).call(); } #location 3 #vulnerability type RESOURCE_LEAK
#fixed code @Override protected void saveMetadata() { commandFactory.createContainerMetadataCommand(getAccount(), getClient(), getAccess(), this, info.getMetadata()).call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(String args[]) throws IOException { if (args.length != 4) { System.out.println("Use syntax: <TENANT> <USERNAME> <PASSWORD> <URL>"); return; } String tenant = args[0]; String username = args[1]; String password = args[2]; String url = args[3]; System.out.println("Executing with "+username+"/"+password+"@"+url); Account account = new ClientImpl().authenticate(tenant, username, password, url); // Container container = account.getContainer("images"); // container.create(); // container.makePublic(); // Collection<Container> containers = account.listContainers(); for (Container currentContainer : containers) { System.out.println(currentContainer.getName()); } // StoredObject object = container.getObject("dog.png"); // object.uploadObject(new File("/dog.png")); // System.out.println("Public URL: "+object.getPublicURL()); // System.out.println("Last modified: "+object.getLastModified()); // System.out.println("ETag: "+object.getEtag()); // System.out.println("Content type: "+object.getContentType()); // System.out.println("Content length: "+object.getContentLength()); // // Collection<StoredObject> objects = container.listObjects(); // for (StoredObject currentObject : objects) { // System.out.println(currentObject.getName()); // } // object.downloadObject(new File("/Users/robertbor/Downloads/dog2.png")); // StoredObject newObject = container.getObject("new-dog.png"); // object.copyObject(container, newObject); // object.delete(); // System.out.println("Public URL: "+object.getPublicURL()); // no longer retrievable // System.out.println("Public URL: "+newObject.getPublicURL()); // the new URL // Map<String, Object> metadata = new TreeMap<String, Object>(); // metadata.put("title", "Some Title"); // metadata.put("department", "Some Department"); // object.setMetadata(metadata); // container.setMetadata(metadata); // object.setMetadata(metadata); // metadata = object.getMetadata(); // for (String name : metadata.keySet()) { // System.out.println("META / "+name+": "+metadata.get(name)); // } ClientMock client = new ClientMock(); MockUserStore users = new MockUserStore(); users.addUser("testuser", "testpassword"); client.setUsers(users); } #location 19 #vulnerability type NULL_DEREFERENCE
#fixed code public static void main(String args[]) throws IOException { if (args.length != 4) { System.out.println("Use syntax: <TENANT> <USERNAME> <PASSWORD> <URL>"); return; } String tenant = args[0]; String username = args[1]; String password = args[2]; String url = args[3]; System.out.println("Executing with "+username+"/"+password+"@"+url); Account account = new ClientImpl().authenticate(tenant, username, password, url, "AMS-1"); // Container container = account.getContainer("images"); // container.create(); // container.makePublic(); // Collection<Container> containers = account.listContainers(); for (Container currentContainer : containers) { System.out.println(currentContainer.getName()); } // StoredObject object = container.getObject("dog.png"); // object.uploadObject(new File("/dog.png")); // System.out.println("Public URL: "+object.getPublicURL()); // System.out.println("Last modified: "+object.getLastModified()); // System.out.println("ETag: "+object.getEtag()); // System.out.println("Content type: "+object.getContentType()); // System.out.println("Content length: "+object.getContentLength()); // // Collection<StoredObject> objects = container.listObjects(); // for (StoredObject currentObject : objects) { // System.out.println(currentObject.getName()); // } // object.downloadObject(new File("/Users/robertbor/Downloads/dog2.png")); // StoredObject newObject = container.getObject("new-dog.png"); // object.copyObject(container, newObject); // object.delete(); // System.out.println("Public URL: "+object.getPublicURL()); // no longer retrievable // System.out.println("Public URL: "+newObject.getPublicURL()); // the new URL // Map<String, Object> metadata = new TreeMap<String, Object>(); // metadata.put("title", "Some Title"); // metadata.put("department", "Some Department"); // object.setMetadata(metadata); // container.setMetadata(metadata); // object.setMetadata(metadata); // metadata = object.getMetadata(); // for (String name : metadata.keySet()) { // System.out.println("META / "+name+": "+metadata.get(name)); // } ClientMock client = new ClientMock(); MockUserStore users = new MockUserStore(); users.addUser("testuser", "testpassword"); client.setUsers(users); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void getInfo() { ContainerInformation info = new ContainerInformationCommand(getAccount(), getClient(), getAccess(), this).call(); this.bytesUsed = info.getBytesUsed(); this.objectCount = info.getObjectCount(); this.publicContainer = info.isPublicContainer(); this.setMetadata(info.getMetadata()); this.setInfoRetrieved(); } #location 3 #vulnerability type NULL_DEREFERENCE
#fixed code protected void getInfo() { this.info = new ContainerInformationCommand(getAccount(), getClient(), getAccess(), this).call(); this.setInfoRetrieved(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(String args[]) throws IOException { if (args.length != 3) { System.out.println("Use syntax: <USERNAME> <PASSWORD> <URL>"); return; } String username = args[0]; String password = args[1]; String url = args[2]; System.out.println("Executing with "+username+"/"+password+"@"+url); OpenStackClient client = new OpenStackClientImpl(); client.authenticate(username, password, url); // client.makeContainerPublic(new Container("Eindhoven")); // client.makeContainerPrivate(new Container("Eindhoven")); // Map<String, Object> metadata = new TreeMap<String, Object>(); // metadata.put("Year", "1989"); // metadata.put("Owner", "42 BV"); // client.setAccountInformation(metadata); // AccountInformation accountInformation = client.getAccountInformation(); // System.out.println("Containers in use: "+accountInformation.getContainerCount()); // System.out.println("Objects in use: "+accountInformation.getObjectCount()); // System.out.println("Bytes used: "+accountInformation.getBytesUsed()); // System.out.println("Year: "+accountInformation.getMetadata().get("Year")); // System.out.println("Owner: "+accountInformation.getMetadata().get("Owner")); System.out.println("Tilburg: "+client.getContainerInformation(new Container("Tilburg")).isPublicContainer()); System.out.println("Breda: "+client.getContainerInformation(new Container("Breda")).isPublicContainer()); System.out.println("Eindhoven: " + client.getContainerInformation(new Container("Eindhoven")).isPublicContainer()); // ContainerInformation info = client.getContainerInformation(new Container("Tilburg")); // System.out.println("Object count: "+info.getObjectCount()); // System.out.println("Bytes used: "+info.getBytesUsed()); // System.out.println("Public?: "+info.isPublicContainer()); // InputStream inputStream = new FileInputStream(new File("/Users/robertbor/Downloads/dog.png")); // byte[] fileToUpload = IOUtils.toByteArray(inputStream); // inputStream.close(); // client.uploadObject(new Container("Tilburg"), new StoreObject("somedog3.png"), fileToUpload); // Container container = new Container("Tilburg"); // StoreObject sourceObject = new StoreObject("somedog5.png"); // StoreObject targetObject = new StoreObject("newdog.png"); // client.uploadObject(container, sourceObject, new File("/Users/robertbor/Downloads/dog.png")); // client.copyObject(container, sourceObject, container, targetObject); // byte[] plaatje = client.downloadObject(new Container("Tilburg"), new StoreObject("newdog.png")); // System.out.println("Grootte plaatje: " + plaatje.length); // FileOutputStream fos = new FileOutputStream(new File("plaatje.png")); // fos.write(plaatje); // fos.close(); // client.downloadObject(new Container("Tilburg"), new StoreObject("newdog.png"), new File("plaatje2.png")); // client.uploadObject(new Container("Tilburg"), new StoreObject("somedog5.png"), new File("/Users/robertbor/Downloads/dog.png")); // client.deleteObject(new Container("Tilburg"), new StoreObject("somedog5.png")); // ContainerInformation info2 = client.getContainerInformation(new Container("Tilburg")); // System.out.println("\nAFTER"); // System.out.println("Object count: "+info2.getObjectCount()); // System.out.println("Bytes used: "+info2.getBytesUsed()); // Map<String, Object> metadata = new TreeMap<String, Object>(); // metadata.put("Description", "Kantoor Eindhoven, inclusief randgemeenten"); // metadata.put("Province", "Noord Brabant"); // metadata.put("Country", "Nederland"); // client.setContainerInformation(new Container("Eindhoven"), metadata); // client.setObjectInformation(new Container("Tilburg"), new StoreObject("somedog.png"), metadata); // // ObjectInformation info = client.getObjectInformation(new Container("Tilburg"), new StoreObject("somedog.png")); // System.out.println("Last modified: "+info.getLastModified()); // System.out.println("ETag: "+info.getEtag()); // System.out.println("Content type: "+info.getContentType()); // System.out.println("Content length: "+info.getContentLength()); // for (String key : info.getMetadata().keySet()) { // System.out.println("META / "+key+": "+info.getMetadata().get(key)); // } // StoreObject objects[] = client.listObjects(new Container("Tilburg")); // for (StoreObject object : objects) { // System.out.println("* object -> "+object); // } // client.createContainer(new Container("Leiden")); // client.deleteContainer(new Container("Leiden")); // Map<String, Object> metadata = new TreeMap<String, Object>(); // metadata.put("Description", "Kantoor Eindhoven, inclusief randgemeenten"); // metadata.put("Province", "Noord Brabant"); // metadata.put("Country", "Nederland"); // client.setContainerInformation(new Container("Eindhoven"), metadata); // ContainerInformation info = client.getContainerInformation(new Container("Eindhoven")); // System.out.println("Object count: "+info.getObjectCount()); // System.out.println("Bytes used: "+info.getBytesUsed()); // System.out.println("Description: "+info.getMetadata().get("Description")); // System.out.println("Province: "+info.getMetadata().get("Province")); // System.out.println("Country: "+info.getMetadata().get("Country")); // // Container[] containers = client.listContainers(); // for (Container container : containers) { // System.out.println(container); // } } #location 30 #vulnerability type NULL_DEREFERENCE
#fixed code public static void main(String args[]) throws IOException { if (args.length != 3) { System.out.println("Use syntax: <USERNAME> <PASSWORD> <URL>"); return; } String username = args[0]; String password = args[1]; String url = args[2]; System.out.println("Executing with "+username+"/"+password+"@"+url); OpenStackClient client = new OpenStackClientImpl(); client.authenticate(username, password, url); // client.makeContainerPublic(new Container("Eindhoven")); // client.makeContainerPrivate(new Container("Eindhoven")); // Map<String, Object> metadata = new TreeMap<String, Object>(); // metadata.put("Year", "1989"); // metadata.put("Owner", "42 BV"); // client.setAccountInformation(metadata); // AccountInformation accountInformation = client.getAccountInformation(); // System.out.println("Containers in use: "+accountInformation.getContainerCount()); // System.out.println("Objects in use: "+accountInformation.getObjectCount()); // System.out.println("Bytes used: "+accountInformation.getBytesUsed()); // System.out.println("Year: "+accountInformation.getMetadata().get("Year")); // System.out.println("Owner: "+accountInformation.getMetadata().get("Owner")); // System.out.println("Tilburg: "+client.getContainerInformation(new Container("Tilburg")).isPublicContainer()); // System.out.println("Breda: "+client.getContainerInformation(new Container("Breda")).isPublicContainer()); // System.out.println("Eindhoven: " + client.getContainerInformation(new Container("Eindhoven")).isPublicContainer()); // ContainerInformation info = client.getContainerInformation(new Container("Tilburg")); // System.out.println("Object count: "+info.getObjectCount()); // System.out.println("Bytes used: "+info.getBytesUsed()); // System.out.println("Public?: "+info.isPublicContainer()); // InputStream inputStream = new FileInputStream(new File("/Users/robertbor/Downloads/dog.png")); // byte[] fileToUpload = IOUtils.toByteArray(inputStream); // inputStream.close(); // client.uploadObject(new Container("Tilburg"), new StoreObject("somedog3.png"), fileToUpload); // Container container = new Container("Tilburg"); // StoreObject sourceObject = new StoreObject("somedog5.png"); // StoreObject targetObject = new StoreObject("newdog.png"); // client.uploadObject(container, sourceObject, new File("/Users/robertbor/Downloads/dog.png")); // client.copyObject(container, sourceObject, container, targetObject); // byte[] plaatje = client.downloadObject(new Container("Tilburg"), new StoreObject("newdog.png")); // System.out.println("Grootte plaatje: " + plaatje.length); // FileOutputStream fos = new FileOutputStream(new File("plaatje.png")); // fos.write(plaatje); // fos.close(); // client.downloadObject(new Container("Tilburg"), new StoreObject("newdog.png"), new File("plaatje2.png")); uploadFile(client, "Tilburg", "doggie.png", new File("/Users/robertbor/Downloads/dog.png")); // client.uploadObject(new Container("Tilburg"), new StoreObject("doggie.png"), new File("/Users/robertbor/Downloads/dog.png")); // client.deleteObject(new Container("Tilburg"), new StoreObject("somedog5.png")); // ContainerInformation info2 = client.getContainerInformation(new Container("Tilburg")); // System.out.println("\nAFTER"); // System.out.println("Object count: "+info2.getObjectCount()); // System.out.println("Bytes used: "+info2.getBytesUsed()); // Map<String, Object> metadata = new TreeMap<String, Object>(); // metadata.put("Description", "Kantoor Eindhoven, inclusief randgemeenten"); // metadata.put("Province", "Noord Brabant"); // metadata.put("Country", "Nederland"); // client.setContainerInformation(new Container("Eindhoven"), metadata); // client.setObjectInformation(new Container("Tilburg"), new StoreObject("somedog.png"), metadata); // // ObjectInformation info = client.getObjectInformation(new Container("Tilburg"), new StoreObject("somedog.png")); // System.out.println("Last modified: "+info.getLastModified()); // System.out.println("ETag: "+info.getEtag()); // System.out.println("Content type: "+info.getContentType()); // System.out.println("Content length: "+info.getContentLength()); // for (String key : info.getMetadata().keySet()) { // System.out.println("META / "+key+": "+info.getMetadata().get(key)); // } // StoreObject objects[] = client.listObjects(new Container("Tilburg")); // for (StoreObject object : objects) { // System.out.println("* object -> "+object); // } // client.createContainer(new Container("Leiden")); // client.deleteContainer(new Container("Leiden")); // Map<String, Object> metadata = new TreeMap<String, Object>(); // metadata.put("Description", "Kantoor Eindhoven, inclusief randgemeenten"); // metadata.put("Province", "Noord Brabant"); // metadata.put("Country", "Nederland"); // client.setContainerInformation(new Container("Eindhoven"), metadata); // ContainerInformation info = client.getContainerInformation(new Container("Eindhoven")); // System.out.println("Object count: "+info.getObjectCount()); // System.out.println("Bytes used: "+info.getBytesUsed()); // System.out.println("Description: "+info.getMetadata().get("Description")); // System.out.println("Province: "+info.getMetadata().get("Province")); // System.out.println("Country: "+info.getMetadata().get("Country")); // // Container[] containers = client.listContainers(); // for (Container container : containers) { // System.out.println(container); // } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void delete() { new DeleteContainerCommand(getAccount(), getClient(), getAccess(), this).call(); } #location 2 #vulnerability type RESOURCE_LEAK
#fixed code public void delete() { commandFactory.createDeleteContainerCommand(getAccount(), getClient(), getAccess(), this).call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void setPreferredRegion(String preferredRegion) { this.currentEndPoint = getObjectStoreCatalog().getRegion(preferredRegion); } #location 2 #vulnerability type NULL_DEREFERENCE
#fixed code public void setPreferredRegion(String preferredRegion) { this.preferredRegion = preferredRegion; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test (expected = CommandException.class ) public void getSegmentationPlanThrowsIOException() throws Exception { UploadPayloadFile uploadPayload = mock(UploadPayloadFile.class); whenNew(UploadPayloadFile.class).withArguments(null).thenReturn(uploadPayload); when(uploadPayload.getSegmentationPlan(anyLong())).thenThrow(new IOException()); UploadInstructions instructions = new UploadInstructions((File)null); instructions.getSegmentationPlan(); } #location 5 #vulnerability type RESOURCE_LEAK
#fixed code @Test (expected = CommandException.class ) public void getSegmentationPlanThrowsIOException() throws Exception { new Expectations() { @Mocked UploadPayloadFile uploadPayload; { new UploadPayloadFile(null); result = uploadPayload; uploadPayload.getSegmentationPlan(anyLong); result = new IOException(); }}; UploadInstructions instructions = new UploadInstructions((File)null); instructions.getSegmentationPlan(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void pushAndUpdate() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("websites"); website = new WebsiteMock(new AccountMock(swift), "website"); website.pushDirectory(FileAction.getFile("websites/website")); assertEquals(7, website.list().size()); website.pushDirectory(FileAction.getFile("websites/website2")); assertEquals(6, website.list().size()); } #location 8 #vulnerability type NULL_DEREFERENCE
#fixed code @Test public void pushAndUpdate() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("websites", false); website = new WebsiteMock(new AccountMock(swift), "website"); website.pushDirectory(FileAction.getFile("websites/website")); assertEquals(7, website.list().size()); website.pushDirectory(FileAction.getFile("websites/website2")); assertEquals(6, website.list().size()); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void getInfo() { AccountInformation info = new AccountInformationCommand(this, httpClient, access).call(); this.bytesUsed = info.getBytesUsed(); this.containerCount = info.getContainerCount(); this.objectCount = info.getObjectCount(); this.setMetadata(info.getMetadata()); this.setInfoRetrieved(); } #location 3 #vulnerability type NULL_DEREFERENCE
#fixed code protected void getInfo() { this.info = new AccountInformationCommand(this, httpClient, access).call(); this.setInfoRetrieved(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public Container create() { new CreateContainerCommand(getAccount(), getClient(), getAccess(), this).call(); return this; } #location 2 #vulnerability type RESOURCE_LEAK
#fixed code public Container create() { commandFactory.createCreateContainerCommand(getAccount(), getClient(), getAccess(), this).call(); return this; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test(expected = UnauthorizedException.class) public void reauthenticateFailTwice() { when(statusLine.getStatusCode()).thenReturn(401); when(authCommand.call()).thenReturn(new AccessImpl()); this.account = new AccountImpl(authCommand, httpClient, defaultAccess, true); new CreateContainerCommand(this.account, httpClient, defaultAccess, account.getContainer("containerName")).call(); } #location 6 #vulnerability type RESOURCE_LEAK
#fixed code @Test(expected = UnauthorizedException.class) public void reauthenticateFailTwice() { when(statusLine.getStatusCode()).thenReturn(401); when(authCommand.call()).thenReturn(new AccessImpl()); this.account = new AccountImpl(authCommand, httpClient, defaultAccess, true); new CreateContainerCommandImpl(this.account, httpClient, defaultAccess, account.getContainer("containerName")).call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void pushToEmptyWebsite() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("websites"); website = new WebsiteMock(new AccountMock(swift), "website"); website.pushDirectory(FileAction.getFile("object-store/container1")); assertEquals(2, website.list().size()); } #location 6 #vulnerability type NULL_DEREFERENCE
#fixed code @Test public void pushToEmptyWebsite() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("websites", false); website = new WebsiteMock(new AccountMock(swift), "website"); website.pushDirectory(FileAction.getFile("object-store/container1")); assertEquals(2, website.list().size()); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void getInfo() { this.info = new ContainerInformationCommand(getAccount(), getClient(), getAccess(), this).call(); this.setInfoRetrieved(); } #location 2 #vulnerability type RESOURCE_LEAK
#fixed code protected void getInfo() { this.info = commandFactory.createContainerInformationCommand(getAccount(), getClient(), getAccess(), this).call(); this.setInfoRetrieved(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @SuppressWarnings("ConstantConditions") @Test public void pullWebsite() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("websites"); website = new WebsiteMock(new AccountMock(swift), "website"); website.pullDirectory(this.writeDir); assertEquals(5, writeDir.listFiles().length); } #location 8 #vulnerability type NULL_DEREFERENCE
#fixed code @SuppressWarnings("ConstantConditions") @Test public void pullWebsite() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("websites", false); website = new WebsiteMock(new AccountMock(swift), "website"); website.pullDirectory(this.writeDir); assertEquals(5, writeDir.listFiles().length); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void delete() { new DeleteObjectCommand(getAccount(), getClient(), getAccess(), this).call(); } #location 2 #vulnerability type RESOURCE_LEAK
#fixed code public void delete() { commandFactory.createDeleteObjectCommand(getAccount(), getClient(), getAccess(), this).call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void downloadObject(File targetFile, DownloadInstructions downloadInstructions) { new DownloadObjectToFileCommand(getAccount(), getClient(), getAccess(), this, downloadInstructions, targetFile).call(); } #location 2 #vulnerability type RESOURCE_LEAK
#fixed code public void downloadObject(File targetFile, DownloadInstructions downloadInstructions) { commandFactory.createDownloadObjectToFileCommand(getAccount(), getClient(), getAccess(), this, downloadInstructions, targetFile).call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void reauthenticateSuccess() { when(statusLine.getStatusCode()).thenReturn(401).thenReturn(201); when(authCommand.call()).thenReturn(new AccessImpl()); this.account = new AccountImpl(authCommand, httpClient, defaultAccess, true); new CreateContainerCommand(this.account, httpClient, defaultAccess, account.getContainer("containerName")).call(); } #location 6 #vulnerability type RESOURCE_LEAK
#fixed code @Test public void reauthenticateSuccess() { when(statusLine.getStatusCode()).thenReturn(401).thenReturn(201); when(authCommand.call()).thenReturn(new AccessImpl()); this.account = new AccountImpl(authCommand, httpClient, defaultAccess, true); new CreateContainerCommandImpl(this.account, httpClient, defaultAccess, account.getContainer("containerName")).call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void makePublic() { new ContainerRightsCommand(getAccount(), getClient(), getAccess(), this, true).call(); } #location 2 #vulnerability type RESOURCE_LEAK
#fixed code public void makePublic() { commandFactory.createContainerRightsCommand(getAccount(), getClient(), getAccess(), this, true).call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public StoredObject setContentType(String contentType) { checkForInfo(); info.setContentType(new ObjectContentType(contentType)); new ObjectMetadataCommand( getAccount(), getClient(), getAccess(), this, info.getHeadersIncludingHeader(info.getContentTypeHeader())).call(); return this; } #location 6 #vulnerability type RESOURCE_LEAK
#fixed code public StoredObject setContentType(String contentType) { checkForInfo(); info.setContentType(new ObjectContentType(contentType)); commandFactory.createObjectMetadataCommand( getAccount(), getClient(), getAccess(), this, info.getHeadersIncludingHeader(info.getContentTypeHeader())).call(); return this; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @SuppressWarnings("ConstantConditions") @Test public void ignoreFileOnPulling() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("object-store"); website = new WebsiteMock(new AccountMock(swift), "container1"); website.pullDirectory(this.writeDir); assertEquals(2, writeDir.listFiles().length); // 2 files website = new WebsiteMock(new AccountMock(swift), "container2") .setIgnoreFilters(new String[] {"checkmark.png"}); website.pullDirectory(this.writeDir); assertEquals(6, writeDir.listFiles().length); // 6 files, checkmark.png has not been removed } #location 8 #vulnerability type NULL_DEREFERENCE
#fixed code @SuppressWarnings("ConstantConditions") @Test public void ignoreFileOnPulling() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("object-store", false); website = new WebsiteMock(new AccountMock(swift), "container1"); website.pullDirectory(this.writeDir); assertEquals(2, writeDir.listFiles().length); // 2 files website = new WebsiteMock(new AccountMock(swift), "container2") .setIgnoreFilters(new String[] {"checkmark.png"}); website.pullDirectory(this.writeDir); assertEquals(6, writeDir.listFiles().length); // 6 files, checkmark.png has not been removed }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public InputStream downloadObjectAsInputStream(DownloadInstructions downloadInstructions) { return new DownloadObjectAsInputStreamCommand(getAccount(), getClient(), getAccess(), this, downloadInstructions).call(); } #location 2 #vulnerability type RESOURCE_LEAK
#fixed code public InputStream downloadObjectAsInputStream(DownloadInstructions downloadInstructions) { return commandFactory.createDownloadObjectAsInputStreamCommand(getAccount(), getClient(), getAccess(), this, downloadInstructions).call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test (expected = CommandException.class) public void unknownError() throws IOException { checkForError(500, new ContainerInformationCommand(this.account, httpClient, defaultAccess, account.getContainer("containerName"))); } #location 3 #vulnerability type RESOURCE_LEAK
#fixed code @Test (expected = CommandException.class) public void unknownError() throws IOException { checkForError(500, new ContainerInformationCommandImpl(this.account, httpClient, defaultAccess, account.getContainer("containerName"))); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Override protected void saveMetadata() { new ObjectMetadataCommand(getAccount(), getClient(), getAccess(), this, info.getHeaders()).call(); } #location 3 #vulnerability type RESOURCE_LEAK
#fixed code @Override protected void saveMetadata() { commandFactory.createObjectMetadataCommand(getAccount(), getClient(), getAccess(), this, info.getHeaders()).call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @SuppressWarnings("ConstantConditions") @Test public void pullDifferentWebsites() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("object-store"); website = new WebsiteMock(new AccountMock(swift), "container1"); website.pullDirectory(this.writeDir); assertEquals(2, writeDir.listFiles().length); // 2 files website = new WebsiteMock(new AccountMock(swift), "container2"); website.pullDirectory(this.writeDir); assertEquals(5, writeDir.listFiles().length); // 5 files } #location 8 #vulnerability type NULL_DEREFERENCE
#fixed code @SuppressWarnings("ConstantConditions") @Test public void pullDifferentWebsites() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("object-store", false); website = new WebsiteMock(new AccountMock(swift), "container1"); website.pullDirectory(this.writeDir); assertEquals(2, writeDir.listFiles().length); // 2 files website = new WebsiteMock(new AccountMock(swift), "container2"); website.pullDirectory(this.writeDir); assertEquals(5, writeDir.listFiles().length); // 5 files }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test(expected = UnauthorizedException.class) public void reauthenticateNotAllowed() { when(statusLine.getStatusCode()).thenReturn(401); this.account.setAllowReauthenticate(false); new CreateContainerCommand(this.account, httpClient, defaultAccess, account.getContainer("containerName")).call(); } #location 5 #vulnerability type RESOURCE_LEAK
#fixed code @Test(expected = UnauthorizedException.class) public void reauthenticateNotAllowed() { when(statusLine.getStatusCode()).thenReturn(401); this.account.setAllowReauthenticate(false); new CreateContainerCommandImpl(this.account, httpClient, defaultAccess, account.getContainer("containerName")).call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public Collection<StoredObject> list(String prefix, String marker, int pageSize) { ListInstructions listInstructions = new ListInstructions() .setPrefix(prefix) .setMarker(marker) .setLimit(pageSize); return new ListObjectsCommand(getAccount(), getClient(), getAccess(), this, listInstructions).call(); } #location 6 #vulnerability type RESOURCE_LEAK
#fixed code public Collection<StoredObject> list(String prefix, String marker, int pageSize) { ListInstructions listInstructions = new ListInstructions() .setPrefix(prefix) .setMarker(marker) .setLimit(pageSize); return commandFactory.createListObjectsCommand(getAccount(), getClient(), getAccess(), this, listInstructions).call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void getInfo() { this.info = new ObjectInformationCommand(getAccount(), getClient(), getAccess(), this).call(); this.setInfoRetrieved(); } #location 2 #vulnerability type RESOURCE_LEAK
#fixed code protected void getInfo() { this.info = commandFactory.createObjectInformationCommand(getAccount(), getClient(), getAccess(), this).call(); this.setInfoRetrieved(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void copyObject(Container targetContainer, StoredObject targetObject) { new CopyObjectCommand(getAccount(), getClient(), getAccess(), this, targetObject).call(); } #location 2 #vulnerability type RESOURCE_LEAK
#fixed code public void copyObject(Container targetContainer, StoredObject targetObject) { commandFactory.createCopyObjectCommand(getAccount(), getClient(), getAccess(), this, targetObject).call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void pushAndUpdate() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("websites"); website = new WebsiteMock(new AccountMock(swift), "website"); website.pushDirectory(FileAction.getFile("websites/website")); assertEquals(7, website.list().size()); website.pushDirectory(FileAction.getFile("websites/website2")); assertEquals(6, website.list().size()); } #location 6 #vulnerability type NULL_DEREFERENCE
#fixed code @Test public void pushAndUpdate() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("websites", false); website = new WebsiteMock(new AccountMock(swift), "website"); website.pushDirectory(FileAction.getFile("websites/website")); assertEquals(7, website.list().size()); website.pushDirectory(FileAction.getFile("websites/website2")); assertEquals(6, website.list().size()); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void getInfo() { ObjectInformation info = new ObjectInformationCommand(getAccount(), getClient(), getAccess(), getContainer(), this).call(); this.lastModified = info.getLastModified(); this.etag = info.getEtag(); this.contentLength = info.getContentLength(); this.contentType = info.getContentType(); this.setMetadata(info.getMetadata()); this.setInfoRetrieved(); } #location 3 #vulnerability type NULL_DEREFERENCE
#fixed code protected void getInfo() { this.info = new ObjectInformationCommand(getAccount(), getClient(), getAccess(), getContainer(), this).call(); this.setInfoRetrieved(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test(expected = CommandException.class) public void httpClientThrowsAnExceptionWithRootCause() throws IOException { IOException exc = new IOException("Mocked HTTP client error"); when(httpClient.execute(any(HttpRequestBase.class))).thenThrow(new CommandException("Something went wrong", exc)); new AuthenticationCommand(httpClient, "http://some.url", "some-tenant", "some-user", "some-pwd").call(); } #location 6 #vulnerability type RESOURCE_LEAK
#fixed code @Test(expected = CommandException.class) public void httpClientThrowsAnExceptionWithRootCause() throws IOException { IOException exc = new IOException("Mocked HTTP client error"); when(httpClient.execute(any(HttpRequestBase.class))).thenThrow(new CommandException("Something went wrong", exc)); new AuthenticationCommandImpl(httpClient, "http://some.url", "some-tenant", "some-user", "some-pwd").call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void checkAuthenticationToken() { when(statusLine.getStatusCode()).thenReturn(201); CreateContainerCommand command = new CreateContainerCommand(this.account, httpClient, defaultAccess, account.getContainer("containerName")); Header[] xAuth = command.request.getHeaders(Token.X_AUTH_TOKEN); assertEquals(1, xAuth.length); assertEquals("cafebabe", xAuth[0].getValue()); } #location 6 #vulnerability type RESOURCE_LEAK
#fixed code @Test public void checkAuthenticationToken() { when(statusLine.getStatusCode()).thenReturn(201); CreateContainerCommandImpl command = new CreateContainerCommandImpl(this.account, httpClient, defaultAccess, account.getContainer("containerName")); Header[] xAuth = command.request.getHeaders(Token.X_AUTH_TOKEN); assertEquals(1, xAuth.length); assertEquals("cafebabe", xAuth[0].getValue()); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void makePrivate() { new ContainerRightsCommand(getAccount(), getClient(), getAccess(), this, false).call(); } #location 2 #vulnerability type RESOURCE_LEAK
#fixed code public void makePrivate() { commandFactory.createContainerRightsCommand(getAccount(), getClient(), getAccess(), this, false).call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void pushTwiceToWebsite() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("websites"); website = new WebsiteMock(new AccountMock(swift), "website"); website.pushDirectory(FileAction.getFile("object-store/container1")); String lastModified1 = website.getObject("checkmark.png").getLastModified(); website.pushDirectory(FileAction.getFile("object-store/container1")); String lastModified2 = website.getObject("checkmark.png").getLastModified(); assertEquals(lastModified1, lastModified2); assertEquals(2, website.list().size()); } #location 6 #vulnerability type NULL_DEREFERENCE
#fixed code @Test public void pushTwiceToWebsite() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("websites", false); website = new WebsiteMock(new AccountMock(swift), "website"); website.pushDirectory(FileAction.getFile("object-store/container1")); String lastModified1 = website.getObject("checkmark.png").getLastModified(); website.pushDirectory(FileAction.getFile("object-store/container1")); String lastModified2 = website.getObject("checkmark.png").getLastModified(); assertEquals(lastModified1, lastModified2); assertEquals(2, website.list().size()); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void ignoreFoldersOnPushing() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("websites"); website = new WebsiteMock(new AccountMock(swift), "website") .setIgnoreFilters(new String[] {"script"} ); website.pushDirectory(FileAction.getFile("websites/website")); assertEquals(4, website.list().size()); } #location 7 #vulnerability type NULL_DEREFERENCE
#fixed code @Test public void ignoreFoldersOnPushing() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("websites", false); website = new WebsiteMock(new AccountMock(swift), "website") .setIgnoreFilters(new String[] {"script"} ); website.pushDirectory(FileAction.getFile("websites/website")); assertEquals(4, website.list().size()); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test(expected = CommandException.class) public void httpClientThrowsAnException() throws IOException { when(httpClient.execute(any(HttpRequestBase.class))).thenThrow(new IOException("Mocked HTTP client error")); new AuthenticationCommand(httpClient, "http://some.url", "some-tenant", "some-user", "some-pwd").call(); } #location 4 #vulnerability type RESOURCE_LEAK
#fixed code @Test(expected = CommandException.class) public void httpClientThrowsAnException() throws IOException { when(httpClient.execute(any(HttpRequestBase.class))).thenThrow(new IOException("Mocked HTTP client error")); new AuthenticationCommandImpl(httpClient, "http://some.url", "some-tenant", "some-user", "some-pwd").call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void directlyUploadObject(UploadInstructions uploadInstructions) { new UploadObjectCommand(getAccount(), getClient(), getAccess(), this, uploadInstructions).call(); } #location 2 #vulnerability type RESOURCE_LEAK
#fixed code public void directlyUploadObject(UploadInstructions uploadInstructions) { commandFactory.createUploadObjectCommand(getAccount(), getClient(), getAccess(), this, uploadInstructions).call(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public static void main(String args[]) throws IOException { if (args.length != 3) { System.out.println("Use syntax: <USERNAME> <PASSWORD> <URL>"); return; } String username = args[0]; String password = args[1]; String url = args[2]; System.out.println("Executing with "+username+"/"+password+"@"+url); OpenStackClient client = new OpenStackClientImpl(); client.authenticate(username, password, url); // client.makeContainerPublic(new Container("Eindhoven")); // client.makeContainerPrivate(new Container("Eindhoven")); // Map<String, Object> metadata = new TreeMap<String, Object>(); // metadata.put("Year", "1989"); // metadata.put("Owner", "42 BV"); // client.setAccountInformation(metadata); // AccountInformation accountInformation = client.getAccountInformation(); // System.out.println("Containers in use: "+accountInformation.getContainerCount()); // System.out.println("Objects in use: "+accountInformation.getObjectCount()); // System.out.println("Bytes used: "+accountInformation.getBytesUsed()); // System.out.println("Year: "+accountInformation.getMetadata().get("Year")); // System.out.println("Owner: "+accountInformation.getMetadata().get("Owner")); // System.out.println("Tilburg: "+client.getContainerInformation(new Container("Tilburg")).isPublicContainer()); // System.out.println("Breda: "+client.getContainerInformation(new Container("Breda")).isPublicContainer()); // System.out.println("Eindhoven: " + client.getContainerInformation(new Container("Eindhoven")).isPublicContainer()); // ContainerInformation info = client.getContainerInformation(new Container("Tilburg")); // System.out.println("Object count: "+info.getObjectCount()); // System.out.println("Bytes used: "+info.getBytesUsed()); // System.out.println("Public?: "+info.isPublicContainer()); // InputStream inputStream = new FileInputStream(new File("/Users/robertbor/Downloads/dog.png")); // byte[] fileToUpload = IOUtils.toByteArray(inputStream); // inputStream.close(); // client.uploadObject(new Container("Tilburg"), new StoreObject("somedog3.png"), fileToUpload); // Container container = new Container("Tilburg"); // StoreObject sourceObject = new StoreObject("somedog5.png"); // StoreObject targetObject = new StoreObject("newdog.png"); // client.uploadObject(container, sourceObject, new File("/Users/robertbor/Downloads/dog.png")); // client.copyObject(container, sourceObject, container, targetObject); byte[] plaatje = client.downloadObject(new Container("Tilburg"), new StoreObject("doggie.png")); System.out.println("Grootte plaatje: " + plaatje.length); FileOutputStream fos = new FileOutputStream(new File("plaatje.png")); fos.write(plaatje); fos.close(); client.downloadObject(new Container("Tilburg"), new StoreObject("doggie.png"), new File("plaatje2.png")); // uploadFile(client, "Tilburg", "doggie.png", new File("/Users/robertbor/Downloads/dog.png")); // client.uploadObject(new Container("Tilburg"), new StoreObject("doggie.png"), new File("/Users/robertbor/Downloads/dog.png")); // client.deleteObject(new Container("Tilburg"), new StoreObject("somedog5.png")); // ContainerInformation info2 = client.getContainerInformation(new Container("Tilburg")); // System.out.println("\nAFTER"); // System.out.println("Object count: "+info2.getObjectCount()); // System.out.println("Bytes used: "+info2.getBytesUsed()); // Map<String, Object> metadata = new TreeMap<String, Object>(); // metadata.put("Description", "Kantoor Eindhoven, inclusief randgemeenten"); // metadata.put("Province", "Noord Brabant"); // metadata.put("Country", "Nederland"); // client.setContainerInformation(new Container("Eindhoven"), metadata); // client.setObjectInformation(new Container("Tilburg"), new StoreObject("somedog.png"), metadata); // // ObjectInformation info = client.getObjectInformation(new Container("Tilburg"), new StoreObject("somedog.png")); // System.out.println("Last modified: "+info.getLastModified()); // System.out.println("ETag: "+info.getEtag()); // System.out.println("Content type: "+info.getContentType()); // System.out.println("Content length: "+info.getContentLength()); // for (String key : info.getMetadata().keySet()) { // System.out.println("META / "+key+": "+info.getMetadata().get(key)); // } // StoreObject objects[] = client.listObjects(new Container("Tilburg")); // for (StoreObject object : objects) { // System.out.println("* object -> "+object); // } // client.createContainer(new Container("Leiden")); // client.deleteContainer(new Container("Leiden")); // Map<String, Object> metadata = new TreeMap<String, Object>(); // metadata.put("Description", "Kantoor Eindhoven, inclusief randgemeenten"); // metadata.put("Province", "Noord Brabant"); // metadata.put("Country", "Nederland"); // client.setContainerInformation(new Container("Eindhoven"), metadata); // ContainerInformation info = client.getContainerInformation(new Container("Eindhoven")); // System.out.println("Object count: "+info.getObjectCount()); // System.out.println("Bytes used: "+info.getBytesUsed()); // System.out.println("Description: "+info.getMetadata().get("Description")); // System.out.println("Province: "+info.getMetadata().get("Province")); // System.out.println("Country: "+info.getMetadata().get("Country")); // // Container[] containers = client.listContainers(); // for (Container container : containers) { // System.out.println(container); // } } #location 50 #vulnerability type NULL_DEREFERENCE
#fixed code public static void main(String args[]) throws IOException { if (args.length != 3) { System.out.println("Use syntax: <USERNAME> <PASSWORD> <URL>"); return; } String username = args[0]; String password = args[1]; String url = args[2]; System.out.println("Executing with "+username+"/"+password+"@"+url); OpenStackClient client = new OpenStackClientImpl(); client.authenticate(username, password, url); // client.makeContainerPublic(new Container("Eindhoven")); // client.makeContainerPrivate(new Container("Eindhoven")); // Map<String, Object> metadata = new TreeMap<String, Object>(); // metadata.put("Year", "1989"); // metadata.put("Owner", "42 BV"); // client.setAccountInformation(metadata); // AccountInformation accountInformation = client.getAccountInformation(); // System.out.println("Containers in use: "+accountInformation.getContainerCount()); // System.out.println("Objects in use: "+accountInformation.getObjectCount()); // System.out.println("Bytes used: "+accountInformation.getBytesUsed()); // System.out.println("Year: "+accountInformation.getMetadata().get("Year")); // System.out.println("Owner: "+accountInformation.getMetadata().get("Owner")); // System.out.println("Tilburg: "+client.getContainerInformation(new Container("Tilburg")).isPublicContainer()); // System.out.println("Breda: "+client.getContainerInformation(new Container("Breda")).isPublicContainer()); // System.out.println("Eindhoven: " + client.getContainerInformation(new Container("Eindhoven")).isPublicContainer()); // ContainerInformation info = client.getContainerInformation(new Container("Tilburg")); // System.out.println("Object count: "+info.getObjectCount()); // System.out.println("Bytes used: "+info.getBytesUsed()); // System.out.println("Public?: "+info.isPublicContainer()); // InputStream inputStream = new FileInputStream(new File("/Users/robertbor/Downloads/dog.png")); // byte[] fileToUpload = IOUtils.toByteArray(inputStream); // inputStream.close(); // client.uploadObject(new Container("Tilburg"), new StoreObject("somedog3.png"), fileToUpload); // Container container = new Container("Tilburg"); // StoreObject sourceObject = new StoreObject("somedog5.png"); // StoreObject targetObject = new StoreObject("newdog.png"); // client.uploadObject(container, sourceObject, new File("/Users/robertbor/Downloads/dog.png")); // client.copyObject(container, sourceObject, container, targetObject); // DOWNLOAD AN IMAGE TO A BYTE ARRAY AND THEN SAVE IT TO FILE // byte[] plaatje = client.downloadObject(new Container("Tilburg"), new StoreObject("doggie.png")); // System.out.println("Grootte plaatje: " + plaatje.length); // FileOutputStream fos = new FileOutputStream(new File("plaatje.png")); // fos.write(plaatje); // fos.close(); // DOWNLOAD AN IMAGE TO FILE // client.downloadObject(new Container("Tilburg"), new StoreObject("doggie.png"), new File("plaatje2.png")); // DOWNLOAD AN IMAGE TO AN INPUTSTREAM AND SAVE IT TO FILE // InputStreamWrapper wrapper = client.downloadObjectAsInputStream(new Container("Tilburg"), new StoreObject("doggie.png")); // FileOutputStream fos = new FileOutputStream(new File("plaatje.png")); // IOUtils.copy(wrapper.getInputStream(), fos); // fos.close(); // wrapper.closeStream(); // Important to clean up the original response object // uploadFile(client, "Tilburg", "doggie.png", new File("/Users/robertbor/Downloads/dog.png")); // client.uploadObject(new Container("Tilburg"), new StoreObject("doggie.png"), new File("/Users/robertbor/Downloads/dog.png")); // client.deleteObject(new Container("Tilburg"), new StoreObject("somedog5.png")); // ContainerInformation info2 = client.getContainerInformation(new Container("Tilburg")); // System.out.println("\nAFTER"); // System.out.println("Object count: "+info2.getObjectCount()); // System.out.println("Bytes used: "+info2.getBytesUsed()); // Map<String, Object> metadata = new TreeMap<String, Object>(); // metadata.put("Description", "Kantoor Eindhoven, inclusief randgemeenten"); // metadata.put("Province", "Noord Brabant"); // metadata.put("Country", "Nederland"); // client.setContainerInformation(new Container("Eindhoven"), metadata); // client.setObjectInformation(new Container("Tilburg"), new StoreObject("somedog.png"), metadata); // // ObjectInformation info = client.getObjectInformation(new Container("Tilburg"), new StoreObject("somedog.png")); // System.out.println("Last modified: "+info.getLastModified()); // System.out.println("ETag: "+info.getEtag()); // System.out.println("Content type: "+info.getContentType()); // System.out.println("Content length: "+info.getContentLength()); // for (String key : info.getMetadata().keySet()) { // System.out.println("META / "+key+": "+info.getMetadata().get(key)); // } // StoreObject objects[] = client.listObjects(new Container("Tilburg")); // for (StoreObject object : objects) { // System.out.println("* object -> "+object); // } // client.createContainer(new Container("Leiden")); // client.deleteContainer(new Container("Leiden")); // Map<String, Object> metadata = new TreeMap<String, Object>(); // metadata.put("Description", "Kantoor Eindhoven, inclusief randgemeenten"); // metadata.put("Province", "Noord Brabant"); // metadata.put("Country", "Nederland"); // client.setContainerInformation(new Container("Eindhoven"), metadata); // ContainerInformation info = client.getContainerInformation(new Container("Eindhoven")); // System.out.println("Object count: "+info.getObjectCount()); // System.out.println("Bytes used: "+info.getBytesUsed()); // System.out.println("Description: "+info.getMetadata().get("Description")); // System.out.println("Province: "+info.getMetadata().get("Province")); // System.out.println("Country: "+info.getMetadata().get("Country")); // // Container[] containers = client.listContainers(); // for (Container container : containers) { // System.out.println(container); // } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public StoredObject setDeleteAfter(long seconds) { checkForInfo(); info.setDeleteAt(null); info.setDeleteAfter(new DeleteAfter(seconds)); new ObjectMetadataCommand( getAccount(), getClient(), getAccess(), this, info.getHeadersIncludingHeader(info.getDeleteAfter())).call(); return this; } #location 7 #vulnerability type RESOURCE_LEAK
#fixed code public StoredObject setDeleteAfter(long seconds) { checkForInfo(); info.setDeleteAt(null); info.setDeleteAfter(new DeleteAfter(seconds)); commandFactory.createObjectMetadataCommand( getAccount(), getClient(), getAccess(), this, info.getHeadersIncludingHeader(info.getDeleteAfter())).call(); return this; }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code @Test public void pushTwiceToWebsite() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("websites"); website = new WebsiteMock(new AccountMock(swift), "website"); website.pushDirectory(FileAction.getFile("object-store/container1")); String lastModified1 = website.getObject("checkmark.png").getLastModified(); website.pushDirectory(FileAction.getFile("object-store/container1")); String lastModified2 = website.getObject("checkmark.png").getLastModified(); assertEquals(lastModified1, lastModified2); assertEquals(2, website.list().size()); } #location 6 #vulnerability type NULL_DEREFERENCE
#fixed code @Test public void pushTwiceToWebsite() throws IOException, URISyntaxException { Swift swift = new Swift() .setOnFileObjectStore("websites", false); website = new WebsiteMock(new AccountMock(swift), "website"); website.pushDirectory(FileAction.getFile("object-store/container1")); String lastModified1 = website.getObject("checkmark.png").getLastModified(); website.pushDirectory(FileAction.getFile("object-store/container1")); String lastModified2 = website.getObject("checkmark.png").getLastModified(); assertEquals(lastModified1, lastModified2); assertEquals(2, website.list().size()); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void testWrite() throws Exception { final File out1 = File.createTempFile("jdeb", ".ar"); final ArOutputStream os = new ArOutputStream(new FileOutputStream(out1)); os.putNextEntry(new ArEntry("data", 4)); os.write("data".getBytes()); os.close(); assertTrue(out1.delete()); } #location 10 #vulnerability type RESOURCE_LEAK
#fixed code public void testWrite() throws Exception { final File out1 = File.createTempFile("jdeb", ".ar"); final ArArchiveOutputStream os = new ArArchiveOutputStream(new FileOutputStream(out1)); os.putArchiveEntry(new ArArchiveEntry("data", 4)); os.write("data".getBytes()); os.closeArchiveEntry(); os.close(); assertTrue(out1.delete()); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void testCreation() throws Exception { final Processor processor = new Processor(new Console() { public void println(String s) { } }, null); final File control = new File(getClass().getResource("deb/control/control").toURI()); final File archive1 = new File(getClass().getResource("deb/data.tgz").toURI()); final File archive2 = new File(getClass().getResource("deb/data.tar.bz2").toURI()); final File directory = new File(getClass().getResource("deb/data").toURI()); final DataProducer[] data = new DataProducer[] { new DataProducerArchive(archive1, null, null, null), new DataProducerArchive(archive2, null, null, null), new DataProducerDirectory(directory, null, new String[] { "**/.svn/**" }, null) }; final File deb = File.createTempFile("jdeb", ".deb"); final PackageDescriptor packageDescriptor = processor.createDeb(new File[] { control }, data, deb, "gzip"); assertTrue(packageDescriptor.isValid()); final Set filesInDeb = new HashSet(); final ArInputStream ar = new ArInputStream(new FileInputStream(deb)); while(true) { final ArEntry arEntry = ar.getNextEntry(); if (arEntry == null) { break; } if ("data.tar.gz".equals(arEntry.getName())) { final TarInputStream tar = new TarInputStream(new GZIPInputStream(ar)); while(true) { final TarEntry tarEntry = tar.getNextEntry(); if (tarEntry == null) { break; } filesInDeb.add(tarEntry.getName()); } tar.close(); break; } for (int i = 0; i < arEntry.getLength(); i++) { ar.read(); } } assertTrue("" + filesInDeb, filesInDeb.contains("/test/testfile")); assertTrue("" + filesInDeb, filesInDeb.contains("/test/testfile2")); assertTrue("" + filesInDeb, filesInDeb.contains("/test/testfile3")); assertTrue(deb.delete()); } #location 36 #vulnerability type RESOURCE_LEAK
#fixed code public void testCreation() throws Exception { final Processor processor = new Processor(new Console() { public void println(String s) { } }, null); final File control = new File(getClass().getResource("deb/control/control").toURI()); final File archive1 = new File(getClass().getResource("deb/data.tgz").toURI()); final File archive2 = new File(getClass().getResource("deb/data.tar.bz2").toURI()); final File directory = new File(getClass().getResource("deb/data").toURI()); final DataProducer[] data = new DataProducer[] { new DataProducerArchive(archive1, null, null, null), new DataProducerArchive(archive2, null, null, null), new DataProducerDirectory(directory, null, new String[] { "**/.svn/**" }, null) }; final File deb = File.createTempFile("jdeb", ".deb"); final PackageDescriptor packageDescriptor = processor.createDeb(new File[] { control }, data, deb, "gzip"); assertTrue(packageDescriptor.isValid()); final Set filesInDeb = new HashSet(); FileInputStream in = new FileInputStream(deb); final ArInputStream ar = new ArInputStream(in); while(true) { final ArEntry arEntry = ar.getNextEntry(); if (arEntry == null) { break; } if ("data.tar.gz".equals(arEntry.getName())) { final TarInputStream tar = new TarInputStream(new GZIPInputStream(ar)); while(true) { final TarEntry tarEntry = tar.getNextEntry(); if (tarEntry == null) { break; } filesInDeb.add(tarEntry.getName()); } tar.close(); break; } for (int i = 0; i < arEntry.getLength(); i++) { ar.read(); } } in.close(); assertTrue("" + filesInDeb, filesInDeb.contains("/test/testfile")); assertTrue("" + filesInDeb, filesInDeb.contains("/test/testfile2")); assertTrue("" + filesInDeb, filesInDeb.contains("/test/testfile3")); assertTrue("Cannot delete the file " + deb, deb.delete()); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code protected void parse( final InputStream pInput ) throws IOException, ParseException { final BufferedReader br = new BufferedReader(new InputStreamReader(pInput)); StringBuffer buffer = new StringBuffer(); String key = null; int linenr = 0; while(true) { final String line = br.readLine(); if (line == null) { if (buffer.length() > 0) { // flush value of previous key set(key, buffer.toString()); buffer = null; } break; } linenr++; final char first = line.charAt(0); if (Character.isLetter(first)) { // new key if (buffer.length() > 0) { // flush value of previous key set(key, buffer.toString()); buffer = new StringBuffer(); } final int i = line.indexOf(':'); if (i < 0) { throw new ParseException("Line misses ':' delimitter", linenr); } key = line.substring(0, i); buffer.append(line.substring(i+1).trim()); continue; } // continueing old value buffer.append('\n').append(line.substring(1)); } br.close(); } #location 14 #vulnerability type RESOURCE_LEAK
#fixed code protected void parse( final InputStream pInput ) throws IOException, ParseException { final BufferedReader br = new BufferedReader(new InputStreamReader(pInput)); StringBuffer buffer = new StringBuffer(); String key = null; int linenr = 0; while(true) { final String line = br.readLine(); if (line == null) { if (buffer.length() > 0) { // flush value of previous key set(key, buffer.toString()); buffer = null; } break; } linenr++; final char first = line.charAt(0); if (Character.isLetter(first)) { // new key if (buffer.length() > 0) { // flush value of previous key set(key, buffer.toString()); buffer = new StringBuffer(); } final int i = line.indexOf(':'); if (i < 0) { throw new ParseException("Line misses ':' delimitter", linenr); } key = line.substring(0, i); buffer.append(line.substring(i+1).trim()); continue; } // continuing old value buffer.append('\n').append(line.substring(1)); } br.close(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code String toString( final String[] pKeys ) { final StringBuffer s = new StringBuffer(); for (int i = 0; i < pKeys.length; i++) { final String key = pKeys[i]; final String value = (String) values.get(key); if (value != null) { s.append(key).append(": "); try { LineNumberReader reader = new LineNumberReader(new StringReader(value)); String line; while ((line = reader.readLine()) != null) { if (reader.getLineNumber() > 0 && line.length() != 0 && !Character.isWhitespace(line.charAt(0))) { // indent the line with a white space s.append(' '); } s.append(line).append('\n'); } } catch (IOException e) { e.printStackTrace(); } } } return s.toString(); } #location 12 #vulnerability type RESOURCE_LEAK
#fixed code String toString( final String[] pKeys ) { final StringBuffer s = new StringBuffer(); for (int i = 0; i < pKeys.length; i++) { final String key = pKeys[i]; final String value = (String) values.get(key); if (value != null) { s.append(key).append(":"); try { BufferedReader reader = new BufferedReader(new StringReader(value)); String line; while ((line = reader.readLine()) != null) { if (line.length() != 0 && !Character.isWhitespace(line.charAt(0))) { s.append(' '); } s.append(line).append('\n'); } } catch (IOException e) { e.printStackTrace(); } } } return s.toString(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void execute() { if (control == null || !control.isDirectory()) { throw new BuildException("You need to point the 'control' attribute to the control directory."); } if (changes != null && !changes.isFile()) { throw new BuildException("If you want the changes written out provide the file via 'changes' attribute."); } if (dataProducers.size() == 0) { throw new BuildException("You need to provide at least one reference to a tgz or directory with data."); } if (deb == null) { throw new BuildException("You need to point the 'destfile' attribute to where the deb is supposed to be created."); } final File[] controlFiles = control.listFiles(); final DataProducer[] data = new DataProducer[dataProducers.size()]; dataProducers.toArray(data); final Processor processor = new Processor(new Console() { public void println(String s) { log(s); } }); try { final ChangesDescriptor changesDescriptor = processor.createDeb(controlFiles, data, new FileOutputStream(deb)); if (changes != null) { processor.createChanges(changesDescriptor, new FileOutputStream(changes)); } } catch (Exception e) { log("failed to create debian package " + e); e.printStackTrace(); } log("created " + deb); } #location 34 #vulnerability type RESOURCE_LEAK
#fixed code public void execute() { if (control == null || !control.isDirectory()) { throw new BuildException("You need to point the 'control' attribute to the control directory."); } if (changes != null && changes.isDirectory()) { throw new BuildException("If you want the changes written out provide the file via 'changes' attribute."); } if (dataProducers.size() == 0) { throw new BuildException("You need to provide at least one reference to a tgz or directory with data."); } if (deb == null) { throw new BuildException("You need to point the 'destfile' attribute to where the deb is supposed to be created."); } final File[] controlFiles = control.listFiles(); final DataProducer[] data = new DataProducer[dataProducers.size()]; dataProducers.toArray(data); final Processor processor = new Processor(new Console() { public void println(String s) { log(s); } }); try { final ChangesDescriptor changesDescriptor = processor.createDeb(controlFiles, data, new FileOutputStream(deb)); log("created " + deb); if (changes != null) { processor.createChanges(changesDescriptor, new FileOutputStream(changes)); log("created changes file " + changes); } } catch (Exception e) { log("failed to create debian package " + e); e.printStackTrace(); } }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void testRead() throws Exception { final File archive = new File(getClass().getResource("data.ar").toURI()); final ArInputStream ar = new ArInputStream(new FileInputStream(archive)); final ArEntry entry1 = ar.getNextEntry(); assertEquals("data.tgz", entry1.getName()); assertEquals(148, entry1.getLength()); for (int i = 0; i < entry1.getLength(); i++) { ar.read(); } final ArEntry entry2 = ar.getNextEntry(); assertNull(entry2); } #location 14 #vulnerability type RESOURCE_LEAK
#fixed code public void testRead() throws Exception { final File archive = new File(getClass().getResource("data.ar").toURI()); final ArInputStream ar = new ArInputStream(new FileInputStream(archive)); final ArEntry entry1 = ar.getNextEntry(); assertEquals("data.tgz", entry1.getName()); assertEquals(148, entry1.getLength()); for (int i = 0; i < entry1.getLength(); i++) { ar.read(); } final ArEntry entry2 = ar.getNextEntry(); assertNull(entry2); ar.close(); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void testTarFileSet() throws Exception { project.executeTarget("tarfileset"); File deb = new File("target/test-classes/test.deb"); assertTrue("package not build", deb.exists()); ArArchiveInputStream in = new ArArchiveInputStream(new FileInputStream(deb)); ArArchiveEntry entry; while ((entry = in.getNextArEntry()) != null) { if (entry.getName().equals("data.tar.gz")) { TarInputStream tar = new TarInputStream(new GZIPInputStream(new NonClosingInputStream(in))); TarEntry tarentry; while ((tarentry = tar.getNextEntry()) != null) { assertTrue("prefix", tarentry.getName().startsWith("./foo/")); if (tarentry.isDirectory()) { assertEquals("directory mode (" + tarentry.getName() + ")", 040700, tarentry.getMode()); } else { assertEquals("file mode (" + tarentry.getName() + ")", 0100600, tarentry.getMode()); } assertEquals("user", "ebourg", tarentry.getUserName()); assertEquals("group", "ebourg", tarentry.getGroupName()); } tar.close(); } else { // skip to the next entry long skip = entry.getLength(); while (skip > 0) { long skipped = in.skip(skip); if (skipped == -1) { throw new IOException("Failed to skip"); } skip -= skipped; } } } in.close(); } #location 30 #vulnerability type RESOURCE_LEAK
#fixed code public void testTarFileSet() throws Exception { project.executeTarget("tarfileset"); File deb = new File("target/test-classes/test.deb"); assertTrue("package not build", deb.exists()); ArchiveWalker.walkData(deb, new ArchiveVisitor<TarArchiveEntry>() { public void visit(TarArchiveEntry entry, byte[] content) throws IOException { assertTrue("prefix", entry.getName().startsWith("./foo/")); if (entry.isDirectory()) { assertEquals("directory mode (" + entry.getName() + ")", 040700, entry.getMode()); } else { assertEquals("file mode (" + entry.getName() + ")", 0100600, entry.getMode()); } assertEquals("user", "ebourg", entry.getUserName()); assertEquals("group", "ebourg", entry.getGroupName()); } }, Compression.GZIP); }
Below is the vulnerable code, please generate the patch based on the following information.
#vulnerable code public void testTarFileSet() throws Exception { project.executeTarget("tarfileset"); File deb = new File("target/test-classes/test.deb"); assertTrue("package not build", deb.exists()); ArArchiveInputStream in = new ArArchiveInputStream(new FileInputStream(deb)); ArArchiveEntry entry; while ((entry = in.getNextArEntry()) != null) { if (entry.getName().equals("data.tar.gz")) { TarInputStream tar = new TarInputStream(new GZIPInputStream(new NonClosingInputStream(in))); TarEntry tarentry; while ((tarentry = tar.getNextEntry()) != null) { assertTrue("prefix", tarentry.getName().startsWith("./foo/")); if (tarentry.isDirectory()) { assertEquals("directory mode (" + tarentry.getName() + ")", 040700, tarentry.getMode()); } else { assertEquals("file mode (" + tarentry.getName() + ")", 0100600, tarentry.getMode()); } assertEquals("user", "ebourg", tarentry.getUserName()); assertEquals("group", "ebourg", tarentry.getGroupName()); } tar.close(); } else { // skip to the next entry long skip = entry.getLength(); while (skip > 0) { long skipped = in.skip(skip); if (skipped == -1) { throw new IOException("Failed to skip"); } skip -= skipped; } } } in.close(); } #location 11 #vulnerability type RESOURCE_LEAK
#fixed code public void testTarFileSet() throws Exception { project.executeTarget("tarfileset"); File deb = new File("target/test-classes/test.deb"); assertTrue("package not build", deb.exists()); ArchiveWalker.walkData(deb, new ArchiveVisitor<TarArchiveEntry>() { public void visit(TarArchiveEntry entry, byte[] content) throws IOException { assertTrue("prefix", entry.getName().startsWith("./foo/")); if (entry.isDirectory()) { assertEquals("directory mode (" + entry.getName() + ")", 040700, entry.getMode()); } else { assertEquals("file mode (" + entry.getName() + ")", 0100600, entry.getMode()); } assertEquals("user", "ebourg", entry.getUserName()); assertEquals("group", "ebourg", entry.getGroupName()); } }, Compression.GZIP); }
Below is the vulnerable code, please generate the patch based on the following information.