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

CtTypeImpl.getAllFields may throw a SpoonClassNotFoundException #775

Closed
msteinbeck opened this issue Aug 5, 2016 · 3 comments · Fixed by #780
Closed

CtTypeImpl.getAllFields may throw a SpoonClassNotFoundException #775

msteinbeck opened this issue Aug 5, 2016 · 3 comments · Fixed by #780

Comments

@msteinbeck
Copy link
Contributor

I would like to access all fields a of CtType node with getAllFields (in NoClasspath mode). Unfortunately, this method may throw a SpoonClassNotFoundException if the accessed class derives from another class not available in classpath. The following snippet show the corresponding stack trace:

spoon.support.reflect.reference.SpoonClassNotFoundException: cannot load class: MimeMessage with class loader sun.misc.Launcher$AppClassLoader@55f96302
    at spoon.support.reflect.reference.CtTypeReferenceImpl.findClass(CtTypeReferenceImpl.java:141)
    at spoon.support.reflect.reference.CtTypeReferenceImpl.getActualClass(CtTypeReferenceImpl.java:129)
    at spoon.support.reflect.reference.CtTypeReferenceImpl.getAllFields(CtTypeReferenceImpl.java:392)
    at spoon.support.reflect.declaration.CtTypeImpl.getAllFields(CtTypeImpl.java:437)
    at spoon.support.reflect.declaration.CtTypeImpl.getAllFields(CtTypeImpl.java:62)
    at spoon.support.reflect.reference.CtTypeReferenceImpl.getAllFields(CtTypeReferenceImpl.java:394)
    at spoon.support.reflect.declaration.CtTypeImpl.getAllFields(CtTypeImpl.java:437)
    at spoon.support.reflect.declaration.CtTypeImpl.getAllFields(CtTypeImpl.java:62)

Is this behavior a bug or to be expected?

@tdurieux
Copy link
Collaborator

tdurieux commented Aug 5, 2016

The behavior of  getAllFields is:

  1. get the fields present in the CtType
  2. get the fields of the declaration of the super class
    • if the super class is in spoon AST go to 1.
    • if the super class is NOT in spoon AST, Spoon uses the reflexion to get the type then go to 1.

If the super class is not present neither the AST neither in the classloader (for the reflexion), spoon throws the exception SpoonClassNotFoundException.

This behavior is 'normal' but can be improved. But according to me, this exception must not be threw in noclasspath mode, a partial response and a warning is more appropriate.

@msteinbeck
Copy link
Contributor Author

How do I determine noclasspath mode from within spoon?

@tdurieux
Copy link
Collaborator

tdurieux commented Aug 5, 2016

if(factory.getEnvironment().getNoClasspath()) {
  // is in no classpath
}

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

Successfully merging a pull request may close this issue.

2 participants