Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-49070] Avoid serializing BigDecimal and BigInteger in the model
  • Loading branch information
abayer committed Jan 22, 2018
1 parent 43518c3 commit 029b1f9
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 1 deletion.
Expand Up @@ -1165,7 +1165,16 @@ class ModelParser implements Parser {
*/
protected ModelASTValue parseArgument(Expression e) {
if (e instanceof ConstantExpression) {
return ModelASTValue.fromConstant(e.value, e)
Object val = e.value
if (val instanceof BigDecimal) {
val = val.doubleValue()
} else if (val instanceof BigInteger) {
if (val > Long.MAX_VALUE || val < Long.MIN_VALUE) {
errorCollector.error(ModelASTValue.fromConstant(-1, e), Messages.ModelParser_BigIntegerValue())
}
val = -1
}
return ModelASTValue.fromConstant(val, e)
}
if (e instanceof GStringExpression) {
String rawSrc = getSourceText(e)
Expand Down
Expand Up @@ -34,6 +34,7 @@ Parser.Triggers=Triggers
Parser.UndefinedSection=Undefined section "{0}"

ModelParser.BareDollarCurly={0} cannot be used as a value directly. Did you mean "{0}"?
ModelParser.BigIntegerValue=BigIntegers cannot be used as constants in Declarative. The maximum value for an integer is 9,223,372,036,854,775,807 and the minimum value for an integer is -9,223,372,036,854,775,808.
ModelParser.CannotHaveBlocks={0} definitions cannot have blocks
ModelParser.DuplicateEnvVar=Duplicate environment variable name: "{0}"
ModelParser.ExpectedAgent=Expected an agent
Expand Down
Expand Up @@ -38,6 +38,7 @@
import org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction;
import org.jenkinsci.plugins.pipeline.modeldefinition.actions.ExecutionModelAction;
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTBranch;
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTKey;
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTNamedArgumentList;
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTScriptBlock;
import org.jenkinsci.plugins.pipeline.modeldefinition.ast.ModelASTSingleArgument;
Expand Down Expand Up @@ -1268,4 +1269,52 @@ public void declarativeJobAction() throws Exception {
j.buildAndAssertSuccess(j2);
assertNull(j2.getAction(DeclarativeJobAction.class));
}

@Issue("JENKINS-49070")
@Test
public void bigDecimalConverts() throws Exception {
WorkflowRun b = expect("bigDecimalConverts").go();

ExecutionModelAction action = b.getAction(ExecutionModelAction.class);
assertNotNull(action);
ModelASTStages stages = action.getStages();
assertNull(stages.getSourceLocation());
assertNotNull(stages);

assertEquals(1, stages.getStages().size());

ModelASTStage stage = stages.getStages().get(0);
assertNull(stage.getSourceLocation());
assertNotNull(stage);

assertEquals(1, stage.getBranches().size());

ModelASTBranch firstBranch = branchForName("default", stage.getBranches());
assertNotNull(firstBranch);
assertNull(firstBranch.getSourceLocation());
assertNotNull(firstBranch);
assertEquals(1, firstBranch.getSteps().size());
ModelASTStep firstStep = firstBranch.getSteps().get(0);
assertNull(firstStep.getSourceLocation());
assertEquals("junit", firstStep.getName());
assertTrue(firstStep.getArgs() instanceof ModelASTNamedArgumentList);
ModelASTNamedArgumentList args = (ModelASTNamedArgumentList)firstStep.getArgs();

ModelASTValue val = null;
for (ModelASTKey k : args.getArguments().keySet()) {
if (k.getKey().equals("healthScaleFactor")) {
val = args.getArguments().get(k);
}
}

assertNotNull(val);

Object realVal = val.getValue();

assertTrue(realVal instanceof Double);

assertEquals(new Double("1.0"), realVal);

}

}
Expand Up @@ -874,4 +874,12 @@ public void invalidParameterTypeInInput() throws Exception {
Parameters.getAllowedParameterTypes().keySet()))
.go();
}

@Issue("JENKINS-49070")
@Test
public void bigIntegerFailure() throws Exception {
expectError("bigIntegerFailure")
.logContains(Messages.ModelParser_BigIntegerValue())
.go();
}
}
@@ -0,0 +1,37 @@
/*
* The MIT License
*
* Copyright (c) 2018, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

pipeline {
agent any
stages {
stage("foo") {
steps {
junit allowEmptyResults: true, testResults: 'junitResult.xml', healthScaleFactor: 1.0
}
}
}
}



@@ -0,0 +1,39 @@
/*
* The MIT License
*
* Copyright (c) 2018, CloudBees, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

pipeline {
agent none
stages {
stage("foo") {
steps {
timeout(time: 9223372036854775808) {
echo "hello"
}
}
}
}
}



0 comments on commit 029b1f9

Please sign in to comment.