You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by sl...@apache.org on 2020/09/14 12:10:46 UTC

[incubator-daffodil] branch master updated: Correctly expand varargs in String.format call

This is an automated email from the ASF dual-hosted git repository.

slawrence pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-daffodil.git


The following commit(s) were added to refs/heads/master by this push:
     new 60675a3  Correctly expand varargs in String.format call
60675a3 is described below

commit 60675a371ec7beb51e0b606e41f12346533952ed
Author: Steve Lawrence <sl...@apache.org>
AuthorDate: Fri Sep 11 12:38:26 2020 -0400

    Correctly expand varargs in String.format call
    
    Without using _ :* for the varargs, the format string is not properly
    expanded and results in an IllegalFormatConversionException. This
    currently only occurs when the BacktrackingException is created because
    it's the only exception that uses the var args constructor with the
    ThinException.
    
    DAFFODIL-2394
---
 .../org/apache/daffodil/io/TestExceptions.scala    | 32 ++++++++++++++++++++++
 .../org/apache/daffodil/exceptions/Assert.scala    |  2 +-
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/daffodil-io/src/test/scala/org/apache/daffodil/io/TestExceptions.scala b/daffodil-io/src/test/scala/org/apache/daffodil/io/TestExceptions.scala
new file mode 100644
index 0000000..f1fc00e
--- /dev/null
+++ b/daffodil-io/src/test/scala/org/apache/daffodil/io/TestExceptions.scala
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.daffodil.io
+
+import org.junit.Assert.assertTrue
+import org.junit.Test
+
+class TestExceptions {
+
+  @Test def testBacktrackingException(): Unit = {
+    val be = new BacktrackingException(123, 456)
+    val msg = be.getMessage()
+    assertTrue(msg.contains("123"))
+    assertTrue(msg.contains("456"))
+  }
+
+}
diff --git a/daffodil-lib/src/main/scala/org/apache/daffodil/exceptions/Assert.scala b/daffodil-lib/src/main/scala/org/apache/daffodil/exceptions/Assert.scala
index e483d12..ef27335 100644
--- a/daffodil-lib/src/main/scala/org/apache/daffodil/exceptions/Assert.scala
+++ b/daffodil-lib/src/main/scala/org/apache/daffodil/exceptions/Assert.scala
@@ -33,7 +33,7 @@ abstract class ThinException protected (dummy: Int, cause: Throwable, fmt: Strin
   extends Exception(null, cause, false, false) {
 
   private lazy val msg_ =
-    if (fmt ne null) fmt.format(args)
+    if (fmt ne null) fmt.format(args: _*)
     else if (cause ne null) cause.getMessage()
     else Misc.getNameFromClass(this)