question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ignore super class methods / Classloader issue

See original GitHub issue

Use case: POJO that extends a 3rd party base class. The base class contains a method whose return type is not available to the ClassLoader.

This seems related to: https://github.com/FasterXML/jackson-databind/pull/785/files and https://github.com/FasterXML/jackson-databind/issues/861

It doesn’t look like it is possible to ignore methods/super class methods, only fields using the AnnotationIntrospector.

Example using Realm (https://github.com/realm/realm-java):

public class Foo extends RealmObject {
  private String bar;
  public void setBar(String bar) {
    this.bar = bar;
  }
  public String getBar() {
    return bar;
  }
}

The problematic method is asObservable() in RealmObject that returns an rx.Observable. RxJava is an optional dependency, so rx.Observable might not be available to the ClassLoader: https://github.com/realm/realm-java/blob/master/realm/realm-library/src/main/java/io/realm/RealmObject.java#L278-Lundefined

The stack trace from Jackson looks something like this:

java.lang.NoClassDefFoundError: rx.Observable
at libcore.reflect.InternalNames.getClass(InternalNames.java:55)
at java.lang.Class.getDexCacheType(Class.java:479)
at java.lang.reflect.ArtMethod.getDexCacheType(ArtMethod.java:191)
at java.lang.reflect.ArtMethod.getReturnType(ArtMethod.java:145)
at java.lang.reflect.Method.getReturnType(Method.java:184)
at java.lang.Class.getDeclaredMethods(Class.java:771)
at com.fasterxml.jackson.databind.introspect.AnnotatedClass._findClassMethods(AnnotatedClass.java:1046)
at com.fasterxml.jackson.databind.introspect.AnnotatedClass._addMemberMethods(AnnotatedClass.java:602)
at com.fasterxml.jackson.databind.introspect.AnnotatedClass.resolveMemberMethods(AnnotatedClass.java:431)
at com.fasterxml.jackson.databind.introspect.AnnotatedClass.memberMethods(AnnotatedClass.java:253)
at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector._addMethods(POJOPropertiesCollector.java:477)
at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.collectAll(POJOPropertiesCollector.java:284)
at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getPropertyMap(POJOPropertiesCollector.java:248)
at com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector.getProperties(POJOPropertiesCollector.java:155)
at com.fasterxml.jackson.databind.introspect.BasicBeanDescription._properties(BasicBeanDescription.java:142)
at com.fasterxml.jackson.databind.introspect.BasicBeanDescription.findProperties(BasicBeanDescription.java:217)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._findCreatorsFromProperties(BasicDeserializerFactory.java:333)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory._constructDefaultValueInstantiator(BasicDeserializerFactory.java:315)
at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findValueInstantiator(BasicDeserializerFactory.java:254)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:222)
at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:142)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:403)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:352)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)
at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:461)
at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:3838)
at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3703)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2005)
at co.moonmonkeylabs.realmsearchview.example.MainActivity.loadBlogData(MainActivity.java:75)

Right now the only fix seems to be to create a dummy rx.Observable class that is empty, but maybe I am missing some configuration?

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:5
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

9reactions
grenniscommented, Jun 13, 2017

Just defining a dummy class as recommended isn’t enough anymore, now I also need the OnSubscribe interface like this:

package rx;

public class Observable {
    public interface OnSubscribe {
    }
}

This is making me very nervous, would love a proper fix.

3reactions
cowtowncodercommented, Oct 9, 2017

@rogerioit Feel free to go ahead and figure out potential solution if you have itch here.

No one has proposed valid solution here yet, or, the usual starting point, unit test to reproduce the issue. Without one fixes are difficult to verify. This is not a bug to fix, per se – if system tries to load a class that refers to another class not found in classpath, it is quite natural that problems occur. It would be nice to have a way to handle this gracefully but it is not clear how this should be approached. Asking for someone to solve this will not get you very far.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'Must Override a Superclass Method' Errors after importing a ...
To resolve this issue, Go to your Project properties -> Java compiler -> Select compiler compliance level to 1.6 ...
Read more >
PowerMockIgnore (powermock-core 1.6.5 API) - Javadoc.io
This annotation tells PowerMock to defer the loading of classes with the names supplied to value() to the system classloader.
Read more >
ClassLoader (Java Platform SE 8 ) - Oracle Help Center
Creates a new class loader using the specified parent class loader for delegation. If there is a security manager, its checkCreateClassLoader method is...
Read more >
Implementing Java Class Isolation Loading - Alibaba Cloud
If the version is backward compatible, the class conflict problem can be solved easily. You only need to exclude the lower version.
Read more >
ClassLoader in Java - GeeksforGeeks
If the parent class loader doesn't find the class, loadClass() calls the method findClass() to find and load the class. The findClass() method...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found