Skip to content

Commit

Permalink
Fix deprecations except Scala 2.12 Stack, and Scala 3 type inference …
Browse files Browse the repository at this point in the history
…warnings (#410)
  • Loading branch information
ekrich authored Nov 12, 2024
1 parent 1632ce0 commit 50b37ba
Show file tree
Hide file tree
Showing 24 changed files with 113 additions and 66 deletions.
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ val scalacOpts = dotcOpts ++ List(
// 57 inferred return type Scala 2.13 cat=scala3-migration
"-Wconf:msg=inferred:ws",
// 2 deprecations Scala 2.12 Stack - fixed for 2.13
"-Wconf:msg=poorly-performing:ws"
"-Wconf:msg=poorly-performing:ws",
// uncomment to see messages
// "-Wconf:any:warning-verbose"
"-Wconf:any:warning-verbose"
)

Compile / console / scalacOptions --= Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ object ConfigBeanImpl {
if (!problems.isEmpty)
throw new ConfigException.ValidationFailed(problems)
// Fill in the bean instance
val bean = clazz.getConstructor().newInstance()
val bean = clazz.getDeclaredConstructor().newInstance()
for (beanProp <- beanProps.asScala) {
breakable {
val setter = beanProp.getWriteMethod
Expand All @@ -137,11 +137,16 @@ object ConfigBeanImpl {
}
bean
} catch {
case e: InstantiationException =>
case e: NoSuchMethodException =>
throw new ConfigException.BadBean(
clazz.getName + " needs a public no-args constructor to be used as a bean",
e
)
case e: InstantiationException =>
throw new ConfigException.BadBean(
clazz.getName + " needs to be instantiatable to be used as a bean",
e
)
case e: IllegalAccessException =>
throw new ConfigException.BadBean(
clazz.getName + " getters and setters are not accessible, they must be for use as a bean",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1049,14 +1049,27 @@ object ConfigFactory extends PlatformConfigFactory {
if (className != null) {
try {
classOf[ConfigLoadingStrategy].cast(
Class.forName(className).getConstructor().newInstance()
Class
.forName(className)
.asSubclass(classOf[ConfigLoadingStrategy])
.getDeclaredConstructor()
.newInstance()
)
} catch {
// possibly InvocationTargetException
case e: Throwable =>
throw new ConfigException.BugOrBroken(
"Failed to load strategy: " + className,
e
)
val cause = e.getCause()
if (cause == null) {
throw new ConfigException.BugOrBroken(
"Failed to load strategy: " + className,
e
)
} else {
throw new ConfigException.BugOrBroken(
"Failed to load strategy: " + className,
cause
)
}
}
} else {
new DefaultConfigLoadingStrategy()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ abstract class AbstractConfigObject(_origin: ConfigOrigin)
override def constructDelayedMerge(
origin: ConfigOrigin,
stack: ju.List[AbstractConfigValue]
) =
): AbstractConfigObject =
new ConfigDelayedMergeObject(origin, stack)

override def mergedWithObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ final class ConfigBoolean(origin: ConfigOrigin, val value: jl.Boolean)

override def transformToString: String = value.toString()

override def newCopy(origin: ConfigOrigin) = new ConfigBoolean(origin, value)
override def newCopy(origin: ConfigOrigin): AbstractConfigValue =
new ConfigBoolean(origin, value)

// serialization all goes through SerializedConfigValue (signature is critical)
@throws[ObjectStreamException]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ final class ConfigConcatenation(
"need to Config#resolve(), see the API docs for Config#resolve(); substitution not resolved: " + this
)

override def valueType = throw notResolved
override def valueType: ConfigValueType = throw notResolved

override def unwrapped = throw notResolved
override def unwrapped: AnyRef = throw notResolved

override def newCopy(newOrigin: ConfigOrigin) =
override def newCopy(newOrigin: ConfigOrigin): AbstractConfigValue =
new ConfigConcatenation(newOrigin, pieces)

override def ignoresFallbacks: Boolean = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.ekrich.config.ConfigException
import org.ekrich.config.ConfigOrigin
import org.ekrich.config.ConfigRenderOptions
import org.ekrich.config.impl.AbstractConfigValue._
import org.ekrich.config.ConfigValueType

/**
* The issue here is that we want to first merge our stack of config files, and
Expand Down Expand Up @@ -227,12 +228,12 @@ final class ConfigDelayedMerge(
)
}

override def valueType =
override def valueType: ConfigValueType =
throw new ConfigException.NotResolved(
"called valueType() on value with unresolved substitutions, need to Config#resolve() first, see API docs"
)

override def unwrapped =
override def unwrapped: AnyRef =
throw new ConfigException.NotResolved(
"called unwrapped() on value with unresolved substitutions, need to Config#resolve() first, see API docs"
)
Expand Down Expand Up @@ -274,7 +275,7 @@ final class ConfigDelayedMerge(
override def ignoresFallbacks: Boolean =
ConfigDelayedMerge.stackIgnoresFallbacks(stack)

override def newCopy(newOrigin: ConfigOrigin) =
override def newCopy(newOrigin: ConfigOrigin): AbstractConfigValue =
new ConfigDelayedMerge(newOrigin, stack)

override final def mergedWithTheUnmergeable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,22 @@ final class ConfigDelayedMergeObject(
mergeable: ConfigMergeable
): ConfigDelayedMergeObject =
super.withFallback(mergeable).asInstanceOf[ConfigDelayedMergeObject]
override def withOnlyKey(key: String) =
override def withOnlyKey(key: String): AbstractConfigObject =
throw ConfigDelayedMergeObject.notResolved
override def withoutKey(key: String) =
override def withoutKey(key: String): AbstractConfigObject =
throw ConfigDelayedMergeObject.notResolved
override def withOnlyPathOrNull(path: Path) =
override def withOnlyPathOrNull(path: Path): AbstractConfigObject =
throw ConfigDelayedMergeObject.notResolved
override def withOnlyPath(path: Path) =
override def withOnlyPath(path: Path): AbstractConfigObject =
throw ConfigDelayedMergeObject.notResolved
override def withoutPath(path: Path) =
override def withoutPath(path: Path): AbstractConfigObject =
throw ConfigDelayedMergeObject.notResolved
override def withValue(key: String, value: ConfigValue) =
override def withValue(
key: String,
value: ConfigValue
): AbstractConfigObject =
throw ConfigDelayedMergeObject.notResolved
override def withValue(path: Path, value: ConfigValue) =
override def withValue(path: Path, value: ConfigValue): AbstractConfigObject =
throw ConfigDelayedMergeObject.notResolved
override def unmergedValues: ju.Collection[AbstractConfigValue] = stack
override def canEqual(other: Any): Boolean =
Expand Down Expand Up @@ -158,18 +161,24 @@ final class ConfigDelayedMergeObject(
): Unit = {
render(sb, indent, atRoot, null, options)
}
override def unwrapped = throw ConfigDelayedMergeObject.notResolved
override def get(key: Any) = throw ConfigDelayedMergeObject.notResolved
override def remove(key: Any) = throw ConfigDelayedMergeObject.notResolved
override def containsKey(key: Any) =
override def unwrapped: ju.Map[String, AnyRef] =
throw ConfigDelayedMergeObject.notResolved
override def containsValue(value: Any) =
override def get(key: Any): AbstractConfigValue =
throw ConfigDelayedMergeObject.notResolved
override def remove(key: Any): ConfigValue =
throw ConfigDelayedMergeObject.notResolved
override def containsKey(key: Any): Boolean =
throw ConfigDelayedMergeObject.notResolved
override def containsValue(value: Any): Boolean =
throw ConfigDelayedMergeObject.notResolved
override def entrySet: ju.Set[ju.Map.Entry[String, ConfigValue]] =
throw ConfigDelayedMergeObject.notResolved
override def isEmpty: Boolean = throw ConfigDelayedMergeObject.notResolved
override def keySet: ju.Set[String] =
throw ConfigDelayedMergeObject.notResolved
override def size: Int = throw ConfigDelayedMergeObject.notResolved
override def values: ju.Collection[ConfigValue] =
throw ConfigDelayedMergeObject.notResolved
override def entrySet = throw ConfigDelayedMergeObject.notResolved
override def isEmpty = throw ConfigDelayedMergeObject.notResolved
override def keySet = throw ConfigDelayedMergeObject.notResolved
override def size = throw ConfigDelayedMergeObject.notResolved
override def values = throw ConfigDelayedMergeObject.notResolved

// exercised in ValidationTest.validationFailedSerializable
// and ConfigTest.test01Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class ConfigDouble(

override def doubleValue: Double = value

override def newCopy(origin: ConfigOrigin) =
override def newCopy(origin: ConfigOrigin): AbstractConfigValue =
new ConfigDouble(origin, value, originalText)

// serialization all goes through SerializedConfigValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class ConfigInt(

override def doubleValue: Double = value.toDouble

override def newCopy(origin: ConfigOrigin) =
override def newCopy(origin: ConfigOrigin): AbstractConfigValue =
new ConfigInt(origin, value, originalText)

// serialization all goes through SerializedConfigValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class ConfigLong(

override def doubleValue: Double = value.toDouble

override def newCopy(origin: ConfigOrigin) =
override def newCopy(origin: ConfigOrigin): AbstractConfigValue =
new ConfigLong(origin, value, originalText)

// serialization all goes through SerializedConfigValue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import java.{util => ju}
final class ConfigNodeArray private[impl] (
children: ju.Collection[AbstractConfigNode]
) extends ConfigNodeComplexValue(children) {
override def newNode(nodes: ju.Collection[AbstractConfigNode]) =
override def newNode(
nodes: ju.Collection[AbstractConfigNode]
): ConfigNodeComplexValue =
new ConfigNodeArray(nodes)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import java.{util => ju}
final class ConfigNodeConcatenation private[impl] (
children: ju.Collection[AbstractConfigNode]
) extends ConfigNodeComplexValue(children) {
override def newNode(nodes: ju.Collection[AbstractConfigNode]) =
override def newNode(
nodes: ju.Collection[AbstractConfigNode]
): ConfigNodeComplexValue =
new ConfigNodeConcatenation(nodes)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import scala.util.control.Breaks._
final class ConfigNodeObject private[impl] (
_children: ju.Collection[AbstractConfigNode]
) extends ConfigNodeComplexValue(_children) {
override def newNode(nodes: ju.Collection[AbstractConfigNode]) =
override def newNode(
nodes: ju.Collection[AbstractConfigNode]
): ConfigNodeComplexValue =
new ConfigNodeObject(nodes)

def hasValue(desiredPath: Path): Boolean =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ final class ConfigNodeRoot private[impl] (
_children: ju.Collection[AbstractConfigNode],
val origin: ConfigOrigin
) extends ConfigNodeComplexValue(_children) {
override def newNode(nodes: ju.Collection[AbstractConfigNode]) =
override def newNode(
nodes: ju.Collection[AbstractConfigNode]
): ConfigNodeComplexValue =
throw new ConfigException.BugOrBroken("Tried to indent the root object")

private[impl] def value: ConfigNodeComplexValue =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ final class ConfigNull(origin: ConfigOrigin)
sb.append("null")
}

override def newCopy(origin: ConfigOrigin) = new ConfigNull(origin)
override def newCopy(origin: ConfigOrigin): AbstractConfigValue =
new ConfigNull(origin)

// serialization all goes through SerializedConfigValue
@throws[ObjectStreamException]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.{util => ju}
import org.ekrich.config.ConfigException
import org.ekrich.config.ConfigOrigin
import org.ekrich.config.ConfigRenderOptions
import org.ekrich.config.ConfigValueType

/**
* ConfigReference replaces ConfigReference (the older class kept for back
Expand All @@ -24,9 +25,9 @@ final class ConfigReference(
new ConfigException.NotResolved(
"need to Config#resolve(), see the API docs for Config#resolve(); substitution not resolved: " + this
)
override def valueType = throw notResolved
override def unwrapped = throw notResolved
override def newCopy(newOrigin: ConfigOrigin) =
override def valueType: ConfigValueType = throw notResolved
override def unwrapped: AnyRef = throw notResolved
override def newCopy(newOrigin: ConfigOrigin): AbstractConfigValue =
new ConfigReference(newOrigin, expression, prefixLength)
override def ignoresFallbacks = false
override def unmergedValues: ju.Collection[ConfigReference] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object ConfigString {
origin: ConfigOrigin,
value: String
) extends ConfigString(origin, value) {
override def newCopy(origin: ConfigOrigin) =
override def newCopy(origin: ConfigOrigin): AbstractConfigValue =
new ConfigString.Quoted(origin, value)

// serialization all goes through SerializedConfigValue
Expand All @@ -36,7 +36,7 @@ object ConfigString {
origin: ConfigOrigin,
value: String
) extends ConfigString(origin, value) {
override def newCopy(origin: ConfigOrigin) =
override def newCopy(origin: ConfigOrigin): AbstractConfigValue =
new ConfigString.Unquoted(origin, value)

@throws[ObjectStreamException]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ object Parseable {
) extends Parseable(options) {
postConstruct(options)
@throws[IOException]
override protected def reader() = throw new FileNotFoundException(message)
override protected def reader(): Reader = throw new FileNotFoundException(
message
)
override protected def createOrigin(): ConfigOrigin =
SimpleConfigOrigin.newSimple(what)
}
Expand Down Expand Up @@ -184,7 +186,7 @@ object Parseable {
postConstruct(options)
}
@throws[IOException]
override protected def reader() =
override protected def reader(): Reader =
throw new ConfigException.BugOrBroken(
"reader() without options should not be called on ParseableURL"
)
Expand Down Expand Up @@ -341,7 +343,7 @@ object Parseable {
with Relativizer {
postConstruct(options)
@throws[IOException]
override protected def reader() =
override protected def reader(): Reader =
throw new ConfigException.BugOrBroken(
"reader() should not be called on resources"
)
Expand Down Expand Up @@ -445,7 +447,7 @@ object Parseable {
) extends Parseable(options) {
postConstruct(options)
@throws[IOException]
override protected def reader() =
override protected def reader(): Reader =
throw new ConfigException.BugOrBroken(
"reader() should not be called on props"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.ekrich.config.ConfigList
import org.ekrich.config.ConfigObject
import org.ekrich.config.ConfigOrigin
import org.ekrich.config.ConfigValue
import org.ekrich.config.ConfigValueType

/**
* Deliberately shoving all the serialization code into this class instead of
Expand Down Expand Up @@ -398,9 +399,10 @@ class SerializedConfigValue() // this has to be public for the Java deserializer
in.readFully(bytes)
new DataInputStream(new ByteArrayInputStream(bytes))
}
override def valueType = throw SerializedConfigValue.shouldNotBeUsed
override def unwrapped = throw SerializedConfigValue.shouldNotBeUsed
override def newCopy(origin: ConfigOrigin) =
override def valueType: ConfigValueType =
throw SerializedConfigValue.shouldNotBeUsed
override def unwrapped: AnyRef = throw SerializedConfigValue.shouldNotBeUsed
override def newCopy(origin: ConfigOrigin): AbstractConfigValue =
throw SerializedConfigValue.shouldNotBeUsed
override final def toString: String =
getClass.getSimpleName + "(value=" + value + ",wasConfig=" + wasConfig + ")"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class SimpleConfigDocument private[impl] (
options = options.setOriginComments(false)
withValueText(path, newValue.render(options).trim)
}
override def withoutPath(path: String) =
override def withoutPath(path: String): ConfigDocument =
new SimpleConfigDocument(
configNodeTree.setValue(path, null, parseOptions.getSyntax),
parseOptions
Expand Down
Loading

0 comments on commit 50b37ba

Please sign in to comment.