Skip to content

Commit

Permalink
refactor: Remove compiler warning stemming from -Wvalue-discard (#2831)
Browse files Browse the repository at this point in the history
  • Loading branch information
seakayone authored Sep 8, 2023
1 parent c754042 commit 9071204
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,8 @@ class OntologyV2R2RSpec extends R2RSpec {
*/
def storeClientTestData(responseStr: String): Unit =
maybeClientTestDataBasename match {
case Some(clientTestDataBasename) =>
CollectClientTestData(clientTestDataBasename, responseStr)

case None => ()
case Some(clientTestDataBasename) => CollectClientTestData(clientTestDataBasename, responseStr)
case None => ()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,5 @@ class CacheUtilSpec extends CoreSpec {
CacheUtil.createCaches(appConfig.cacheConfigs)
CacheUtil.get(cacheName, 213.toString) should be(None)
}

"allow to delete a set value " in {
CacheUtil.removeAllCaches()
CacheUtil.createCaches(appConfig.cacheConfigs)
CacheUtil.remove(cacheName, sessionId)
CacheUtil.get(cacheName, sessionId) should be(None)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ object PermissionsMessagesUtilADM {
}
}

def checkPermissionIri(iri: IRI): Unit = {
def checkPermissionIri(iri: IRI): IRI = {
implicit val sf: StringFormatter = StringFormatter.getInstanceForConstantOntologies
sf.validatePermissionIri(iri).fold(e => throw BadRequestException(e), v => v)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class JenaModel(private val dataset: jena.query.Dataset, private val nodeFactory
override def setNamespace(prefix: String, namespace: IRI): Unit = {
def setNamespaceInGraph(graph: jena.graph.Graph): Unit = {
val prefixMapping: jena.shared.PrefixMapping = graph.getPrefixMapping
prefixMapping.setNsPrefix(prefix, namespace)
val _ = prefixMapping.setNsPrefix(prefix, namespace)
}

// Add the namespace to the default graph.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ object GravsearchParser {

if (smartIri.isKnoraEntityIri) {
smartIri.getOntologySchema match {
case Some(_: ApiV2Schema) => allIris.add(smartIri)
case Some(_: ApiV2Schema) => val _ = allIris.add(smartIri)
case _ => throw GravsearchException(s"Ontology schema not allowed in Gravsearch query: $smartIri")
}
}
Expand Down Expand Up @@ -470,7 +470,7 @@ object GravsearchParser {
if (node.getName.startsWith("_const_")) {
// This is a parser-generated constant used in the CONSTRUCT clause. Just save it so we can
// build the CONSTRUCT clause correctly later.
valueConstants.put(node.getName, valueConstant)
val _ = valueConstants.put(node.getName, valueConstant)
} else {
// It's a BIND. Accept it if it refers to a Knora data IRI.
valueConstant.getValue match {
Expand Down
19 changes: 8 additions & 11 deletions webapi/src/main/scala/org/knora/webapi/responders/IriLocker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package org.knora.webapi.responders

import zio.Task
import zio.UIO
import zio.ZIO

import java.util.UUID
Expand Down Expand Up @@ -99,15 +100,10 @@ object IriLocker {
* @param task The [[Task]] that performs the update.
* @return the result of the task.
*/
def runWithIriLock[T](apiRequestID: UUID, iri: IRI, task: Task[T]): Task[T] = {
val acquireLock: Task[Unit] = ZIO.attemptBlocking(this.acquireLock(iri, apiRequestID)).logError
def releaseLock(ignored: Unit) = ZIO.attempt(decrementOrReleaseLock(iri, apiRequestID)).logError.ignore
ZIO.scoped {
for {
_ <- ZIO.acquireRelease(acquireLock)(releaseLock)
taskResult <- task
} yield taskResult
}
def runWithIriLock[A](apiRequestID: UUID, iri: IRI, task: Task[A]): Task[A] = {
val acquire: Task[Unit] = ZIO.attemptBlocking(this.acquireLock(iri, apiRequestID)).logError
val release: Unit => UIO[Unit] = _ => ZIO.attempt(decrementOrReleaseLock(iri, apiRequestID)).logError.ignore
ZIO.scoped(ZIO.acquireRelease(acquire)(release) *> task)
}

/**
Expand Down Expand Up @@ -177,8 +173,8 @@ object IriLocker {
* @param iri the IRI that is locked.
* @param apiRequestID the ID of the API request that has the lock.
*/
private def decrementOrReleaseLock(iri: IRI, apiRequestID: UUID): Unit =
lockMap.compute(
private def decrementOrReleaseLock(iri: IRI, apiRequestID: UUID): Unit = {
val _ = lockMap.compute(
iri,
JavaUtil.biFunction({ (_, maybeCurrentLock) =>
Option(maybeCurrentLock) match {
Expand Down Expand Up @@ -209,4 +205,5 @@ object IriLocker {
}
})
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ final case class ProjectsResponderADMLive(
}

if (projectUpdatePayload.status.nonEmpty) {
projectUpdatePayload.status
val _ = projectUpdatePayload.status
.map(_.value)
.filter(_ == updatedProject.status)
.getOrElse(
Expand All @@ -637,7 +637,7 @@ final case class ProjectsResponderADMLive(
}

if (projectUpdatePayload.selfjoin.nonEmpty) {
projectUpdatePayload.selfjoin
val _ = projectUpdatePayload.selfjoin
.map(_.value)
.filter(_ == updatedProject.selfjoin)
.getOrElse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private object TriGCombiner {
override def prefix(prefix: String, iri: String): Unit =
if (!prefixes.contains(prefix)) {
writer.prefix(prefix, iri)
prefixes.add(prefix)
val _ = prefixes.add(prefix)
}
override def triple(triple: Triple): Unit = writer.triple(triple)
override def quad(quad: Quad): Unit = writer.quad(quad)
Expand Down
9 changes: 4 additions & 5 deletions webapi/src/main/scala/org/knora/webapi/util/ActorUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ import akka.actor.ActorRef
import zio._

import dsp.errors._
import org.knora.webapi.routing.UnsafeZioRun

object ActorUtil {

/**
* _Unsafely_ runs a ZIO workflow and sends the result to the `sender` actor as a message or a failure.
* Used mainly during the refactoring phase, to be able to return ZIO inside an Actor.
*/
def zio2Message[R, A](sender: ActorRef, zioTask: ZIO[R, Throwable, A])(implicit runtime: Runtime[R]): Unit =
Unsafe.unsafe { implicit u =>
runtime.unsafe.run(
zioTask.foldCause(cause => sender ! akka.actor.Status.Failure(cause.squash), success => sender ! success)
)
def zio2Message[R, A](sender: ActorRef, zio: ZIO[R, Throwable, A])(implicit runtime: Runtime[R]): Unit =
UnsafeZioRun.runOrThrow {
zio.foldCause(cause => sender ! akka.actor.Status.Failure(cause.squash), success => sender ! success)
}

/**
Expand Down
5 changes: 2 additions & 3 deletions webapi/src/main/scala/org/knora/webapi/util/FileUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object FileUtil {
* @param file the destination file.
* @param content the string to write.
*/
def writeTextFile(file: Path, content: String): Unit =
def writeTextFile(file: Path, content: String): Path =
writeBinaryFile(file, content.getBytes(StandardCharsets.UTF_8))

/**
Expand Down Expand Up @@ -93,8 +93,7 @@ object FileUtil {
* @param file the destination file.
* @param content the binary data to write.
*/
def writeBinaryFile(file: Path, content: Array[Byte]): Unit =
Files.write(file, content)
private def writeBinaryFile(file: Path, content: Array[Byte]) = Files.write(file, content)

/**
* Generates a byte array representing a Zip file containing the specified data. The Zip file data is
Expand Down
18 changes: 0 additions & 18 deletions webapi/src/main/scala/org/knora/webapi/util/cache/CacheUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,6 @@ object CacheUtil {
}

}

/**
* Tries to remove a value from a cache.
*
* @param cacheName the name of the cache.
* @param key the cache key as a [[String]]
*/
def remove(cacheName: String, key: String): Unit = {
val cacheManager = CacheManager.getInstance()
val cacheOption = Option(cacheManager.getCache(cacheName))

cacheOption match {
case Some(cache) => cache.remove(key)
case None =>
throw ApplicationCacheException(s"Can't find application cache '$cacheName'")
}
}

}

class LoggingCacheEventListener(log: Logger) extends CacheEventListener {
Expand Down

0 comments on commit 9071204

Please sign in to comment.