Skip to content
Permalink
Browse files

Merge pull request #239 from abayer/jenkins-49070

[JENKINS-49070] Avoid serializing BigDecimal and BigInteger in the model
  • Loading branch information...
abayer committed Jan 29, 2018
2 parents 7736888 + 441c3dd commit 6fd36ef29323d404945057cb6a94b7234f56e95b
@@ -20,7 +20,7 @@ pipeline {
environment {
GIT_COMMITTER_NAME = "jenkins"
GIT_COMMITTER_EMAIL = "jenkins@jenkins.io"
NEWER_CORE_VERSION = "2.89.2"
NEWER_CORE_VERSION = "2.89.3"
}


@@ -1165,7 +1165,18 @@ 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
} else {
val = val.longValue()
}
}
return ModelASTValue.fromConstant(val, e)
}
if (e instanceof GStringExpression) {
String rawSrc = getSourceText(e)
@@ -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
@@ -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;
@@ -1268,4 +1269,50 @@ 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();

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

}

}
@@ -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 6fd36ef

Please sign in to comment.
You can’t perform that action at this time.