Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some more collection errors #1431

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,10 @@ def buildScalacOptions(scalaVersion: String) = {
Seq(
"-Xlint:inaccessible",
"-Xlint:infer-any",
"-Xlint:nullary-unit"
"-Xlint:nullary-unit",
// the import is needed for Scala 2.12 but issues an unused import warning under 2.13, so we add this to
// suppresss the warning
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whenever we do this sort of scala 2.12 compatibility thing, I think we should anticipate that we will drop scala 2.12 fairly quickly once we've moved to scala 2.13 or scala 3. So I would add a // TODO: scala 2.12 phase out or other easily identified TODO item.

"-Wconf:origin=scala.collection.compat.*:s"
)
case _ => Seq.empty
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.lib.util

import scala.collection.mutable

/**
* Compatibility class for 2.12 and 2.13 since MultiMap and inheritance
* from class mutable.HashMap have been deprecated in 2.13.
*/
class MultiMapWrapper[K, V] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this is a wrapper, but I think this should just be called MultiMap.

private val underlying = mutable.Map.empty[K, mutable.Set[V]]

def addBinding(key: K, value: V): Unit =
underlying.getOrElseUpdate(key, mutable.Set.empty) += value

def addBinding(key: K, values: mutable.Set[V]): Unit = {
values.foreach(addBinding(key, _))
}

def removeBinding(key: K, value: V): Unit =
underlying.get(key).foreach { values =>
values -= value
if (values.isEmpty) underlying -= key

Check warning on line 39 in daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/MultiMapWrapper.scala

View check run for this annotation

Codecov / codecov/patch

daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/MultiMapWrapper.scala#L37-L39

Added lines #L37 - L39 were not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to suggest we just ignore these codecov as part of this scala 2.13/scala 3 conversion process.

We can always run a complete code-cov analysis later.

}

def get(key: K): Option[mutable.Set[V]] = underlying.get(key)

Check warning on line 42 in daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/MultiMapWrapper.scala

View check run for this annotation

Codecov / codecov/patch

daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/MultiMapWrapper.scala#L42

Added line #L42 was not covered by tests

def keys: Iterable[K] = underlying.keys

Check warning on line 44 in daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/MultiMapWrapper.scala

View check run for this annotation

Codecov / codecov/patch

daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/MultiMapWrapper.scala#L44

Added line #L44 was not covered by tests

def iterator: Iterator[(K, mutable.Set[V])] = underlying.iterator

Check warning on line 46 in daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/MultiMapWrapper.scala

View check run for this annotation

Codecov / codecov/patch

daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/MultiMapWrapper.scala#L46

Added line #L46 was not covered by tests

def filter(func: (K, mutable.Set[V]) => Boolean): MultiMapWrapper[K, V] = {
val filtered = new MultiMapWrapper[K, V]
for ((key, values) <- underlying) {
if (func(key, values)) {
filtered.addBinding(key, values)
}
}
filtered
}

def map[T](func: (K, mutable.Set[V]) => T): collection.Seq[T] = {
val ret = mutable.ListBuffer.empty[T]
for ((key, values) <- underlying) {
ret.append(func(key, values))
}
ret
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.daffodil.runtime1.debugger

import java.io.File
import scala.collection.compat.immutable.ArraySeq

import org.apache.daffodil.lib.api.DaffodilTunables
import org.apache.daffodil.lib.api.WarnID
Expand Down Expand Up @@ -279,7 +280,7 @@ class InteractiveDebugger(
input
}
}
cmd.split(" ").filter(_ != "")
ArraySeq.unsafeWrapArray(cmd.split(" ").filter(_ != ""))
}

private val debuggerQName = GlobalQName(Some("daf"), "debugger", XMLUtils.dafintURI)
Expand Down Expand Up @@ -1862,7 +1863,7 @@ class InteractiveDebugger(
}

