Stackoverflowerror when fetching object by Id - ANDROID

Hi, i am having a feature in my application where i need to fetch an object and update its property. I am having the id of the object so i am trying to fetch the object by id. But it has been a nightmare, i don’t know what i am doing wrong here, i get the following exception:

E/AndroidRuntime: FATAL EXCEPTION: pool-7-thread-3
 Process: com.beyondseek.ServicesAroundMe, PID: 18732
 java.lang.StackOverflowError: stack size 1036KB
 at java.util.HashMap.newEntryIterator(HashMap.java:890)
 at java.util.HashMap$EntrySet.iterator(HashMap.java:935)
 at java.util.AbstractMap.hashCode(AbstractMap.java:309)
 at com.backendless.geo.GeoPoint.hashCode(GeoPoint.java:192)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at com.backendless.geo.GeoPoint.hashCode(GeoPoint.java:192)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at com.backendless.geo.GeoPoint.hashCode(GeoPoint.java:192)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at com.backendless.geo.GeoPoint.hashCode(GeoPoint.java:192)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at com.backendless.geo.GeoPoint.hashCode(GeoPoint.java:192)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at com.backendless.geo.GeoPoint.hashCode(GeoPoint.java:192)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at com.backendless.geo.GeoPoint.hashCode(GeoPoint.java:192)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at com.backendless.geo.GeoPoint.hashCode(GeoPoint.java:192)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at com.backendless.geo.GeoPoint.hashCode(GeoPoint.java:192)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at com.backendless.geo.GeoPoint.hashCode(GeoPoint.java:192)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at com.backendless.geo.GeoPoint.hashCode(GeoPoint.java:192)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at com.backendless.geo.GeoPoint.hashCode(GeoPoint.java:192)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(AbstractMap.java:311)
 at com.backendless.geo.GeoPoint.hashCode(GeoPoint.java:192)
 at java.util.HashMap$HashMapEntry.hashCode(HashMap.java:755)
 at java.util.AbstractMap.hashCode(Abstrac

After this i get the following exception:



E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!
 E/AndroidRuntime: Error reporting crash
 android.os.TransactionTooLargeException
 at android.os.BinderProxy.transactNative(Native Method)
 at android.os.BinderProxy.transact(Binder.java:496)
 at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:4200)
 at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:89)
 at com.crashlytics.android.core.CrashlyticsUncaughtExceptionHandler.uncaughtException(CrashlyticsUncaughtExceptionHandler.java:249)
 at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
 at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)

Here is the code snippet responsible for this:

//The crash happens as soon as control reaches line #2, the application closes and i get those exceptions..
Backendless.Data.of(ServiceProviders.class).findById("The object ID", new AsyncCallback<ServiceProviders>() {


 @Override
 public void handleResponse(ServiceProviders response) {
 //Ok fetched the object


 }


 @Override
 public void handleFault(BackendlessFault fault) {
 //There was some issue..
 }
});

I’ve spent hours trying alternative methods, but it doesn’t work. Somebody please tell what i am doing wrong here! Thank you.

Really high priority, somebody please help!

Hi Basanth,

Could you please provide your appId, table and id of record you try to find by id.

Regards,

Denys

Hi Denys,

Table: ServiceProviders

Here is the App ID: B4847C1C-5B14-8716-FF77-224A0BB3EA00

One of the Objects’ ID that i tried accessing: 27B48010-A210-E88E-FF27-5D476D29DD00

Thank you,
Basanth

Hi Basanth,

What version of SDK do you use? I cannot reproduce this issue with latest SDK.
Please, also chaeck you do not call toString() method of this object because it has cyclic relations.

Regards,

Denys

Hi Denys,

I am using version 3.011, here is what i’ve used in build.gradle
compile ‘com.backendless:backendless:3.0.11’

And i believe i am not calling toString() method, here is my class:

 public class ServiceProviders {
    private String name;
    private String contactNumber;
    private String description;
    private Boolean approved;
    private Boolean unpublished;
    private String objectId;
    private String serviceName;
    private String imageUrl;
    private String serviceCost;
    private String serviceTime;
    private GeoPoint geoLocation;
    private  String category;

    public Boolean getUnpublished() {
        return unpublished;
    }

    public void setUnpublished(Boolean unpublished) {
        this.unpublished = unpublished;
    }


    public String getContactNumber() {
        return contactNumber;
    }

    public void setContactNumber(String contactNumber) {
        this.contactNumber = contactNumber;
    }

    public String getObjectId() {
        return objectId;
    }

    public void setObjectId(String objectId) {
        this.objectId = objectId;
    }

    public Boolean getApproved() {
        return approved;
    }

    public void setApproved(Boolean approved) {
        this.approved = approved;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getName()
    {
        return name;
    }

    public void setName( String name )
    {
        this.name = name;
    }

    public String getServiceName() {
        return serviceName;
    }

    public void setServiceName(String serviceName) {
        this.serviceName = serviceName;
    }

    public static ServiceProviders findById(String id) {
        return Backendless.Data.of(ServiceProviders.class).findById(id);
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public void setImageUrl(String imageUrl) {
        this.imageUrl = imageUrl;
    }

    public GeoPoint getGeoLocation() {
        return geoLocation;
    }

    public void setGeoLocation(GeoPoint geoLocation) {
        this.geoLocation = geoLocation;
    }

    public String getServiceCost() {
        return serviceCost;
    }

    public void setServiceCost(String serviceCost) {
        this.serviceCost = serviceCost;
    }

    public String getServiceTime() {
        return serviceTime;
    }

    public void setServiceTime(String serviceTime) {
        this.serviceTime = serviceTime;
    }
}

The geoLocation object here is a relationship, am i doing something wrong with it?

Please try using the latest SDK, which is 3.0.20.1

Hi Sergey,

I Got this with the latest SDK as well.

I found another log message which i’ve updated in the Question, but still this one is a Stackoverflowerror.

Couldn’t add it in the question, here is the log:

com.beyondseek.ServicesAroundMe D/Error: ERR: TOTAL BYTES WRITTEN: 764360

Digging deeper in the GeoPoint class, i debugged the possible reason. I put a breakpoint in the code, and found this inside GeoPoint class:

Method threw 'java.lang.StackOverflowError' exception. Cannot evaluate com.backendless.geo.GeoPoint.toString()

I got this by printing the metadata variable that was in line #169 of GeoPoint class. The metadata had 19 values, as in my Table ServiceProviders. The 14th value was the GeoPoint object called geoLocation. The value field had the exception that i’ve mentioned above. Although i can see the proper latitude and longitude values, not sure from where “toString()” is being called and causing the stackoverflow.

When you debug, .toString() is called internally in order to show you the object’s state.

Do you have cyclic relations in your object?

Ok, i guess i am creating a cyclic relation when i am adding the ServiceProvider object,

//Here is where i am adding the geoPoint to the geoLocation column.
serviceProvider.setGeoLocation(geoPoint);
//And here is where i am adding the serviceProvider object as meta data to 
the same geoPoint object
geoPoint.addMetadata("ServiceProviders", serviceProvider);

So is this a cyclic relation? (Pardon me, i do not know much about it). and should i
be removing the metadata that i am adding?

I’ve removed the metadata from Geopoint, which was causing the cyclic relationship and it works fine now.

The problem was with the creation of the Service Provider object:

//Here is where i am adding the geoPoint to the geoLocation column.
serviceProvider.setGeoLocation(geoPoint);
//And here is where i am adding the serviceProvider object as meta data to
the same geoPoint object, and thus creating a cyclic relationship.
geoPoint.addMetadata("ServiceProviders", serviceProvider);