Skip to content

Commit

Permalink
Fix ClassCastException when using a memory value without unit
Browse files Browse the repository at this point in the history
  • Loading branch information
WGautier committed Sep 23, 2015
1 parent de4347d commit 5e21d2d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions src/main/java/com/hpe/cloudfoundryjenkins/DeploymentInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,24 @@ private void readManifestFile(PrintStream logger, Map<String, Object> manifestJs
appName = jenkinsBuildName;
}

int memory = 0;
String memString = (String) manifestJson.get("memory");
if (memString == null) {
int memory;
Object mem = manifestJson.get("memory");
if (mem == null) {
logger.println("WARNING: No manifest value for memory. Using default value: " +
DescriptorImpl.DEFAULT_MEMORY);
memory = DescriptorImpl.DEFAULT_MEMORY;
} else if (memString.toLowerCase().endsWith("m")) {
memory = Integer.parseInt(memString.substring(0, memString.length() - 1));
} else {
// The YAML parser from ManifestReader might make the memory value an Integer or a String
// depending on whether or not there is a unit at the end of the value
if(mem instanceof Integer) {
memory = (Integer) mem;
} else {
String memString = (String) mem;
if (memString.toLowerCase().endsWith("m")) {
memString = memString.substring(0, memString.length() - 1);
}
memory = Integer.parseInt(memString);
}
}
this.memory = memory;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
applications:
- name: hello-java
memory: 512M
memory: 512
host: testhost
instances: 4
timeout: 42
Expand Down

0 comments on commit 5e21d2d

Please sign in to comment.