abstract class InfoProcessorBase extends DebugCommand with DebugCommandValidateZeroArgs {
val desc = "display the current Daffodil " + name
val desc = "display the current Daffodil " + this.name
mbeckerle marked this conversation as resolved.
Show resolved Hide resolved
val longDesc = desc
def act(
args: Seq[String],
Expand All @@ -1871,15 +1872,15 @@ class InteractiveDebugger(
): DebugState.Type = {
state match {
case pstate: PState => {
if (name == "parser") {
debugPrintln("%s: %s".format(name, processor.toBriefXML(2)))
if (this.name == "parser") {
debugPrintln("%s: %s".format(this.name, processor.toBriefXML(2)))
} else {
debugPrintln("unparser: not available")
}
}
case ustate: UState => {
if (name == "unparser") {
debugPrintln("%s: %s".format(name, processor.toBriefXML(2)))
if (this.name == "unparser") {
debugPrintln("%s: %s".format(this.name, processor.toBriefXML(2)))
} else {
debugPrintln("parser: not available")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@

// This is toXML for the case class object, not the infoset node it is
// dealing with.
override def toXML = toXML(recipe.toXML)
override def toXML = toXMLVarargs(recipe.toXML)

Check warning on line 238 in daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/DFDLXFunctions.scala

View check run for this annotation

Codecov / codecov/patch

daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/DFDLXFunctions.scala#L238

Added line #L238 was not covered by tests

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.daffodil.runtime1.dpath

import java.lang.{ Number => JNumber }
import scala.collection.compat.immutable.ArraySeq
import scala.xml.NodeSeq.seqToNodeSeq

import org.apache.daffodil.lib.api.DaffodilTunables
Expand All @@ -43,7 +44,7 @@

class CompiledDPath(val ops: RecipeOp*) extends Serializable {

def this(ops: List[RecipeOp]) = this(ops.toArray: _*)
def this(ops: List[RecipeOp]) = this(ArraySeq.unsafeWrapArray(ops.toArray): _*)

override def toString =
toXML.toString
Expand Down Expand Up @@ -157,9 +158,9 @@

protected def subRecipes: Seq[CompiledDPath] = Nil

protected def toXML(s: String): scala.xml.Node = toXML(new scala.xml.Text(s))
protected def toXML(s: String): scala.xml.Node = toXMLVarargs(new scala.xml.Text(s))

protected def toXML(children: scala.xml.Node*): scala.xml.Node = toXML(children.toSeq)
protected def toXMLVarargs(children: scala.xml.Node*): scala.xml.Node = toXML(children.toSeq)

protected def toXML(children: scala.xml.NodeSeq): scala.xml.Node = {
val name = Misc.getNameFromClass(this)
Expand Down Expand Up @@ -246,7 +247,8 @@
def right: CompiledDPath
override def subRecipes: Seq[CompiledDPath] = Seq(left, right)

override def toXML: scala.xml.Node = toXML(new scala.xml.Text(op), left.toXML, right.toXML)
override def toXML: scala.xml.Node =
toXMLVarargs(new scala.xml.Text(op), left.toXML, right.toXML)

Check warning on line 251 in daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/DPathRuntime.scala

View check run for this annotation

Codecov / codecov/patch

daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/DPathRuntime.scala#L251

Added line #L251 was not covered by tests
}

case class CompareOperator(cop: CompareOpBase, left: CompiledDPath, right: CompiledDPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
dstate.setCurrentValue(computeValue(arg, dstate))
}

override def toXML = toXML(recipe.toXML)
override def toXML = toXMLVarargs(recipe.toXML)

Check warning on line 127 in daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/FNBases.scala

View check run for this annotation

Codecov / codecov/patch

daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/FNBases.scala#L127

Added line #L127 was not covered by tests

def computeValue(str: DataValuePrimitive, dstate: DState): DataValuePrimitive
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@
dstate.setCurrentValue(res)
}

override def toXML = toXML(recipe.toXML)
override def toXML = toXMLVarargs(recipe.toXML)

Check warning on line 717 in daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/FNFunctions.scala

View check run for this annotation

Codecov / codecov/patch

daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/FNFunctions.scala#L717

Added line #L717 was not covered by tests

}

Expand All @@ -726,7 +726,7 @@
dstate.setCurrentValue(!res)
}

override def toXML = toXML(recipe.toXML)
override def toXML = toXMLVarargs(recipe.toXML)

Check warning on line 729 in daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/FNFunctions.scala

View check run for this annotation

Codecov / codecov/patch

daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/dpath/FNFunctions.scala#L729

Added line #L729 was not covered by tests

}

Expand Down Expand Up @@ -919,13 +919,13 @@
val f = asFloat(value.getAnyRef).floatValue()
if (f.isPosInfinity || f.isNegInfinity) f
else if (f.isNaN()) throw new NumberFormatException("fn:round received NaN")
else f.round: Float
else f.round.toFloat
}
case NodeInfo.Double => {
val d = asDouble(value.getAnyRef).doubleValue()
if (d.isPosInfinity || d.isNegInfinity) d
else if (d.isNaN()) throw new NumberFormatException("fn:round received NaN")
else d.round: Double
else d.round.toDouble
}
case _: NodeInfo.Numeric.Kind => value
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.apache.daffodil.runtime1.externalvars

import java.io.File
import java.net.URI
import scala.collection.compat._
import scala.collection.immutable.Queue
import scala.io.Codec.string2codec
import scala.xml.Node
Expand Down Expand Up @@ -65,7 +66,7 @@ object ExternalVariablesLoader {
Binding(name, value)
}
}
Queue.empty.enqueue(varsKVP)
Queue.empty.enqueueAll(varsKVP)
}

def uriToBindings(uri: URI): Queue[Binding] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.daffodil.runtime1.infoset

import scala.collection.compat.immutable.LazyList

import org.apache.daffodil.lib.exceptions.Assert
import org.apache.daffodil.lib.util.Logger
import org.apache.daffodil.lib.util.MStackOf
Expand Down Expand Up @@ -126,7 +128,7 @@
): Maybe[ElementRuntimeData] = {
val allTRDs = {
iter.reset()
iter.toStream.takeWhile { stackTRD =>
iter.to(LazyList).takeWhile { stackTRD =>

Check warning on line 131 in daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/infoset/PartialNextElementResolver.scala

View check run for this annotation

Codecov / codecov/patch

daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/infoset/PartialNextElementResolver.scala#L131

Added line #L131 was not covered by tests
optTRD.map { _ ne stackTRD }.getOrElse(true)
}
}
Expand Down Expand Up @@ -334,7 +336,7 @@
// with a matching local name, and error if we found more than one.
// If we only found one we found it. If we didn't find any, there was
// no match.
val localMatches = nextERDMap.filterKeys(_.local == local)
val localMatches = nextERDMap.filter { case (k, v) => k.local == local }

Check warning on line 339 in daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/infoset/PartialNextElementResolver.scala

View check run for this annotation

Codecov / codecov/patch

daffodil-runtime1/src/main/scala/org/apache/daffodil/runtime1/infoset/PartialNextElementResolver.scala#L339

Added line #L339 was not covered by tests
if (localMatches.size > 1) {
val sqn = StepQName(None, local, NS(namespace))
val keys = localMatches.keys.toSeq
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package org.apache.daffodil.runtime1.processors

import java.math.RoundingMode
import scala.collection.mutable

import org.apache.daffodil.lib.cookers.TextBooleanFalseRepCooker
import org.apache.daffodil.lib.cookers.TextBooleanTrueRepCooker
Expand All @@ -33,6 +32,7 @@ import org.apache.daffodil.lib.util.Maybe._
import org.apache.daffodil.lib.util.MaybeChar
import org.apache.daffodil.lib.util.MaybeDouble
import org.apache.daffodil.lib.util.MaybeInt
import org.apache.daffodil.lib.util.MultiMapWrapper
import org.apache.daffodil.runtime1.dpath.NodeInfo.PrimType
import org.apache.daffodil.runtime1.dsom._

Expand Down Expand Up @@ -96,8 +96,7 @@ class TextNumberFormatEv(
exponentRep: Maybe[String]
): Unit = {

val mm = new mutable.HashMap[String, mutable.Set[String]]
with mutable.MultiMap[String, String]
val mm = new MultiMapWrapper[String, String]
if (decimalSep.isDefined)
mm.addBinding(decimalSep.get.toString, "textStandardDecimalSeparator")
if (groupingSep.isDefined)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ class SuspensionDeadlockException(suspExprs: Seq[Suspension])
.groupBy {
_.rd
}
.mapValues {
.values
.map {
_(0)
}
.values
.mkString(" - ", "\n - ", "")
)
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.daffodil.runtime1.processors.dfa

import scala.collection.compat.immutable.ArraySeq
import scala.collection.mutable.ArrayBuffer

import org.apache.daffodil.runtime1.dsom.DPathCompileInfo
Expand Down Expand Up @@ -95,7 +96,7 @@ object CreateDelimiterDFA {
val d = new Delimiter()
d.compileDelimiter(delimiterStr, ignoreCase)
val db = d.delimBuf
apply(delimType, ci, db, delimiterStr, ignoreCase)
apply(delimType, ci, ArraySeq.unsafeWrapArray(db), delimiterStr, ignoreCase)
}

/**
Expand All @@ -111,7 +112,7 @@ object CreateDelimiterDFA {
val d = new Delimiter()
d.compileDelimiter(delimiterStr, false)
val db = d.delimBuf
apply(delimType, ci, db, delimiterStr, outputNewLine)
apply(delimType, ci, ArraySeq.unsafeWrapArray(db), delimiterStr, outputNewLine)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.daffodil.runtime1.processors.dfa

import scala.collection.compat.immutable.ArraySeq
import scala.collection.mutable.ArrayBuffer

import org.apache.daffodil.io.DataInputStream
Expand Down Expand Up @@ -97,10 +98,10 @@ class TextDelimitedUnparser(override val context: TermRuntimeData) extends Delim
val fieldReg: Registers = state.dfaRegistersPool.getFromPool("escapeBlock1")

val fieldEscapesIter = {
val ab = ArrayBuffer((blockEnd +: delims): _*)
val ab = ArrayBuffer(ArraySeq.unsafeWrapArray(blockEnd +: delims): _*)
new AllDelimiterIterator(ab)
}
val delimIter = new AllDelimiterIterator(ArrayBuffer(delims: _*))
val delimIter = new AllDelimiterIterator(ArrayBuffer(ArraySeq.unsafeWrapArray(delims): _*))

fieldReg.reset(state, input, fieldEscapesIter)

Expand Down Expand Up @@ -274,7 +275,7 @@ class TextDelimitedUnparser(override val context: TermRuntimeData) extends Delim
val successes: ArrayBuffer[(DFADelimiter, Registers)] = ArrayBuffer.empty
val fieldReg: Registers = state.dfaRegistersPool.getFromPool("escapeCharacter1")

val delimIter = new AllDelimiterIterator(ArrayBuffer(delims: _*))
val delimIter = new AllDelimiterIterator(ArrayBuffer(ArraySeq.unsafeWrapArray(delims): _*))

fieldReg.reset(state, input, delimIter)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import java.lang.reflect.Method
import java.util.ServiceConfigurationError
import java.util.ServiceLoader
import scala.collection.mutable._
import scala.collection.compat.immutable.ArraySeq

import org.apache.daffodil.lib.util.Logger
import org.apache.daffodil.lib.util.Misc
Expand Down Expand Up @@ -56,7 +57,7 @@ object UserDefinedFunctionService {
}

def lookupMethod() = {
val m = decClass.getMethod(methodName, paramTypes: _*)
val m = decClass.getMethod(methodName, ArraySeq.unsafeWrapArray(paramTypes): _*)
m
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Paths
import javax.xml.XMLConstants
import scala.collection.compat.immutable.ArraySeq

import org.apache.daffodil.lib.Implicits.using
import org.apache.daffodil.lib.exceptions.UsageException
Expand Down Expand Up @@ -1213,7 +1214,7 @@ class TestScalaAPI {

val bos = new java.io.ByteArrayOutputStream()
val wbc = java.nio.channels.Channels.newChannel(bos)
val inputter = new TestInfosetInputter(expectedEvents: _*)
val inputter = new TestInfosetInputter(ArraySeq.unsafeWrapArray(expectedEvents): _*)

val ur = dp.unparse(inputter, wbc)
assertFalse(ur.isError())
Expand Down
Loading
Loading