Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import pekko.testkit.TestKit
}

private def messageOrEmpty(event: LoggingEvent): String =
if (event.message == null) "" else event.message
if (event.message eq null) "" else event.message

private def sourceOrEmpty(event: LoggingEvent): String =
event.mdc.getOrElse("pekkoSource", "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object SpawnProtocol {
msg match {
case Spawn(bhvr: Behavior[t], name, props, replyTo) =>
val ref =
if (name == null || name.equals(""))
if ((name eq null) || name.equals(""))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are the extra parentheses needed?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

likewise for all the extra parentheses?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, otherwise compiling error

ctx.spawnAnonymous(bhvr, props)
else {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ import scala.util.Success
future: CompletionStage[Value],
applyToResult: pekko.japi.function.Function2[Value, Throwable, T]): Unit = {
future.handle[Unit] { (value, ex) =>
if (ex != null)
if (ex ne null)
self.unsafeUpcast ! AdaptMessage(ex, applyToResult.apply(null.asInstanceOf[Value], _: Throwable))
else self.unsafeUpcast ! AdaptMessage(value, applyToResult.apply(_: Value, null))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ import pekko.annotation.InternalApi
}

final case class ActorTagsImpl(tags: Set[String], next: Props = Props.empty) extends ActorTags {
if (tags == null)
if (tags eq null)
throw new IllegalArgumentException("Tags must not be null")
def withNext(next: Props): Props = copy(next = next)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ import java.util.function.Predicate
override def exists(predicate: T => Boolean): Boolean = {
var hasElement = false
var node = _first
while (node != null && !hasElement) {
while ((node ne null) && !hasElement) {
hasElement = predicate(node.message)
node = node.next
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,12 @@ object Behaviors {
behavior: Behavior[T]): Behavior[T] = {

def asScalaMap(m: java.util.Map[String, String]): Map[String, String] = {
if (m == null || m.isEmpty) Map.empty[String, String]
if ((m eq null) || m.isEmpty) Map.empty[String, String]
else m.asScala.toMap
}

val mdcForMessageFun: T => Map[String, String] =
if (mdcForMessage == null) _ => Map.empty
if (mdcForMessage eq null) _ => Map.empty
else { message =>
asScalaMap(mdcForMessage.apply(message))
}
Expand Down
8 changes: 4 additions & 4 deletions actor/src/main/scala/org/apache/pekko/actor/Actor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ final case class Identify(messageId: Any) extends AutoReceivedMessage with NotIn
*/
@SerialVersionUID(1L)
final case class ActorIdentity(correlationId: Any, ref: Option[ActorRef]) {
if (ref.isDefined && ref.get == null) {
if (ref.isDefined && (ref.get eq null)) {
throw new IllegalArgumentException(
"ActorIdentity created with ref = Some(null) is not allowed, " +
"this could happen when serializing with Scala 2.12 and deserializing with Scala 2.11 which is not supported.")
Expand Down Expand Up @@ -201,7 +201,7 @@ class ActorInitializationException protected (actor: ActorRef, message: String,
}
object ActorInitializationException {
private def enrichedMessage(actor: ActorRef, message: String) =
if (actor == null) message else s"${actor.path}: $message"
if (actor eq null) message else s"${actor.path}: $message"
private[pekko] def apply(actor: ActorRef, message: String, cause: Throwable = null): ActorInitializationException =
new ActorInitializationException(actor, message, cause)
private[pekko] def apply(message: String): ActorInitializationException =
Expand Down Expand Up @@ -230,7 +230,7 @@ final case class PreRestartException private[pekko] (
extends ActorInitializationException(
actor,
"exception in preRestart(" +
(if (originalCause == null) "null" else originalCause.getClass) + ", " +
(if (originalCause eq null) "null" else originalCause.getClass) + ", " +
(messageOption match { case Some(m: AnyRef) => m.getClass; case _ => "None" }) +
")",
cause)
Expand All @@ -247,7 +247,7 @@ final case class PreRestartException private[pekko] (
final case class PostRestartException private[pekko] (actor: ActorRef, cause: Throwable, originalCause: Throwable)
extends ActorInitializationException(
actor,
"exception post restart (" + (if (originalCause == null) "null" else originalCause.getClass) + ")",
"exception post restart (" + (if (originalCause eq null) "null" else originalCause.getClass) + ")",
cause)

/**
Expand Down
4 changes: 2 additions & 2 deletions actor/src/main/scala/org/apache/pekko/actor/ActorCell.scala
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ private[pekko] class ActorCell(

protected def create(failure: Option[ActorInitializationException]): Unit = {
def failActor(): Unit =
if (_actor != null) {
if (_actor ne null) {
clearActorFields(actor, recreate = false)
_actor = null // ensure that we know that we failed during creation
}
Expand Down Expand Up @@ -684,7 +684,7 @@ private[pekko] class ActorCell(

@tailrec
private def rootCauseOf(throwable: Throwable): Throwable = {
if (throwable.getCause != null && throwable.getCause != throwable)
if ((throwable.getCause ne null) && throwable.getCause != throwable)
rootCauseOf(throwable.getCause)
else
throwable
Expand Down
8 changes: 4 additions & 4 deletions actor/src/main/scala/org/apache/pekko/actor/Address.scala
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@ object AddressFromURIString {

def unapply(uri: URI): Option[Address] =
if (uri eq null) None
else if (uri.getScheme == null || (uri.getUserInfo == null && uri.getHost == null)) None
else if (uri.getUserInfo == null) { // case 1: “pekko://system”
else if ((uri.getScheme eq null) || (uri.getUserInfo == null && (uri.getHost eq null))) None
else if (uri.getUserInfo eq null) { // case 1: “pekko://system”
if (uri.getPort != -1) None
else Some(Address(uri.getScheme, uri.getHost))
} else { // case 2: “pekko://system@host:port”
if (uri.getHost == null || uri.getPort == -1) None
if ((uri.getHost eq null) || uri.getPort == -1) None
else
Some(
if (uri.getUserInfo == null) Address(uri.getScheme, uri.getHost)
if (uri.getUserInfo eq null) Address(uri.getScheme, uri.getHost)
else Address(uri.getScheme, uri.getUserInfo, uri.getHost, uri.getPort))
}

Expand Down
6 changes: 3 additions & 3 deletions actor/src/main/scala/org/apache/pekko/actor/FSM.scala
Original file line number Diff line number Diff line change
Expand Up @@ -696,22 +696,22 @@ trait FSM[S, D] extends Actor with Listeners with ActorLogging {
* @see [[#startWith]]
*/
final def initialize(): Unit =
if (currentState != null) makeTransition(currentState)
if (currentState ne null) makeTransition(currentState)
else throw new IllegalStateException("You must call `startWith` before calling `initialize`")

/**
* Return current state name (i.e. object of type S)
*/
final def stateName: S = {
if (currentState != null) currentState.stateName
if (currentState ne null) currentState.stateName
else throw new IllegalStateException("You must call `startWith` before using `stateName`")
}

/**
* Return current state data (i.e. object of type D)
*/
final def stateData: D =
if (currentState != null) currentState.stateData
if (currentState ne null) currentState.stateData
else throw new IllegalStateException("You must call `startWith` before using `stateData`")

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class LightArrayRevolverScheduler(config: Config, log: LoggingAdapter, threadFac
try {
runnable.run()
val driftNanos = clock() - getAndAdd(delay.toNanos)
if (self.get() != null)
if (self.get() ne null)
swap(schedule(executor, this, Duration.fromNanos(Math.max(delay.toNanos - driftNanos, 1))))
} catch {
case _: SchedulerException => // ignore failure to enqueue or terminated target actor
Expand Down Expand Up @@ -204,10 +204,10 @@ class LightArrayRevolverScheduler(config: Config, log: LoggingAdapter, threadFac

private def schedule(ec: ExecutionContext, r: Runnable, delay: FiniteDuration): TimerTask =
if (delay.length <= 0L) { // use simple comparison instead of Ordering for performance
if (stopped.get != null) throw SchedulerException("cannot enqueue after timer shutdown")
if (stopped.get ne null) throw SchedulerException("cannot enqueue after timer shutdown")
ec.execute(r)
NotCancellable
} else if (stopped.get != null) {
} else if (stopped.get ne null) {
throw SchedulerException("cannot enqueue after timer shutdown")
} else {
val delayNanos = delay.toNanos
Expand All @@ -216,7 +216,7 @@ class LightArrayRevolverScheduler(config: Config, log: LoggingAdapter, threadFac
val ticks = (delayNanos / tickNanos).toInt
val task = new TaskHolder(r, ticks, ec)
queue.add(task)
if (stopped.get != null && task.cancel())
if ((stopped.get ne null) && task.cancel())
throw SchedulerException("cannot enqueue after timer shutdown")
task
}
Expand Down
8 changes: 4 additions & 4 deletions actor/src/main/scala/org/apache/pekko/actor/Scheduler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ trait Scheduler {
override def run(): Unit = {
try {
runnable.run()
if (get != null)
if (get ne null)
swap(scheduleOnce(delay, this))
} catch {
// ignore failure to enqueue or terminated target actor
case _: SchedulerException =>
case e: IllegalStateException if e.getCause != null && e.getCause.isInstanceOf[SchedulerException] =>
case _: SchedulerException =>
case e: IllegalStateException if (e.getCause ne null) && e.getCause.isInstanceOf[SchedulerException] =>
}
}

Expand Down Expand Up @@ -541,7 +541,7 @@ object Scheduler {

@tailrec final protected def swap(c: Cancellable): Unit = {
get match {
case null => if (c != null) c.cancel()
case null => if (c ne null) c.cancel()
case old =>
if (!compareAndSet(old, c))
swap(c)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private[pekko] trait Dispatch { this: ActorCell =>
val req = system.mailboxes.getRequiredType(actorClass)
if (req.isInstance(mbox.messageQueue)) Create(None)
else {
val gotType = if (mbox.messageQueue == null) "null" else mbox.messageQueue.getClass.getName
val gotType = if (mbox.messageQueue eq null) "null" else mbox.messageQueue.getClass.getName
Create(Some(ActorInitializationException(self, s"Actor [$self] requires mailbox type [$req] got [$gotType]")))
}
case _ => Create(None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private[pekko] trait FaultHandling { this: ActorCell =>
* Do re-create the actor in response to a failure.
*/
protected def faultRecreate(cause: Throwable): Unit =
if (actor == null) {
if (actor eq null) {
system.eventStream.publish(
Error(self.path.toString, clazz(actor), "changing Recreate into Create after " + cause))
faultCreate()
Expand Down Expand Up @@ -134,11 +134,11 @@ private[pekko] trait FaultHandling { this: ActorCell =>
* prompted this action.
*/
protected def faultResume(causedByFailure: Throwable): Unit = {
if (actor == null) {
if (actor eq null) {
system.eventStream.publish(
Error(self.path.toString, clazz(actor), "changing Resume into Create after " + causedByFailure))
faultCreate()
} else if (isFailedFatally && causedByFailure != null) {
} else if (isFailedFatally && (causedByFailure ne null)) {
system.eventStream.publish(
Error(self.path.toString, clazz(actor), "changing Resume into Restart after " + causedByFailure))
faultRecreate(causedByFailure)
Expand All @@ -147,7 +147,7 @@ private[pekko] trait FaultHandling { this: ActorCell =>
// done always to keep that suspend counter balanced
// must happen “atomically”
try resumeNonRecursive()
finally if (causedByFailure != null) clearFailed()
finally if (causedByFailure ne null) clearFailed()
resumeChildren(causedByFailure, perp)
}
}
Expand Down Expand Up @@ -331,7 +331,7 @@ private[pekko] trait FaultHandling { this: ActorCell =>
* otherwise tell the supervisor etc. (in that second case, the match
* below will hit the empty default case, too)
*/
if (actor != null) {
if (actor ne null) {
try actor.supervisorStrategy.handleChildTerminated(this, child, children)
catch handleNonFatalOrInterruptedException { e =>
publish(Error(e, self.path.toString, clazz(actor), "handleChildTerminated failed"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private[dispatch] object VirtualThreadSupport {
val ofVirtualClass = ClassLoader.getSystemClassLoader.loadClass("java.lang.Thread$Builder$OfVirtual")
val ofVirtualMethod = classOf[Thread].getDeclaredMethod("ofVirtual")
var builder = ofVirtualMethod.invoke(null)
if (executor != null) {
if (executor ne null) {
val clazz = builder.getClass
val field = clazz.getDeclaredField("scheduler")
field.setAccessible(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class EventStream(sys: ActorSystem, private val debug: Boolean) extends LoggingB
protected def classify(event: Any): Class[_] = event.getClass

protected def publish(event: Any, subscriber: ActorRef) = {
if (sys == null && subscriber.isTerminated) unsubscribe(subscriber)
if ((sys eq null) && subscriber.isTerminated) unsubscribe(subscriber)
else subscriber ! event
}

Expand Down
4 changes: 2 additions & 2 deletions actor/src/main/scala/org/apache/pekko/event/Logging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1647,7 +1647,7 @@ trait DiagnosticLoggingAdapter extends LoggingAdapter {
* These values can be used in PatternLayout when `org.apache.pekko.event.slf4j.Slf4jLogger` is configured.
* Visit <a href="https://logback.qos.ch/manual/mdc.html">Logback Docs: MDC</a> for more information.
*/
def mdc(mdc: MDC): Unit = _mdc = if (mdc != null) mdc else emptyMDC
def mdc(mdc: MDC): Unit = _mdc = if (mdc ne null) mdc else emptyMDC

/**
* Java API:
Expand Down Expand Up @@ -1675,7 +1675,7 @@ trait DiagnosticLoggingAdapter extends LoggingAdapter {
* These values can be used in PatternLayout when `org.apache.pekko.event.slf4j.Slf4jLogger` is configured.
* Visit <a href="https://logback.qos.ch/manual/mdc.html">Logback Docs: MDC</a> for more information.
*/
def setMDC(jMdc: java.util.Map[String, Any]): Unit = mdc(if (jMdc != null) jMdc.asScala.toMap else emptyMDC)
def setMDC(jMdc: java.util.Map[String, Any]): Unit = mdc(if (jMdc ne null) jMdc.asScala.toMap else emptyMDC)

/**
* Clear all entries in the MDC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private[pekko] class DirectByteBufferPool(defaultBufferSize: Int, maxPoolEntries
}

// allocate new and clear outside the lock
if (buffer == null)
if (buffer eq null)
allocate(defaultBufferSize)
else {
buffer.clear()
Expand Down
4 changes: 2 additions & 2 deletions actor/src/main/scala/org/apache/pekko/io/Tcp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,9 @@ object Tcp extends ExtensionId[TcpExt] with ExtensionIdProvider {
_cause
.map(t => {
val msg =
if (t.getCause == null)
if (t.getCause eq null)
t.getMessage
else if (t.getCause.getCause == null)
else if (t.getCause.getCause eq null)
s"${t.getMessage}, caused by: ${t.getCause}"
else
s"${t.getMessage}, caused by: ${t.getCause}, caused by: ${t.getCause.getCause}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ private[io] abstract class TcpConnection(val tcp: TcpExt, val channel: SocketCha
}

@tailrec private[this] def extractMsg(t: Throwable): String =
if (t == null) "unknown"
if (t eq null) "unknown"
else {
t.getMessage match {
case null | "" => extractMsg(t.getCause)
Expand Down
2 changes: 1 addition & 1 deletion actor/src/main/scala/org/apache/pekko/io/TcpListener.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private[io] class TcpListener(
case NonFatal(e) => { log.error(e, "Accept error: could not accept new connection"); null }
}
} else null
if (socketChannel != null) {
if (socketChannel ne null) {
log.debug("New connection accepted")
socketChannel.configureBlocking(false)
def props(registry: ChannelRegistry) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private[io] class UdpConnection(
}

override def postStop(): Unit =
if (channel != null && channel.isOpen) {
if ((channel ne null) && channel.isOpen) {
log.debug("Closing DatagramChannel after being stopped")
try channel.close()
catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ object DnsSettings {
val ctx = new InitialDirContext(env)
val dnsUrls = ctx.getEnvironment.get("java.naming.provider.url").asInstanceOf[String]
// Only try if not empty as otherwise we will produce an exception
if (dnsUrls != null && !dnsUrls.isEmpty) {
if ((dnsUrls ne null) && !dnsUrls.isEmpty) {
val servers = dnsUrls.split(" ")
servers.flatMap { server =>
asInetSocketAddress(server).toOption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ final class ExplicitlyAskableActorRef(val actorRef: ActorRef) extends AnyVal {
s"question not sent to [$actorRef]."))
case _ =>
val message =
if (sender == null) null else messageFactory(sender.asInstanceOf[InternalActorRef].provider.deadLetters)
if (sender eq null) null else messageFactory(sender.asInstanceOf[InternalActorRef].provider.deadLetters)
Future.failed[Any](AskableActorRef.unsupportedRecipientType(actorRef, message, sender))
}
}
Expand Down Expand Up @@ -501,7 +501,7 @@ final class ExplicitlyAskableActorSelection(val actorSel: ActorSelection) extend
s"question not sent to [$actorSel]."))
case _ =>
val message =
if (sender == null) null else messageFactory(sender.asInstanceOf[InternalActorRef].provider.deadLetters)
if (sender eq null) null else messageFactory(sender.asInstanceOf[InternalActorRef].provider.deadLetters)
Future.failed[Any](AskableActorRef.unsupportedRecipientType(actorSel, message, sender))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ class CircuitBreaker(

private def isIgnoredException(ex: Any): Boolean =
allowExceptions.nonEmpty && (ex match {
case ce: CompletionException => ce.getCause != null && allowExceptions.contains(ce.getCause.getClass.getName)
case ce: CompletionException => (ce.getCause ne null) && allowExceptions.contains(ce.getCause.getClass.getName)
case _ => allowExceptions.contains(ex.getClass.getName)
})

Expand Down
Loading