Skip to content

Commit

Permalink
Fix warnings for "Auto-application to () is deprecated" (#989)
Browse files Browse the repository at this point in the history
In the spirit of reducing compile warnings to see actual issues, this patch resolves many issues with the "Auto-application to `()` is deprecated" warning. These fixes were auto-applied by using the `scala-rewrites` plugins for `sbt-scalafix` and, for now, scalafix won't be configured to check for this issue during CI.

The full warning looks like this:

    Auto-application to `()` is deprecated. Supply the empty argument list `()` explicitly to invoke method unbundleTasks,
    [warn] or remove the empty argument list from its definition (Java-defined methods are exempt).
    [warn] In Scala 3, an unapplied method like this will be eta-expanded into a function.
    [warn]       this.service.unbundleTasks(User.superUser, bundle.bundleId, List(task2.id))

There were some version issues with the plugin were resolved with these steps:

- build.sbt:
  - Set `scalaVersion := "2.13.8"`
  - Add `ThisBuild / scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value)`
- project/plugins.sbt:
  - Change sbt-scalafix to `addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.34")`

Now run `scalafixAll dependency:fix.scala213.ExplicitNonNullaryApply@org.scala-lang:scala-rewrites:0.1.3`
  • Loading branch information
ljdelight authored Oct 25, 2022
1 parent b25b33f commit 3f27b6c
Show file tree
Hide file tree
Showing 23 changed files with 109 additions and 100 deletions.
4 changes: 2 additions & 2 deletions app/controllers/AuthController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class AuthController @Inject() (
*/
def authenticate(): Action[AnyContent] = Action.async { implicit request =>
MPExceptionUtil.internalAsyncExceptionCatcher { () =>
val p = Promise[Result]
val p = Promise[Result]()
val redirect = request.getQueryString("redirect").getOrElse("")
request.getQueryString("oauth_verifier") match {
case Some(verifier) =>
Expand Down Expand Up @@ -119,7 +119,7 @@ class AuthController @Inject() (

def signIn(redirect: String): Action[AnyContent] = Action.async { implicit request =>
MPExceptionUtil.internalAsyncExceptionCatcher { () =>
val p = Promise[Result]
val p = Promise[Result]()
request.body.asFormUrlEncoded match {
case Some(data) =>
val username = data.getOrElse("signInUsername", ArrayBuffer("")).mkString
Expand Down
4 changes: 2 additions & 2 deletions app/org/maproulette/controllers/OSMChangesetController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class OSMChangesetController @Inject() (
}
},
element => {
val p = Promise[Result]
val p = Promise[Result]()
val future = changeType match {
case OSMChangesetController.CHANGETYPE_OSMCHANGE =>
val updates = element.map(tagChange => {
Expand Down Expand Up @@ -97,7 +97,7 @@ class OSMChangesetController @Inject() (
}
},
element => {
val p = Promise[Result]
val p = Promise[Result]()
// For now just support creation of new geometries
changeService.getOsmChange(element, None) onComplete {
case Success(res) =>
Expand Down
4 changes: 2 additions & 2 deletions app/org/maproulette/controllers/api/ChallengeController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1071,9 +1071,9 @@ class ChallengeController @Inject() (
rebuild: Boolean
): Action[AnyContent] = Action.async { implicit request =>
this.sessionManager.authenticatedFutureRequest { implicit user =>
val result = Promise[Result]
val result = Promise[Result]()
val baseURL = s"https://raw.githubusercontent.com/$username/$repo/master/${name}_";
this.wsClient.url(s"${baseURL}create.json").get onComplete {
this.wsClient.url(s"${baseURL}create.json").get() onComplete {
case Success(response) =>
try {
// inject the info link into the challenge
Expand Down
4 changes: 2 additions & 2 deletions app/org/maproulette/controllers/api/TaskController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ class TaskController @Inject() (
this.sessionManager.authenticatedFutureRequest { implicit user =>
this.dal.retrieveById(taskId) match {
case Some(t) =>
val promise = Promise[Result]
val promise = Promise[Result]()
this.dal.matchToOSMChangeSet(t, user, false) onComplete {
case Success(response) => promise success Ok(Json.toJson(t))
case Failure(error) => promise failure error
Expand All @@ -646,7 +646,7 @@ class TaskController @Inject() (
}
},
element => {
val p = Promise[Result]
val p = Promise[Result]()

val requestReview = request.getQueryString("requestReview") match {
case Some(v) => Some(v.toBoolean)
Expand Down
2 changes: 1 addition & 1 deletion app/org/maproulette/exception/MPExceptionUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ object MPExceptionUtil {
* @return Future[Result]
*/
def internalAsyncExceptionCatcher(block: () => Future[Result]): Future[Result] = {
val p = Promise[Result]
val p = Promise[Result]()
Try(block()) match {
case Success(f) =>
f onComplete {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ class ChallengeSnapshotController @Inject() (
val priorityActions = snapshot.priorityActions.get

s"${snapshot.created},${snapshot.id},${snapshot.itemId},${snapshot.name},${snapshot.status.getOrElse("")}," +
snapshot.actions.get.values.mkString(",") + "," +
priorityActions(Challenge.PRIORITY_HIGH.toString).values.mkString(",") + "," +
priorityActions(Challenge.PRIORITY_MEDIUM.toString).values.mkString(",") + "," +
priorityActions(Challenge.PRIORITY_LOW.toString).values.mkString(",")
snapshot.actions.get.values().mkString(",") + "," +
priorityActions(Challenge.PRIORITY_HIGH.toString).values().mkString(",") + "," +
priorityActions(Challenge.PRIORITY_MEDIUM.toString).values().mkString(",") + "," +
priorityActions(Challenge.PRIORITY_LOW.toString).values().mkString(",")
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class UserController @Inject() (
*/
def refreshProfile(osmUserId: Long): Action[AnyContent] = Action.async { implicit request =>
sessionManager.authenticatedFutureRequest { implicit user =>
val p = Promise[Result]
val p = Promise[Result]()
this.serviceManager.user.retrieveByOSMId(osmUserId) match {
case Some(u) =>
sessionManager.refreshProfile(u.osmProfile.requestToken, user) onComplete {
Expand Down
2 changes: 1 addition & 1 deletion app/org/maproulette/framework/psql/filter/Parameter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ case class FuzzySearchParameter(
)"""
}

override def parameters(): List[NamedParameter] = List(Symbol(getKey) -> value)
override def parameters(): List[NamedParameter] = List(Symbol(getKey()) -> value)
}

object FilterParameter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class ChallengeService @Inject() (
),
BaseParameter(
Challenge.FIELD_PARENT_ID,
user.managedProjectIds,
user.managedProjectIds(),
Operator.IN,
table = Some(Challenge.TABLE)
)
Expand Down
2 changes: 1 addition & 1 deletion app/org/maproulette/jobs/SchedulerActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ object SchedulerActor {
private val TWELVE_MONTHS = 12
private val ALL_TIME = -1

def props = Props[SchedulerActor]
def props = Props[SchedulerActor]()

case class RunJob(name: String, action: String = "")

Expand Down
4 changes: 2 additions & 2 deletions app/org/maproulette/models/dal/TaskDAL.scala
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ class TaskDAL @Inject() (
def matchToOSMChangeSet(task: Task, user: User, immediate: Boolean = true)(
implicit c: Option[Connection] = None
): Future[Boolean] = {
val result = Promise[Boolean]
val result = Promise[Boolean]()
if (config.allowMatchOSM) {
task.status match {
case Some(Task.STATUS_FIXED) =>
Expand Down Expand Up @@ -930,7 +930,7 @@ class TaskDAL @Inject() (
* @return A list of sorted changesets
*/
private def getSortedChangeList(statusAction: StatusActionItem): Future[Seq[Changeset]] = {
val result = Promise[Seq[Changeset]]
val result = Promise[Seq[Changeset]]()
val format = "YYYY-MM-dd'T'HH:mm:ss'Z'"
val fixedTimeDiff = statusAction.created.getMillis
val prevHours =
Expand Down
2 changes: 1 addition & 1 deletion app/org/maproulette/provider/KeepRightProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class KeepRightProvider @Inject() (

// This will create a challenge for each KeepRight Check and each country
def integrate(checkIDs: List[Int] = List.empty, bounding: KeepRightBox): Future[Boolean] = {
val p = Promise[Boolean]
val p = Promise[Boolean]()
val cidList = URLEncoder.encode(
this.errorList
.filter(cid => checkIDs.isEmpty || checkIDs.contains(cid.id))
Expand Down
14 changes: 7 additions & 7 deletions app/org/maproulette/provider/osm/ChangesetProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ChangesetProvider @Inject() (
import scala.concurrent.ExecutionContext.Implicits.global

def getVersionedChange(tagChanges: List[TagChange]): Future[List[VersionedObject]] = {
val p = Promise[List[VersionedObject]]
val p = Promise[List[VersionedObject]]()
this.conflateTagChanges(tagChanges) onComplete {
case Success(res) => p success res.map(_._1)
case Failure(f) => p failure f
Expand All @@ -56,7 +56,7 @@ class ChangesetProvider @Inject() (
* @return
*/
def testTagChange(tagChanges: List[TagChange]): Future[List[TagChangeResult]] = {
val p = Promise[List[TagChangeResult]]
val p = Promise[List[TagChangeResult]]()
this.conflateTagChanges(tagChanges) onComplete {
case Success(res) => p success res.map(_._2)
case Failure(f) => p failure f
Expand All @@ -77,7 +77,7 @@ class ChangesetProvider @Inject() (
accessToken: RequestToken,
taskId: Option[Long] = None
)(implicit c: Option[Connection] = None): Future[Elem] = {
val p = Promise[Elem]
val p = Promise[Elem]()
// create the new changeset
this.createChangeset(changeSetComment, accessToken) onComplete {
case Success(changesetId) =>
Expand Down Expand Up @@ -137,7 +137,7 @@ class ChangesetProvider @Inject() (
* @return The osmChange XML
*/
def getOsmChange(change: OSMChange, changeSetId: Option[Int]): Future[Elem] = {
val changePromise = Promise[Elem]
val changePromise = Promise[Elem]()
val osmCreates = change.creates match {
case Some(creates) =>
<create>
Expand All @@ -146,7 +146,7 @@ class ChangesetProvider @Inject() (
case None => NodeSeq.Empty
}

val updatesPromise = Promise[NodeSeq]
val updatesPromise = Promise[NodeSeq]()
val osmUpdates = change.updates match {
case Some(updates) =>
// Only support tag changes for now
Expand Down Expand Up @@ -198,7 +198,7 @@ class ChangesetProvider @Inject() (
relations <- relationService.get(relations.map(_.osmId))
} yield (nodes, ways, relations)

val p = Promise[List[(VersionedObject, TagChangeResult)]]
val p = Promise[List[(VersionedObject, TagChangeResult)]]()
results onComplete {
case Success(r) =>
val changes = (r._1 ++ r._2 ++ r._3).flatMap(feature => {
Expand Down Expand Up @@ -271,7 +271,7 @@ class ChangesetProvider @Inject() (
private def checkResult[T](
block: WSResponse => T
)(implicit req: Future[WSResponse], url: String): Future[T] = {
val p = Promise[T]
val p = Promise[T]()
req onComplete {
case Success(res) =>
res.status match {
Expand Down
4 changes: 2 additions & 2 deletions app/org/maproulette/provider/osm/objects/ObjectProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ trait ObjectProvider[T <: VersionedObject] {
* @return A list of VersionedObjects that is basically every version of the object
*/
def getObjectHistory(id: Long, osmType: OSMType): Future[List[T]] = {
val p = Promise[List[T]]
val p = Promise[List[T]]()
if (id < 0) {
p success List.empty
} else {
Expand All @@ -61,7 +61,7 @@ trait ObjectProvider[T <: VersionedObject] {
* @return
*/
protected def getFromType(ids: List[Long], osmType: OSMType): Future[List[T]] = {
val p = Promise[List[T]]
val p = Promise[List[T]]()
if (ids.isEmpty) {
p success List.empty
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import akka.actor._
*/
@Singleton
class WebSocketProvider @Inject() (implicit system: ActorSystem) {
val publisher = system.actorOf(Props[WebSocketPublisher], "publisher")
val publisher = system.actorOf(Props[WebSocketPublisher](), "publisher")

def sendMessage(message: WebSocketMessages.ServerMessage): Unit = {
publisher ! message
Expand Down
10 changes: 5 additions & 5 deletions app/org/maproulette/session/SessionManager.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class SessionManager @Inject() (
* @return A Future which will contain the user
*/
def retrieveUser(verifier: String)(implicit request: Request[AnyContent]): Future[User] = {
val p = Promise[User]
val p = Promise[User]()
this.sessionTokenPair match {
case Some(pair) =>
this.oauth.retrieveAccessToken(pair, verifier) match {
Expand Down Expand Up @@ -137,7 +137,7 @@ class SessionManager @Inject() (
protected def userAware(
block: Option[User] => Result
)(implicit request: Request[Any]): Future[Result] = {
val p = Promise[Result]
val p = Promise[Result]()
this.sessionUser(sessionTokenPair) onComplete {
case Success(result) =>
Try(block(result)) match {
Expand Down Expand Up @@ -169,7 +169,7 @@ class SessionManager @Inject() (
protected def authenticated(
execute: Either[User => Result, User => Future[Result]]
)(implicit request: Request[Any], requireSuperUser: Boolean = false): Future[Result] = {
val p = Promise[Result]
val p = Promise[Result]()
try {
this.sessionUser(sessionTokenPair) onComplete {
case Success(result) =>
Expand Down Expand Up @@ -246,7 +246,7 @@ class SessionManager @Inject() (
def sessionUser(tokenPair: Option[RequestToken], create: Boolean = false)(
implicit request: RequestHeader
): Future[Option[User]] = {
val p = Promise[Option[User]]
val p = Promise[Option[User]]()
val userId = request.session.get(SessionManager.KEY_USER_ID)
val osmId = request.session.get(SessionManager.KEY_OSM_ID)
// if in dev mode we just default every request to super user request
Expand Down Expand Up @@ -375,7 +375,7 @@ class SessionManager @Inject() (
* None.
*/
def refreshProfile(accessToken: RequestToken, user: User): Future[Option[User]] = {
val p = Promise[Option[User]]
val p = Promise[Option[User]]()
// if no user is matched, then lets create a new user
val details = this.ws
.url(this.osmOAuth.userDetailsURL)
Expand Down
6 changes: 3 additions & 3 deletions test/org/maproulette/cache/CacheSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class CacheSpec extends PlaySpec with JodaWrites with JodaReads {
manager.withOptionCaching { () =>
Some(TestBaseObject(1, "name1"))
}
theCache.size mustEqual 0
theCache.size() mustEqual 0
}

"cache only the elements that are not already cached withIDListCaching" in {
Expand All @@ -123,7 +123,7 @@ class CacheSpec extends PlaySpec with JodaWrites with JodaReads {
uncachedList.size mustEqual 2
uncachedList.map(id => TestBaseObject(id, s"name$id"))
}
theCache.size mustEqual 5
theCache.size() mustEqual 5
theCache.get(5).isDefined mustEqual true
theCache.get(6).isDefined mustEqual true
}
Expand Down Expand Up @@ -168,7 +168,7 @@ class CacheSpec extends PlaySpec with JodaWrites with JodaReads {

// The cache may have a thread managing the evictions, so we can't expect an exact size.
// Since we inserted far more items than the capacity, check that some items were evicted.
theCache.size must be < 15L
theCache.size() must be < 15L

// Add a handful of new objects to the cache, and keep fetching one to keep it from being evicted
for (id <- 0L until insertN) {
Expand Down
Loading

0 comments on commit 3f27b6c

Please sign in to comment.