maropu commented on a change in pull request #31733:
URL: https://github.com/apache/spark/pull/31733#discussion_r587216175
##########
File path: core/src/main/scala/org/apache/spark/util/Utils.scala
##########
@@ -2858,6 +2858,31 @@ private[spark] object Utils extends Logging {
Hex.encodeHexString(secretBytes)
}
+ /**
+ * Returns true if and only if the underlying class is a member class.
+ *
+ * Note: jdk8u throws a "Malformed class name" error if a given class is a
deeply-nested
+ * inner class (See SPARK-34607 for details). This issue has already been
fixed in jdk9+, so
+ * we can remove this helper method safely if we drop the support of jdk8u.
+ */
+ def isMemberClass(cls: Class[_]): Boolean = {
+ try {
+ cls.isMemberClass
+ } catch {
+ case _: InternalError =>
+ // We emulate jdk8u `Class.isMemberClass` below:
+ // public boolean isMemberClass() {
+ // return getSimpleBinaryName() != null &&
!isLocalOrAnonymousClass();
+ // }
+ // `getSimpleBinaryName()` returns null if a given class is a
top-level class,
+ // so we replace it with `cls.getEnclosingClass != null`. The second
condition checks
+ // if a given class is not a local or an anonymous class, so we
replace it with
+ // `cls.getEnclosingMethod == null` because `cls.getEnclosingMethod()`
return a value
+ // only in either case (JVM Spec 4.8.6).
+ cls.getEnclosingClass != null && cls.getEnclosingMethod == null
Review comment:
Ah, okay. Nice suggestion and I'll follow it.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]