I wonder if this is a known Java bug (Java 8 on Mac)

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

I wonder if this is a known Java bug (Java 8 on Mac)

Vlad Patryshev

scala> object X { object Y { object Z }}

defined module X

scala> X.Y.Z.getClass()

res0: Class[_ <: X.Y.Z.type] = class X$Y$Z$


scala> X.Y.Z.getClass().getCanonicalName()

java.lang.InternalError: Malformed class name

at java.lang.Class.getSimpleName(Class.java:1330)

at java.lang.Class.getCanonicalName(Class.java:1399)

at java.lang.Class.getCanonicalName(Class.java:1396)

at java.lang.Class.getCanonicalName(Class.java:1396)

What happens here: there's a three-level enclosure. Class.getSimpleName() builds the compound name by appending the name of an enclosed class to the name of enclosing class, separated by '.', and checks that we had a separator '$'. When we have "X$Y$Z$", the first component is "X", the second comes as "$Y$", and the third comes as "Z$" - kaboom, no dollars, no service:

if (length < 1 || simpleName.charAt(0) != '$')
throw new InternalError("Malformed class name");
The bug is in Class file, but well...

Thanks,
-Vlad

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: I wonder if this is a known Java bug (Java 8 on Mac)

Roland Kuhn
While I cannot comment on whose bug it is I can tell you that this has been like that for ages. It is a clash of name mangling schemes between Java and Scala. My personal strategy is to never use getSimpleName, ever.

Regards, Roland 

Sent from my iPhone

On 11 Mar 2017, at 08:24, Vlad Patryshev <[hidden email]> wrote:

scala> object X { object Y { object Z }}

defined module X

scala> X.Y.Z.getClass()

res0: Class[_ <: X.Y.Z.type] = class X$Y$Z$


scala> X.Y.Z.getClass().getCanonicalName()

java.lang.InternalError: Malformed class name

at java.lang.Class.getSimpleName(Class.java:1330)

at java.lang.Class.getCanonicalName(Class.java:1399)

at java.lang.Class.getCanonicalName(Class.java:1396)

at java.lang.Class.getCanonicalName(Class.java:1396)

What happens here: there's a three-level enclosure. Class.getSimpleName() builds the compound name by appending the name of an enclosed class to the name of enclosing class, separated by '.', and checks that we had a separator '$'. When we have "X$Y$Z$", the first component is "X", the second comes as "$Y$", and the third comes as "Z$" - kaboom, no dollars, no service:

if (length < 1 || simpleName.charAt(0) != '$')
throw new InternalError("Malformed class name");
The bug is in Class file, but well...

Thanks,
-Vlad

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: I wonder if this is a known Java bug (Java 8 on Mac)

Jason Zaugg

On Sat, 11 Mar 2017 at 18:25, Roland Kuhn <[hidden email]> wrote:
While I cannot comment on whose bug it is I can tell you that this has been like that for ages. It is a clash of name mangling schemes between Java and Scala. My personal strategy is to never use getSimpleName, ever.

Java 9 will include a fix. Fixing it on our side would have required big changes to name mangling that would have risked regression elaewhere

Jason


--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: I wonder if this is a known Java bug (Java 8 on Mac)

Vlad Patryshev
In reply to this post by Roland Kuhn
Yes; the problem is, it's jmh that does it. Ok, so it's a known feature. Will figure out something.

Thanks,
-Vlad

On Sat, Mar 11, 2017 at 12:25 AM, Roland Kuhn <[hidden email]> wrote:
While I cannot comment on whose bug it is I can tell you that this has been like that for ages. It is a clash of name mangling schemes between Java and Scala. My personal strategy is to never use getSimpleName, ever.

Regards, Roland 

Sent from my iPhone

On 11 Mar 2017, at 08:24, Vlad Patryshev <[hidden email]> wrote:

scala> object X { object Y { object Z }}

defined module X

scala> X.Y.Z.getClass()

res0: Class[_ <: X.Y.Z.type] = class X$Y$Z$


scala> X.Y.Z.getClass().getCanonicalName()

java.lang.InternalError: Malformed class name

at java.lang.Class.getSimpleName(Class.java:1330)

at java.lang.Class.getCanonicalName(Class.java:1399)

at java.lang.Class.getCanonicalName(Class.java:1396)

at java.lang.Class.getCanonicalName(Class.java:1396)

What happens here: there's a three-level enclosure. Class.getSimpleName() builds the compound name by appending the name of an enclosed class to the name of enclosing class, separated by '.', and checks that we had a separator '$'. When we have "X$Y$Z$", the first component is "X", the second comes as "$Y$", and the third comes as "Z$" - kaboom, no dollars, no service:

if (length < 1 || simpleName.charAt(0) != '$')
throw new InternalError("Malformed class name");
The bug is in Class file, but well...

Thanks,
-Vlad

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.