From 7a7ef21ab73f64acbdb2c9a7dff6967d7e665073 Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Mon, 6 Mar 2023 14:49:44 +0100 Subject: [PATCH] clear warnings in http-core --- .../apache/pekko/http/impl/engine/http2/Http2.scala | 2 +- .../impl/engine/rendering/BodyPartRenderer.scala | 2 +- .../http/impl/engine/rendering/RenderSupport.scala | 2 +- .../http/impl/model/parser/CharacterClasses.scala | 1 - .../scala/org/apache/pekko/http/javadsl/Http.scala | 2 +- .../pekko/http/javadsl/settings/ParserSettings.scala | 2 -- .../scala/org/apache/pekko/http/scaladsl/Http.scala | 6 +----- .../pekko/http/scaladsl/model/HttpEntity.scala | 5 ++--- .../scaladsl/model/headers/HttpCredentials.scala | 4 ++-- .../impl/engine/client/HostConnectionPoolSpec.scala | 2 +- .../client/LowLevelOutgoingConnectionSpec.scala | 3 ++- .../impl/engine/server/HttpServerTestSetupBase.scala | 2 +- .../http/impl/engine/ws/ByteStringSinkProbe.scala | 2 +- .../http/impl/engine/ws/WSClientAutobahnTest.scala | 2 +- .../http/impl/engine/ws/WebSocketClientSpec.scala | 2 +- .../http/impl/model/parser/HttpHeaderSpec.scala | 12 +++++++----- .../settings/ConnectionPoolSettingsSpec.scala | 8 -------- project/Common.scala | 3 +++ 18 files changed, 26 insertions(+), 36 deletions(-) diff --git a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2.scala b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2.scala index 38f7000c0..75d5dde76 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/http2/Http2.scala @@ -293,7 +293,7 @@ private[http] object Http2 extends ExtensionId[Http2Ext] with ExtensionIdProvide override def get(system: ClassicActorSystemProvider): Http2Ext = super.get(system) def apply()(implicit system: ClassicActorSystemProvider): Http2Ext = super.apply(system) override def apply(system: ActorSystem): Http2Ext = super.apply(system) - def lookup(): ExtensionId[_ <: Extension] = Http2 + def lookup: ExtensionId[_ <: Extension] = Http2 def createExtension(system: ExtendedActorSystem): Http2Ext = new Http2Ext()(system) private[http] type HttpImplementation = Flow[SslTlsInbound, SslTlsOutbound, ServerTerminator] diff --git a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/rendering/BodyPartRenderer.scala b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/rendering/BodyPartRenderer.scala index d87e77cad..a26332348 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/rendering/BodyPartRenderer.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/rendering/BodyPartRenderer.scala @@ -151,7 +151,7 @@ private[http] object BodyPartRenderer { def randomBoundary(length: Int = 18, random: java.util.Random = ThreadLocalRandom.current()): String = { val array = new Array[Byte](length) random.nextBytes(array) - Base64.custom.encodeToString(array, false) + Base64.custom().encodeToString(array, false) } /** diff --git a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/rendering/RenderSupport.scala b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/rendering/RenderSupport.scala index aa8ac82fb..afe908fd9 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/rendering/RenderSupport.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/rendering/RenderSupport.scala @@ -56,7 +56,7 @@ private[http] object RenderSupport { val defaultLastChunkBytes: ByteString = renderChunk(HttpEntity.LastChunk) def CancelSecond[T, Mat](first: Source[T, Mat], second: Source[T, Any]): Source[T, Mat] = { - Source.fromGraph(GraphDSL.create(first) { implicit b => frst => + Source.fromGraph(GraphDSL.createGraph(first) { implicit b => frst => import GraphDSL.Implicits._ second ~> Sink.cancelled SourceShape(frst.out) diff --git a/http-core/src/main/scala/org/apache/pekko/http/impl/model/parser/CharacterClasses.scala b/http-core/src/main/scala/org/apache/pekko/http/impl/model/parser/CharacterClasses.scala index aa2814a38..d3228b4d7 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/impl/model/parser/CharacterClasses.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/impl/model/parser/CharacterClasses.scala @@ -13,7 +13,6 @@ package org.apache.pekko.http.impl.model.parser -import org.apache.pekko import org.parboiled2.CharPredicate // efficient encoding of *7-bit* ASCII characters diff --git a/http-core/src/main/scala/org/apache/pekko/http/javadsl/Http.scala b/http-core/src/main/scala/org/apache/pekko/http/javadsl/Http.scala index 822764b99..a9aed51c7 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/javadsl/Http.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/javadsl/Http.scala @@ -43,7 +43,7 @@ import pekko.stream.scaladsl.Keep object Http extends ExtensionId[Http] with ExtensionIdProvider { override def get(system: ActorSystem): Http = super.get(system) override def get(system: ClassicActorSystemProvider): Http = super.get(system) - def lookup() = Http + def lookup = Http def createExtension(system: ExtendedActorSystem): Http = new Http(system) } diff --git a/http-core/src/main/scala/org/apache/pekko/http/javadsl/settings/ParserSettings.scala b/http-core/src/main/scala/org/apache/pekko/http/javadsl/settings/ParserSettings.scala index db8bd917f..75392f273 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/javadsl/settings/ParserSettings.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/javadsl/settings/ParserSettings.scala @@ -27,7 +27,6 @@ import pekko.http.impl.util.JavaMapping.Implicits._ import scala.annotation.varargs import scala.collection.JavaConverters._ import pekko.http.javadsl.model.{ HttpMethod, MediaType, StatusCode, Uri } -import scala.annotation.nowarn import com.typesafe.config.Config /** @@ -138,7 +137,6 @@ object ParserSettings extends SettingsCompanion[ParserSettings] { */ @Deprecated @deprecated("Use forServer or forClient instead", since = "Akka HTTP 10.2.0") - @nowarn("msg=create overrides concrete, non-deprecated symbol") override def create(system: ActorSystem): ParserSettings = create(system.settings.config) def forServer(system: ClassicActorSystemProvider): ParserSettings = diff --git a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/Http.scala b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/Http.scala index 5051026f0..15f9ef2ee 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/Http.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/Http.scala @@ -189,7 +189,6 @@ class HttpExt @InternalStableApi /* constructor signature is hardcoded in Teleme @deprecated( "Use Http().newServerAt(...)...connectionSource() to create a source that can be materialized to a binding.", since = "10.2.0") - @nowarn("msg=deprecated") def bind(interface: String, port: Int = DefaultPortForProtocol, connectionContext: ConnectionContext = defaultServerHttpContext, settings: ServerSettings = ServerSettings(system), @@ -238,7 +237,6 @@ class HttpExt @InternalStableApi /* constructor signature is hardcoded in Teleme * use the `pekko.http.server` config section or pass in a [[pekko.http.scaladsl.settings.ServerSettings]] explicitly. */ @deprecated("Use Http().newServerAt(...)...bindFlow() to create server bindings.", since = "10.2.0") - @nowarn("msg=deprecated") def bindAndHandle( handler: Flow[HttpRequest, HttpResponse, Any], interface: String, port: Int = DefaultPortForProtocol, @@ -320,7 +318,6 @@ class HttpExt @InternalStableApi /* constructor signature is hardcoded in Teleme * use the `pekko.http.server` config section or pass in a [[pekko.http.scaladsl.settings.ServerSettings]] explicitly. */ @deprecated("Use Http().newServerAt(...)...bindSync() to create server bindings.", since = "10.2.0") - @nowarn("msg=deprecated") def bindAndHandleSync( handler: HttpRequest => HttpResponse, interface: String, port: Int = DefaultPortForProtocol, @@ -349,7 +346,6 @@ class HttpExt @InternalStableApi /* constructor signature is hardcoded in Teleme * Any other value for `parallelism` overrides the setting. */ @deprecated("Use Http().newServerAt(...)...bind() to create server bindings.", since = "10.2.0") - @nowarn("msg=deprecated") def bindAndHandleAsync( handler: HttpRequest => Future[HttpResponse], interface: String, port: Int = DefaultPortForProtocol, @@ -1133,7 +1129,7 @@ object Http extends ExtensionId[HttpExt] with ExtensionIdProvider { def apply()(implicit system: ClassicActorSystemProvider): HttpExt = super.apply(system) override def apply(system: ActorSystem): HttpExt = super.apply(system) - def lookup() = Http + def lookup = Http def createExtension(system: ExtendedActorSystem): HttpExt = new HttpExt(system.settings.config.getConfig("pekko.http"))(system) diff --git a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/HttpEntity.scala b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/HttpEntity.scala index 426f9523b..ac0ee8f55 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/HttpEntity.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/HttpEntity.scala @@ -14,12 +14,10 @@ package org.apache.pekko.http.scaladsl.model import java.util.OptionalLong - import language.implicitConversions import java.io.File import java.nio.file.{ Files, Path } import java.lang.{ Iterable => JIterable } - import scala.util.control.NonFatal import scala.concurrent.Future import scala.concurrent.duration._ @@ -38,10 +36,10 @@ import pekko.http.impl.util.JavaMapping.Implicits._ import scala.compat.java8.OptionConverters._ import scala.compat.java8.FutureConverters._ import java.util.concurrent.CompletionStage - import pekko.actor.ClassicActorSystemProvider import pekko.annotation.{ DoNotInherit, InternalApi } +import scala.annotation.nowarn import scala.compat.java8.FutureConverters /** @@ -664,6 +662,7 @@ object HttpEntity { private var maxBytes = -1L private var bytesLeft = Long.MaxValue + @nowarn("msg=getFirst in class Attributes is deprecated") // there's no valid alternative right now override def preStart(): Unit = { attributes.getFirst[SizeLimit] match { case Some(limit: SizeLimit) if limit.isDisabled => diff --git a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/headers/HttpCredentials.scala b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/headers/HttpCredentials.scala index b86ff318a..fc2a7ebfc 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/headers/HttpCredentials.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/headers/HttpCredentials.scala @@ -33,7 +33,7 @@ final case class BasicHttpCredentials(username: String, password: String) extend val cookie = { val userPass = username + ':' + password val bytes = userPass.getBytes(`UTF-8`.nioCharset) - Base64.rfc2045.encodeToChar(bytes, false) + Base64.rfc2045().encodeToChar(bytes, false) } def render[R <: Rendering](r: R): r.type = r ~~ "Basic " ~~ cookie @@ -44,7 +44,7 @@ final case class BasicHttpCredentials(username: String, password: String) extend object BasicHttpCredentials { def apply(credentials: String): BasicHttpCredentials = { - val bytes = Base64.rfc2045.decodeFast(credentials.toCharArray) + val bytes = Base64.rfc2045().decodeFast(credentials.toCharArray) val userPass = new String(bytes, `UTF-8`.nioCharset) userPass.indexOf(':') match { case -1 => apply(userPass, "") diff --git a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/client/HostConnectionPoolSpec.scala b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/client/HostConnectionPoolSpec.scala index 343c465f1..d23e33a92 100644 --- a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/client/HostConnectionPoolSpec.scala +++ b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/client/HostConnectionPoolSpec.scala @@ -886,7 +886,7 @@ class HostConnectionPoolSpec extends PekkoSpecWithMaterializer( // 2. when client connection was established, grab server connection as well and attach to proxies // (cannot be implemented with just mapMaterializedValue because there's no transposing constructor for BidiFlow) BidiFlow.fromGraph( - GraphDSL.create(Sink.asPublisher[HttpResponse](fanout = false), Source.asSubscriber[HttpRequest], + GraphDSL.createGraph(Sink.asPublisher[HttpResponse](fanout = false), Source.asSubscriber[HttpRequest], clientConnectionFlow(serverBinding, connectionKillSwitch))((_, _, _)) { implicit builder => (resIn, reqOut, client) => import GraphDSL.Implicits._ diff --git a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/client/LowLevelOutgoingConnectionSpec.scala b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/client/LowLevelOutgoingConnectionSpec.scala index c3064dc51..9c8c2dbdd 100644 --- a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/client/LowLevelOutgoingConnectionSpec.scala +++ b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/client/LowLevelOutgoingConnectionSpec.scala @@ -1022,7 +1022,8 @@ class LowLevelOutgoingConnectionSpec extends PekkoSpecWithMaterializer with Insi val netOut = TestSubscriber.manualProbe[ByteString]() val netIn = TestPublisher.manualProbe[ByteString]() - RunnableGraph.fromGraph(GraphDSL.create(OutgoingConnectionBlueprint(Host("example.com"), settings, NoLogging)) { + RunnableGraph.fromGraph(GraphDSL.createGraph(OutgoingConnectionBlueprint(Host("example.com"), settings, + NoLogging)) { implicit b => client => import GraphDSL.Implicits._ Source.fromPublisher(netIn) ~> Flow[ByteString].map(SessionBytes(null, _)) ~> client.in2 diff --git a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/server/HttpServerTestSetupBase.scala b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/server/HttpServerTestSetupBase.scala index 8fcab08a5..c6d36e8ac 100644 --- a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/server/HttpServerTestSetupBase.scala +++ b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/server/HttpServerTestSetupBase.scala @@ -46,7 +46,7 @@ abstract class HttpServerTestSetupBase { val netIn = TestPublisher.probe[ByteString]() val netOut = ByteStringSinkProbe() - RunnableGraph.fromGraph(GraphDSL.create(modifyServer(Http().serverLayer(settings))) { implicit b => server => + RunnableGraph.fromGraph(GraphDSL.createGraph(modifyServer(Http().serverLayer(settings))) { implicit b => server => import GraphDSL.Implicits._ Source.fromPublisher(netIn) ~> Flow[ByteString].map(SessionBytes(null, _)) ~> server.in2 server.out1 ~> Flow[SslTlsOutbound].collect { case SendBytes(x) => x }.buffer(1, diff --git a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/ws/ByteStringSinkProbe.scala b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/ws/ByteStringSinkProbe.scala index b0137e3ea..0230c7124 100644 --- a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/ws/ByteStringSinkProbe.scala +++ b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/ws/ByteStringSinkProbe.scala @@ -64,7 +64,7 @@ private[http] object ByteStringSinkProbe { } def expectNoBytes(): Unit = { ensureRequested() - probe.expectNoMsg() + probe.expectNoMessage() } def expectNoBytes(timeout: FiniteDuration): Unit = { ensureRequested() diff --git a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/ws/WSClientAutobahnTest.scala b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/ws/WSClientAutobahnTest.scala index 336a92eeb..1a3761a85 100644 --- a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/ws/WSClientAutobahnTest.scala +++ b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/ws/WSClientAutobahnTest.scala @@ -50,7 +50,7 @@ object WSClientAutobahnTest extends App { s"ws://localhost:9001/updateReports?agent=$agent" def runCase(caseIndex: Int, agent: String = Agent): Future[CaseStatus] = - runWs(runCaseUri(caseIndex, agent), echo).recover { case _ => () }.flatMap { _ => + runWs(runCaseUri(caseIndex, agent), echo).recover { case _ => (): Any }.flatMap { _ => getCaseStatus(caseIndex, agent) } diff --git a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/ws/WebSocketClientSpec.scala b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/ws/WebSocketClientSpec.scala index b1ebeaa5b..79a4e8e3a 100644 --- a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/ws/WebSocketClientSpec.scala +++ b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/ws/WebSocketClientSpec.scala @@ -373,7 +373,7 @@ class WebSocketClientSpec extends PekkoSpecWithMaterializer("pekko.http.client.w val netIn = TestPublisher.probe[ByteString]() val graph = - RunnableGraph.fromGraph(GraphDSL.create(clientLayer) { implicit b => client => + RunnableGraph.fromGraph(GraphDSL.createGraph(clientLayer) { implicit b => client => import GraphDSL.Implicits._ Source.fromPublisher(netIn) ~> Flow[ByteString].map(SessionBytes(null, _)) ~> client.in2 client.out1 ~> Flow[SslTlsOutbound].collect { case SendBytes(x) => x } ~> netOut.sink diff --git a/http-core/src/test/scala/org/apache/pekko/http/impl/model/parser/HttpHeaderSpec.scala b/http-core/src/test/scala/org/apache/pekko/http/impl/model/parser/HttpHeaderSpec.scala index d7d973e52..3585395bb 100644 --- a/http-core/src/test/scala/org/apache/pekko/http/impl/model/parser/HttpHeaderSpec.scala +++ b/http-core/src/test/scala/org/apache/pekko/http/impl/model/parser/HttpHeaderSpec.scala @@ -13,10 +13,14 @@ package org.apache.pekko.http.impl.model.parser +import org.scalatest.exceptions.TestFailedException +import org.scalatest.freespec.AnyFreeSpec +import org.scalatest.matchers.should.Matchers +import org.scalatest.matchers.{ MatchResult, Matcher } + import org.apache.pekko import pekko.http.scaladsl.settings.ParserSettings.CookieParsingMode import pekko.http.impl.model.parser.HeaderParser.Settings -import org.scalatest.matchers.{ MatchResult, Matcher } import pekko.http.impl.util._ import pekko.http.scaladsl.model.{ HttpHeader, _ } import headers._ @@ -29,9 +33,6 @@ import HttpMethods._ import java.net.InetAddress import pekko.http.scaladsl.model.MediaType.WithOpenCharset -import org.scalatest.exceptions.TestFailedException -import org.scalatest.freespec.AnyFreeSpec -import org.scalatest.matchers.should.Matchers class HttpHeaderSpec extends AnyFreeSpec with Matchers { val `application/vnd.spray` = MediaType.applicationBinary("vnd.spray", MediaType.Compressible) @@ -56,7 +57,8 @@ class HttpHeaderSpec extends AnyFreeSpec with Matchers { MediaRange.custom("text", Map("foo" -> "bar")), MediaType.customBinary("custom", "custom", MediaType.Compressible, params = Map("bar" -> "b>az"))) "Accept: application/*+xml; version=2" =!= - Accept(MediaType.customBinary("application", "*+xml", MediaType.Compressible, params = Map("version" -> "2"))) + Accept(MediaType.customBinary("application", "*+xml", MediaType.Compressible, + params = Map("version" -> "2")): MediaRange) } "Accept-Charset" in { diff --git a/http-core/src/test/scala/org/apache/pekko/http/scaladsl/settings/ConnectionPoolSettingsSpec.scala b/http-core/src/test/scala/org/apache/pekko/http/scaladsl/settings/ConnectionPoolSettingsSpec.scala index d86582652..8a10a734c 100644 --- a/http-core/src/test/scala/org/apache/pekko/http/scaladsl/settings/ConnectionPoolSettingsSpec.scala +++ b/http-core/src/test/scala/org/apache/pekko/http/scaladsl/settings/ConnectionPoolSettingsSpec.scala @@ -13,9 +13,6 @@ package org.apache.pekko.http.scaladsl.settings -import scala.util.Failure -import scala.util.Success -import scala.util.Try import org.apache.pekko import pekko.testkit.PekkoSpec import pekko.http.scaladsl.model.headers.`User-Agent` @@ -161,11 +158,6 @@ class ConnectionPoolSettingsSpec extends PekkoSpec { settings.forHost("akka.com").minConnections shouldEqual 2 settings.minConnections shouldEqual 2 } - - def expectError(configString: String): String = Try(config(configString)) match { - case Failure(cause) => cause.getMessage - case Success(_) => fail("Expected a failure when max-open-requests is not a power of 2") - } } def config(configString: String): ConnectionPoolSettings = diff --git a/project/Common.scala b/project/Common.scala index aaa8388f3..17327ccc3 100644 --- a/project/Common.scala +++ b/project/Common.scala @@ -45,6 +45,9 @@ object Common extends AutoPlugin { (if (isJdk8) Seq.empty else if (scalaBinaryVersion.value == "2.12") Seq("-target:jvm-1.8") else Seq("-release", "8")), + Test / scalacOptions ++= Seq( + // we sometimes use pattern definitions in tests just for the side-effects and don't care about the extra member + "-Wconf:msg=Pattern definition introduces Unit-valued member:s"), javacOptions ++= Seq("-encoding", "UTF-8") ++ onlyOnJdk8("-source", "1.8") ++ onlyAfterJdk8("--release", "8"), // restrict to 'compile' scope because otherwise it is also passed to