Skip to content

Commit c9a5f78

Browse files
committed
Replace Deprecated classes like Stack/Stream
- remove TransientParam class, replace with just @transient - replace deprecated Stream with LazyList - rename iterator to eventIterator since Iterator trait now defines iterator field - .toIterator -> .iterator - update collection converters for 2.13, add compat class to enable for 2.12 - remove additional implicitCoversions/reflectiveCalls imports since it causes an unused import error in 2.13 - replace mutable.ArrayStack/Stack with custom Stack class that is backed by ListBuffer - replace deprecated Proxy class with overrides to toString, hashCode and equals - non-explicit implicit return types are deprecated in 2.13 - parseString is required for 2.13 extenders of Numeric, set to None - add comments about code not covered by tests DAFFODIL-2152
1 parent 08e28a9 commit c9a5f78

File tree

32 files changed

+237
-147
lines changed

32 files changed

+237
-147
lines changed

daffodil-cli/bin.NOTICE

+16
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,19 @@ The following NOTICE information applies to binary components distributed with t
167167
Portions of this code are derived from classes placed in the
168168
public domain by Arbortext on 10 Apr 2000. See:
169169
http://www.arbortext.com/customer_support/updates_and_technical_notes/catalogs/docs/README.htm
170+
171+
- org.scala-lang.scala-collection-compat_2.13-<VERSION>.jar
172+
scala-collection-compat
173+
Copyright (c) 2002-2025 EPFL
174+
Copyright (c) 2011-2025 Lightbend, Inc. dba Akka
175+
176+
Scala includes software developed at
177+
LAMP/EPFL (https://lamp.epfl.ch/) and
178+
Akka (https://akka.io/).
179+
180+
Licensed under the Apache License, Version 2.0 (the "License").
181+
Unless required by applicable law or agreed to in writing, software
182+
distributed under the License is distributed on an "AS IS" BASIS,
183+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
184+
See the License for the specific language governing permissions and
185+
limitations under the License.

daffodil-cli/src/main/scala/org/apache/daffodil/cli/debugger/CLIDebuggerRunner.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ package org.apache.daffodil.cli.debugger
2020
import java.io.File
2121
import java.io.InputStream
2222
import java.io.PrintStream
23-
import scala.collection.JavaConverters._
2423
import scala.io.Source
24+
import scala.jdk.CollectionConverters._
2525

2626
import org.apache.daffodil.runtime1.debugger._
2727

daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/Util.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import java.nio.file.Path
3131
import java.nio.file.Paths
3232
import java.security.MessageDigest
3333
import java.util.concurrent.TimeUnit
34-
import scala.collection.JavaConverters._
3534
import scala.collection.mutable
35+
import scala.jdk.CollectionConverters._
3636

3737
import org.apache.daffodil.cli.Main
3838
import org.apache.daffodil.cli.Main.ExitCode

daffodil-codegen-c/src/main/scala/org/apache/daffodil/codegen/c/DaffodilCCodeGenerator.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import java.io.File
2121
import java.net.JarURLConnection
2222
import java.nio.file.Files
2323
import java.nio.file.Paths
24-
import scala.collection.JavaConverters._
24+
import scala.jdk.CollectionConverters._
2525
import scala.util.Properties.isWin
2626

2727
import org.apache.daffodil.codegen.c.generators.AlignmentFillCodeGenerator

daffodil-codegen-c/src/main/scala/org/apache/daffodil/codegen/c/generators/CodeGeneratorState.scala

+81-68
Large diffs are not rendered by default.

daffodil-core/src/test/scala/org/apache/daffodil/core/layers/TestLayers.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import java.io.ByteArrayInputStream
2121
import java.io.ByteArrayOutputStream
2222
import java.io.InputStreamReader
2323
import java.nio.charset.StandardCharsets
24-
import scala.collection.JavaConverters._
24+
import scala.jdk.CollectionConverters._
2525

2626
import org.apache.daffodil.core.util.TestUtils
2727
import org.apache.daffodil.lib.util._

daffodil-io/src/test/scala/org/apache/daffodil/layers/TestJavaIOStreams.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import java.io.ByteArrayInputStream
2222
import java.io.ByteArrayOutputStream
2323
import java.nio.charset.StandardCharsets
2424
import java.util.Scanner
25+
import scala.jdk.CollectionConverters._
2526

2627
import org.apache.daffodil.lib.exceptions.Assert
2728

28-
import collection.JavaConverters._
2929
import org.apache.commons.io.IOUtils
3030
import org.junit.Assert._
3131
import org.junit.Test

daffodil-japi/src/main/scala/org/apache/daffodil/japi/Daffodil.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import java.io.File
2121
import java.net.URI
2222
import java.nio.channels.ReadableByteChannel
2323
import java.nio.channels.WritableByteChannel
24-
import scala.collection.JavaConverters._
24+
import scala.jdk.CollectionConverters._
2525

2626
import org.apache.daffodil.core.compiler.{ Compiler => SCompiler }
2727
import org.apache.daffodil.core.compiler.{ InvalidParserException => SInvalidParserException }

daffodil-japi/src/test/java/org/apache/daffodil/example/TestJavaAPI.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import java.util.ArrayList;
4040
import java.util.Iterator;
4141
import java.util.List;
42-
import scala.collection.JavaConverters;
42+
import scala.jdk.javaapi.CollectionConverters;
4343

4444
import org.apache.commons.io.FileUtils;
4545
import org.apache.commons.io.IOUtils;
@@ -1357,7 +1357,7 @@ public void testJavaAPIBlob1() throws IOException, ClassNotFoundException, Inval
13571357
output.setBlobAttributes(blobDir, "pre-", ".suf");
13581358

13591359
ParseResult res = dp.parse(input, output);
1360-
List<Path> blobPaths = JavaConverters.seqAsJavaList(output.getBlobPaths());
1360+
List<Path> blobPaths = CollectionConverters.asJava(output.getBlobPaths());
13611361

13621362
try {
13631363
assertFalse(res.isError());

daffodil-lib/src/main/scala/org/apache/daffodil/lib/Implicits.scala

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package org.apache.daffodil.lib
2020
import java.io.{ BufferedInputStream, ByteArrayInputStream }
2121
import scala.language.implicitConversions
2222
import scala.language.reflectiveCalls
23-
import scala.language.{ implicitConversions, reflectiveCalls } // silences scala 2.10 warnings
2423

2524
import org.apache.daffodil.lib.exceptions.Assert
2625
import org.apache.daffodil.lib.xml.NS

daffodil-lib/src/main/scala/org/apache/daffodil/lib/api/Validator.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ object ValidationResult {
6969
val empty: ValidationResult = ValidationResult(Seq.empty, Seq.empty)
7070

7171
def apply(w: Seq[ValidationWarning], e: Seq[ValidationFailure]): ValidationResult = {
72-
import scala.collection.JavaConverters.asJavaCollectionConverter
72+
import scala.jdk.CollectionConverters._
7373
new ValidationResult {
7474
val warnings: java.util.Collection[ValidationWarning] = w.asJavaCollection
7575
val errors: java.util.Collection[ValidationFailure] = e.asJavaCollection

daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/Coroutines.scala

+9-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package org.apache.daffodil.lib.util
1919

2020
import java.util.concurrent.ArrayBlockingQueue
2121
import java.util.concurrent.Executors
22+
import scala.collection.compat.immutable.LazyList
2223
import scala.concurrent.ExecutionContext
2324
import scala.concurrent.Future
2425
import scala.util.Failure
@@ -212,13 +213,14 @@ final class InvertControl[S](body: => Unit) extends MainCoroutine[Try[S]] with I
212213

213214
private val dummy: Try[S] = Success(null.asInstanceOf[S])
214215

215-
private def gen: Stream[S] = {
216+
private def gen: LazyList[S] = {
216217
val x = resume(
217218
producer,
218219
dummy
219220
) // producer isn't sent anything. It's just resumed to get another value.
220221
x match {
221-
case EndOfData => Stream.Empty
222+
// TODO: no test coverage
223+
case EndOfData => LazyList.empty
222224
case Success(v) => v #:: gen
223225
case Failure(e) => {
224226
failed = true
@@ -227,14 +229,16 @@ final class InvertControl[S](body: => Unit) extends MainCoroutine[Try[S]] with I
227229
}
228230
}
229231

230-
private lazy val iterator = gen.toIterator
232+
private lazy val eventIterator = gen.iterator
231233

232234
override def hasNext: Boolean = {
233-
!failed && iterator.hasNext
235+
// TODO: no test coverage
236+
!failed && eventIterator.hasNext
234237
}
235238
override def next(): S = {
236239
if (failed) throw new IllegalStateException()
237-
else iterator.next()
240+
// TODO: no test coverage
241+
else eventIterator.next()
238242
}
239243

240244
}

daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/DecimalUtils.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ object DecimalUtils {
553553
}
554554

555555
val allDigits = opl match {
556-
case OverpunchLocation.Start => digit + num.substring(1)
556+
case OverpunchLocation.Start => digit.toString + num.substring(1)
557557
case OverpunchLocation.End => num.substring(0, opindex) + digit
558558
case _ => Assert.impossible()
559559
}
@@ -603,7 +603,7 @@ object DecimalUtils {
603603
}
604604

605605
val convertedNum = opl match {
606-
case OverpunchLocation.Start => digit + inStr.substring(1)
606+
case OverpunchLocation.Start => digit +: inStr.substring(1)
607607
case OverpunchLocation.End => inStr.substring(0, opindex) + digit
608608
case _ => Assert.impossible()
609609
}

daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/Misc.scala

+5-4
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ import java.nio.charset.StandardCharsets
3232
import java.nio.charset.{ Charset => JavaCharset }
3333
import java.nio.file.Files
3434
import java.nio.file.Paths
35-
import scala.collection.JavaConverters._
3635
import scala.io.Source
36+
import scala.jdk.CollectionConverters._
3737

3838
import org.apache.daffodil.lib.equality._
3939
import org.apache.daffodil.lib.exceptions.Assert
@@ -272,8 +272,9 @@ object Misc {
272272
}
273273
}
274274

275-
def initialUpperCase(s: String): String = s.head.toUpper + s.substring(1)
276-
def initialLowerCase(s: String): String = s.head.toLower + s.substring(1)
275+
// TODO: no test coverage
276+
def initialUpperCase(s: String): String = s.head.toUpper +: s.substring(1)
277+
def initialLowerCase(s: String): String = s.head.toLower +: s.substring(1)
277278

278279
/**
279280
* Convert FooBar to fooBar, but leave FOOBAR as FOOBAR.
@@ -284,7 +285,7 @@ object Misc {
284285
// At this point we know the first letter is uppercase
285286
//
286287
if (isAllUpper(s, 1)) s
287-
else s(0).toLower + s.substring(1)
288+
else s(0).toLower +: s.substring(1)
288289
}
289290

290291
def isAllUpper(s: String, start: Int): Boolean = {

daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/NonAllocatingMap.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
package org.apache.daffodil.lib.util
1919

20-
import scala.collection.JavaConverters._
2120
import scala.collection.mutable
21+
import scala.jdk.CollectionConverters._
2222

2323
import org.apache.daffodil.lib.exceptions.Assert
2424

daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/OnStack.scala

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
package org.apache.daffodil.lib.util
1919

2020
import java.util.regex.Matcher
21-
import scala.collection.mutable
2221

2322
sealed abstract class LocalStackBase[T](constructorFunc: => T, optionalResetFunc: (T => Unit)) {
2423

25-
protected def stack: mutable.ArrayStack[T]
24+
protected def stack: Stack[T]
2625

2726
/**
2827
* This must be inlined to achieve what we're trying to achieve with OnStack/LocalStack.
@@ -61,9 +60,9 @@ class OnStack[T](constructorFunc: => T, optionalResetFunc: (T => Unit))
6160
*/
6261
def this(constructorFunc: => T) = this(constructorFunc, x => {})
6362

64-
private val tl = new ThreadLocal[mutable.ArrayStack[T]] {
65-
protected final override def initialValue(): mutable.ArrayStack[T] = {
66-
val stack = new mutable.ArrayStack[T]
63+
private val tl = new ThreadLocal[Stack[T]] {
64+
protected final override def initialValue(): Stack[T] = {
65+
val stack = new Stack[T]
6766
stack
6867
}
6968
}
@@ -94,7 +93,7 @@ class LocalStack[T](constructorFunc: => T, optionalResetFunc: (T => Unit))
9493
*/
9594
def this(constructorFunc: => T) = this(constructorFunc, x => {})
9695

97-
final protected val stack = new mutable.ArrayStack[T]
96+
final protected val stack = new Stack[T]
9897

9998
}
10099

daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/Serialize.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
package org.apache.daffodil.lib.util
1919

20-
import scala.collection.JavaConverters._
2120
import scala.collection.mutable.HashMap
21+
import scala.jdk.CollectionConverters._
2222

2323
import org.apache.daffodil.lib.exceptions.Assert
2424

daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/ScalaAnnotations.scala daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/Stack.scala

+39-8
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,42 @@
1717

1818
package org.apache.daffodil.lib.util
1919

20-
import scala.annotation.meta._
21-
22-
// The @transient annotation on a constructor parameter doesn't work properly
23-
// in scala >= 2.11, this is because it does not include the @param annotation.
24-
// This custom annotation extends transient, but adds the @param annotation so
25-
// construcutor parameters are properly made transient
26-
@param
27-
class TransientParam extends scala.transient
20+
import scala.collection.mutable.ListBuffer
21+
22+
/**
23+
* Compatibility class for 2.12 and 2.13 since ArrayStack and Stack
24+
* have been deprecated in 2.13. This allows us to maintain the same
25+
* functionality as stack while using ListBuffer instead
26+
*/
27+
class Stack[T] {
28+
def apply(index: Int): T = {
29+
_stackLike(index)
30+
}
31+
32+
private val _stackLike: ListBuffer[T] = new ListBuffer[T]
33+
34+
def pop(): T = {
35+
_stackLike.remove(_stackLike.length - 1)
36+
}
37+
38+
def push(item: T): Unit = {
39+
_stackLike += item
40+
}
41+
42+
def isEmpty: Boolean = {
43+
_stackLike.isEmpty
44+
}
45+
46+
def clear(): Unit = {
47+
// TODO: not covered by tests
48+
_stackLike.clear()
49+
}
50+
51+
def top(): T = {
52+
_stackLike.last
53+
}
54+
55+
def nonEmpty: Boolean = {
56+
_stackLike.nonEmpty
57+
}
58+
}

daffodil-lib/src/main/scala/org/apache/daffodil/lib/util/Timer.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package org.apache.daffodil.lib.util
1919

20-
import scala.collection.JavaConverters._
20+
import scala.jdk.CollectionConverters._
2121

2222
object Timer {
2323

@@ -185,8 +185,10 @@ object TimeTracker {
185185
* necessary since we often want to track the time each parser takes to
186186
* complete, but our parsers are nested making that difficult with standard
187187
* profilers. This makes that much easier.
188+
*
189+
* TODO: not covered by tests
188190
*/
189-
val childrenTimeStack = scala.collection.mutable.Stack[Long]()
191+
val childrenTimeStack = new org.apache.daffodil.lib.util.Stack[Long]()
190192

191193
/**
192194
* Used to measure a section of code that might get called multiple times.

daffodil-lib/src/main/scala/org/apache/daffodil/lib/validation/XercesValidator.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package org.apache.daffodil.lib.validation
2020
import java.net.URI
2121
import javax.xml.XMLConstants
2222
import javax.xml.transform.stream.StreamSource
23-
import scala.collection.JavaConverters._
23+
import scala.jdk.CollectionConverters._
2424
import scala.xml.SAXException
2525

2626
import org.apache.daffodil.lib.api.ValidationException

daffodil-lib/src/main/scala/org/apache/daffodil/lib/xml/DaffodilXMLLoader.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import javax.xml.transform.sax.SAXSource
3535
import javax.xml.transform.stream.StreamSource
3636
import javax.xml.validation.Schema
3737
import javax.xml.validation.SchemaFactory
38-
import scala.collection.JavaConverters.asScalaBufferConverter
38+
import scala.jdk.CollectionConverters._
3939
import scala.xml.SAXParseException
4040
import scala.xml.SAXParser
4141
import scala.xml.parsing.NoBindingFactoryAdapter

daffodil-lib/src/main/scala/org/apache/daffodil/lib/xml/XMLUtils.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ object XMLUtils {
282282
}
283283
// we fell out of the loop. So
284284
processText() // in case there is text left pending when we hit the end
285-
ab.result()
285+
ab.result().toSeq
286286
}
287287

288288
val XSD_NAMESPACE = NS(

0 commit comments

Comments
 (0)