edoardocomar commented on code in PR #21873:
URL: https://github.com/apache/kafka/pull/21873#discussion_r3311064879
##########
core/src/main/scala/kafka/network/SocketServer.scala:
##########
@@ -98,7 +94,8 @@ class SocketServer(
private val memoryPoolDepletedPercentMetricName =
metrics.metricName("MemoryPoolAvgDepletedPercent", JSocketServer.METRICS_GROUP)
private val memoryPoolDepletedTimeMetricName =
metrics.metricName("MemoryPoolDepletedTimeTotal", JSocketServer.METRICS_GROUP)
memoryPoolSensor.add(new Meter(TimeUnit.MILLISECONDS,
memoryPoolDepletedPercentMetricName, memoryPoolDepletedTimeMetricName))
- private val memoryPool = if (config.queuedMaxBytes > 0) new
SimpleMemoryPool(config.queuedMaxBytes, config.socketRequestMaxBytes, false,
memoryPoolSensor) else MemoryPool.NONE
+ // accessible for testing
+ val memoryPool = if (config.queuedMaxBytes > 0) new
SimpleMemoryPool(config.queuedMaxBytes, config.socketRequestMaxBytes, false,
memoryPoolSensor) else MemoryPool.NONE
Review Comment:
Done
TIL
private[network] in Scala 2 compiles to a public getter method in JVM
bytecode. The private[network] restriction is enforced only by the Scala
compiler — it will reject Scala code outside kafka.network that tries to call
memoryPool(). But the underlying bytecode method has public visibility, so Java
code can call
it freely, completely bypassing the Scala-level restriction.
This is a fundamental limitation of how Scala 2 maps its package-scoped
visibility to the JVM: the JVM has no concept of "private to a specific named
package," so the compiler can only enforce the restriction syntactically during
Scala-to-Scala compilation. Any Java caller (or even reflection) sees a fully
public method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]