Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type argument of class scala.Int is resolved to java.lang.Object when discovering type arguments using Java reflection #4948

Closed
scabug opened this issue Aug 29, 2011 · 7 comments
Assignees

Comments

@scabug
Copy link

scabug commented Aug 29, 2011

We're using a legacy infrastructure for data conversion based on the Dozer project, for which we wrote some scala-specific adapters. Everything works properly except for fields that are generic on scala.Int, such as Option[Int] or List[Int]. After some research it appears that the Java reflection system fails to discover the type argument for Option[Int], whereas it succeeds in doing so for Option[String].

Please see the attached file which reproduces the issue.

@scabug
Copy link
Author

scabug commented Aug 29, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4948?orig=1
Reporter: Shai Yallin (electricmonk)
Affected Versions: 2.9.0-1
Attachments:

@scabug
Copy link
Author

scabug commented Aug 29, 2011

@paulp said:
Duplicate of several other tickets.

@scabug scabug closed this as completed Aug 29, 2011
@scabug
Copy link
Author

scabug commented Aug 29, 2011

Shai Yallin (electricmonk) said:
Can you please link this issue to any of the duplicates so that I can add a watch on it?

@scabug
Copy link
Author

scabug commented Aug 29, 2011

@paulp said:
First, can you enumerate the searches you issued before opening this ticket, the results of which must have omitted the existing ones. I need this information to improve the search facility, because I lose far too much time to duplicate, not-a-bug, and documented-wontfix tickets.

@scabug
Copy link
Author

scabug commented Aug 29, 2011

@SethTisue said:
I searched for "object type parameter primitive" and the #1 hit was #4403 which is linked to #4214 which iirc is the main relevant ticket here.

@scabug
Copy link
Author

scabug commented Aug 30, 2011

Shai Yallin (electricmonk) said (edited on Aug 30, 2011 5:40:30 AM UTC):
I see the relation to #4403, although the comment by @paulp seems to indicate that there's no intention to fix this issue, which is a problem, as I see it, since the compiler generates invalid bytecode.

#4214 seems to have been resolved if you look at the comment from the original reporter, but nowhere do I see a reference to a solution that resolves the primitive generic type issue.

I've linked this issue to the "metabug" #4912, I hope to see a fix soon, and I would love to hear from @paulp why there's not much that can be done about it.

@scabug
Copy link
Author

scabug commented Aug 30, 2011

@retronym said:
Hi Shai,

It's best to consult the mailing list before raising a ticket unless you're sure that it it's a bug, and not a duplicate.

There is a conflict between the Java generics, which can only accept AnyRef type parameters, and the Scala type system, which can include AnyVals. For this reason, some information must be erased.

Here are a few threads that highlight the difficulty of the problem.

http://www.scala-lang.org/node/8888
https://groups.google.com/forum/#!topic/scala-internals/734iM8b3kGc

You're really after a Scala specific reflection API. The good news is that this is coming in Scala 2.10. In the meantime, take a look at Salat, which uses the Scala Decompiler (scalap) to extract the same information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants