Inconsistent uploading of objects with dynamic schema creation

I’m uploading some 19 objects to Backendless. Sometimes all 19 get uploaded without any errors. With no changes in code, there are times when 1 to 6 of the uploads fail with the following error message: Server.Processing: java.lang.RuntimeException: java.lang.NullPointerException

Between each run i go into Backendless console and delete the object’s table and i recompile/restart my app.

Any thoughts on what i’m doing wrong? I’m working on an Android app with Android Studio.

This is my code:

int count = 0;
for (ListAttributes attribute : listOfAttributes) {
ListAttributes.saveAsync(attribute);
count++;
}
public static void saveAsync(final ListAttributes attributes) {
// save object asynchronously
Backendless.Persistence.save(attributes, new AsyncCallback<ListAttributes>() {
public void handleResponse(ListAttributes response) {
// new Contact instance has been saved
MyLog.i(“ListAttributes”, "saveAsync(): saved - " + response.getName());
}

    public void handleFault(BackendlessFault fault) {
        // an error has occurred, the error code can be retrieved with fault.
        MyLog.e("ListAttributes", "handleFault(): BackendlessFault: ListAttributesName: " + attributes.getName()
                + " code: " + fault.getCode() + ": " + fault.getMessage());
    }
});

}

Hello Backendless … i see that my question has been marked as “Known”. What does this mean? Is there an issue with the Backendless server implementation? Or am i making an error on my android client code?

I find it strange that with no code changes that sometimes when i upload objects to Backendless they all get uploaded, while other times i receive a “Server.Processing: java.lang.RuntimeException: java.lang.NullPointerException” error. Which suggest to me a problem on the Backendless server.

Thanks for your help.

Hi Loren!
This behavior (NullPointerException) looks rather strange. We will try to reproduce this issue on our side.
Regards,
Kate.

Hi Loren,

The “Known” status is assigned by default by the support software. As for the NPE, it is what Kate wrote - we will work on reproducing the problem.

Regards,
Mark

Do you happen to have a stack trace of the exception?

Sorry … captured the fault.getMessage() as shown in the code below:

public void handleFault(BackendlessFault fault) {
// an error has occurred, the error code can be retrieved with fault.
MyLog.e(“ListAttributes”, "handleFault(): BackendlessFault: ListAttributesName: " + attributes.getName()

  • " code: " + fault.getCode() + ": " + fault.getMessage());
    }

Is there a stack trace? Or at least a more detailed log output?

I’m running my app now, and continue to get the Server.Processing: java.lang.RuntimeException: java.lang.NullPointerException error. Is there a way you watch what’s going on from your end?

Regarding the stack trace … I don’t see any ability to get a stacktrace from the Backendless BackendlessFault class.

Here is the error message that i just got. It includes fault.getCode(), fault.getMessage(), and fault.getDetail().

02-11 23:01:41.348 563-563/
code:
message: Server.Processing: java.lang.RuntimeException: java.lang.NullPointerException
Detail: null

Could you show what the ListAttributes class looks like?

Here you go … Note out of the 19 objects that i’m trying to upload … usually 12 to 15 succeed. Sometimes all succeed. I don’t see any pattern to why one succeeds and one fails … they are different on each run.

package lbconsulting.com.backendlesstest1.database;

import android.content.Context;

import com.backendless.Backendless;
import com.backendless.BackendlessCollection;
import com.backendless.async.callback.AsyncCallback;
import com.backendless.exceptions.BackendlessException;
import com.backendless.exceptions.BackendlessFault;
import com.backendless.persistence.BackendlessDataQuery;
import com.backendless.persistence.QueryOptions;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import lbconsulting.com.backendlesstest1.classes.CommonMethods;
import lbconsulting.com.backendlesstest1.classes.MyLog;

/**

  • Backendless object for an A1List Attributes.
    */

public class ListAttributes {

private String objectId;
private String name;
private int startColor; // int
private int endColor;
private int textColor; // int
private float textSize; //float
private float horizontalPaddingInDp; //float dp. Need to convert to float px
private float verticalPaddingInDp; //float dp. Need to convert to float px
private boolean dirty;
private boolean bold;
private boolean checked;
private boolean defaultAttributes;
private boolean markedForDeletion;
private boolean transparent;
private String uuid;
private Date updated;
private Date created;

private static final int PAGE_SIZE = 99;

public ListAttributes() {
    // A default constructor is required.
}


//region Getters and Setters

public int getEndColor() {
    return endColor;
}

public void setEndColor(int endColor) {
    setDirty(true);
    this.endColor = endColor;
}

public float getHorizontalPaddingInDp() {
    return horizontalPaddingInDp;
}

public void setHorizontalPaddingInDp(float horizontalPaddingInDp) {
    setDirty(true);
    this.horizontalPaddingInDp = horizontalPaddingInDp;
}

public boolean isDirty() {
    return dirty;
}

public void setDirty(boolean isAttributesDirty) {
    this.dirty = isAttributesDirty;
}

public boolean isBold() {
    return bold;
}

public void setBold(boolean isBold) {
    setDirty(true);
    this.bold = isBold;
}

public boolean isChecked() {
    return checked;
}

public void setChecked(boolean isChecked) {
    setDirty(true);
    this.checked = isChecked;
}

public boolean isDefaultAttributes() {
    return defaultAttributes;
}

public void setDefaultAttributes(boolean isDefaultAttributes) {
    setDirty(true);
    this.defaultAttributes = isDefaultAttributes;
}

public boolean isMarkedForDeletion() {
    return markedForDeletion;
}

public void setMarkedForDeletion(boolean isMarkedForDeletion) {
    setDirty(true);
    this.markedForDeletion = isMarkedForDeletion;
}

public boolean isTransparent() {
    return transparent;
}

public void setTransparent(boolean isTransparent) {
    setDirty(true);
    this.transparent = isTransparent;
}

public String getName() {
    return name;
}

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

public String getObjectId() {
    return objectId;
}

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

public int getStartColor() {
    return startColor;
}

public void setStartColor(int startColor) {
    setDirty(true);
    this.startColor = startColor;
}

public int getTextColor() {
    return textColor;
}

public void setTextColor(int textColor) {
    setDirty(true);
    this.textColor = textColor;
}

public float getTextSize() {
    return textSize;
}

public void setTextSize(float textSize) {
    setDirty(true);
    this.textSize = textSize;
}

public String getUuid() {
    return uuid;
}

public void setUuid(String uuid) {
    setDirty(true);
    this.uuid = uuid;
}

public float getVerticalPaddingInDp() {
    return verticalPaddingInDp;
}

public void setVerticalPaddingInDp(float verticalPaddingInDp) {
    setDirty(true);
    this.verticalPaddingInDp = verticalPaddingInDp;
}

public Date getUpdated() {
    return updated;
}

public void setUpdated(Date updated) {
    this.updated = updated;
}

public Date getCreated() {
    return created;
}

public void setCreated(Date created) {
    this.created = created;
}

@Override
public String toString() {
    return getName();
}


//endregion

public static ListAttributes newInstance(String newAttributesName,
                                         int startColor, int endColor,
                                         int textColor, float textSize,
                                         float horizontalPaddingInDp, float verticalPaddingInDp,
                                         boolean isBold, boolean isTransparent, boolean isDefaultAttributes) {

    ListAttributes newAttributes = new ListAttributes();
    newAttributes.setName(newAttributesName);
    newAttributes.setStartColor(startColor);
    newAttributes.setEndColor(endColor);
    newAttributes.setTextColor(textColor);
    newAttributes.setTextSize(textSize);
    newAttributes.setHorizontalPaddingInDp(horizontalPaddingInDp);
    newAttributes.setVerticalPaddingInDp(verticalPaddingInDp);
    newAttributes.setBold(isBold);
    newAttributes.setChecked(false);
    newAttributes.setDefaultAttributes(isDefaultAttributes);
    newAttributes.setMarkedForDeletion(false);
    newAttributes.setTransparent(isTransparent);
    String newUuid = UUID.randomUUID().toString();
    // replace uuid "-" with "_" to distinguish it from Backendless objectId
    newUuid = newUuid.replace("-", "_");
    newAttributes.setUuid(newUuid);

    return newAttributes;
}



//    private static boolean mFirstResponse;

// private static CountDownLatch latch ;

private static int index = 0;

public static ListAttributes getDefaultAttributes() {

// List<ListAttributes> listOfAttributes = getListOfAttributes();
// TODO: implement getDefaultAttributes
ListAttributes attributes = getListOfAttributes().get(index);
index++;
if (index == getListOfAttributes().size()) {
index = 0;
}
return attributes;

}

private static List&lt;ListAttributes&gt; mListOfAttributes;

public static List&lt;ListAttributes&gt; getListOfAttributes() {
    return mListOfAttributes;
}

public static void getAllAttributesFromBackendlessAsync(final Context context) {
    mListOfAttributes = new ArrayList&lt;&gt;();

// long startTime = System.currentTimeMillis();

    final AsyncCallback&lt;BackendlessCollection&lt;ListAttributes&gt;> callback = new AsyncCallback&lt;BackendlessCollection&lt;ListAttributes&gt;>() {
        @Override
        public void handleResponse(BackendlessCollection&lt;ListAttributes&gt; foundAttributes) {

            List&lt;ListAttributes&gt; listOfAttributes = foundAttributes.getData();
            mListOfAttributes.addAll(listOfAttributes);
            int size = foundAttributes.getCurrentPage().size();
            MyLog.i("ListAttributes", "getAllListTitlesFromBackendlessAsync(): Loaded " + size + " attributes in the current page");

            if (size > 0) {
                foundAttributes.nextPage(this);
            } else {
                // all done
                String msg = "All attributes retrieved. Total number of attributes = " + mListOfAttributes.size();
                MyLog.i("ListAttributes", "getAllListTitlesFromBackendlessAsync(): " + msg);
                CommonMethods.showOkDialog(context, "All Attributes", msg);

// latch.countDown();
}
// TODO: 2/9/2016 Replace all attributes in the SQLite database
}

        @Override
        public void handleFault(BackendlessFault fault) {
            // an error has occurred, the error code can be retrieved with fault.getCode()
            MyLog.e("ListAttributes", "getAllAttributesFromBackendlessAsync(): BackendlessFault: code: "
                    + fault.getCode() + ": " + fault.getMessage());
        }
    };
    BackendlessDataQuery dataQuery = new BackendlessDataQuery();
    dataQuery.setPageSize(PAGE_SIZE);
    QueryOptions queryOptions = new QueryOptions();
    queryOptions.addSortByOption("nameLowercase ASC");
    dataQuery.setQueryOptions(queryOptions);
    Backendless.Data.of(ListAttributes.class).find(dataQuery, callback);
}

}

Thanks, Loren. Where do these objects in question come from?

Here’s the source of the data … just hard coded. [Note: I’ve refactored the name ListAttributes to ListTheme. The data structure has not changed.]

private void uploadTestAttributes() {
if (!CommonMethods.isNetworkAvailable()) {
showOkDialog(this, “Network Not Available”, “Unable to upload attributes”);
return;
}
long startTime = System.currentTimeMillis();
ArrayList<ListTheme> listOfAttributes = new ArrayList<>();

ListThemeRepositoryImpl listAttributesRepositoryImpl = new ListThemeRepositoryImpl(this);

ListTheme attributes;

attributes = ListTheme.newInstance("Genoa",
        Color.parseColor("#4c898e"), Color.parseColor("#125156"),
        ContextCompat.getColor(this, R.color.white),
        17f, 10f, 10f, false, false, true);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);

attributes = ListTheme.newInstance("Opal",
        Color.parseColor("#cbdcd4"), Color.parseColor("#91a69d"),
        ContextCompat.getColor(this, R.color.black),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);


attributes = ListTheme.newInstance("Shades of Blue",
        -5777934, -10841921,
        ContextCompat.getColor(this, R.color.black),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);


attributes = ListTheme.newInstance("Off White",
        ContextCompat.getColor(this, R.color.white), -2436147,
        ContextCompat.getColor(this, R.color.black),
        17f, 10f, 10f, false, true, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);


attributes = ListTheme.newInstance("Whiskey",
        Color.parseColor("#e9ac6d"), Color.parseColor("#ad7940"),
        ContextCompat.getColor(this, R.color.white),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);


attributes = ListTheme.newInstance("Shakespeare",
        Color.parseColor("#73c5d3"), Color.parseColor("#308d9e"),
        ContextCompat.getColor(this, R.color.white),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);


attributes = ListTheme.newInstance("Sorbus",
        Color.parseColor("#f0725b"), Color.parseColor("#bc3c21"),
        ContextCompat.getColor(this, R.color.white),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);


attributes = ListTheme.newInstance("Dark Khaki",
        Color.parseColor("#ced285"), Color.parseColor("#9b9f55"),
        ContextCompat.getColor(this, R.color.white),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);


attributes = ListTheme.newInstance("Lemon Chiffon",
        Color.parseColor("#fdfcdd"), Color.parseColor("#e3e2ac"),
        ContextCompat.getColor(this, R.color.black),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);


attributes = ListTheme.newInstance("Paprika",
        Color.parseColor("#994552"), Color.parseColor("#5f0c16"),
        ContextCompat.getColor(this, R.color.white),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);


attributes = ListTheme.newInstance("Medium Wood",
        Color.parseColor("#bfaa75"), Color.parseColor("#8a7246"),
        ContextCompat.getColor(this, R.color.white),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);


attributes = ListTheme.newInstance("Breaker Bay",
        Color.parseColor("#6d8b93"), Color.parseColor("#31535c"),
        ContextCompat.getColor(this, R.color.white),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);


attributes = ListTheme.newInstance("Sandrift",
        Color.parseColor("#cbb59d"), Color.parseColor("#92806c"),
        ContextCompat.getColor(this, R.color.white),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);


attributes = ListTheme.newInstance("Pale Brown",
        Color.parseColor("#ac956c"), Color.parseColor("#705c39"),
        ContextCompat.getColor(this, R.color.white),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);


attributes = ListTheme.newInstance("Seagull",
        Color.parseColor("#94dcea"), Color.parseColor("#4ea0ab"),
        ContextCompat.getColor(this, R.color.black),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);


attributes = ListTheme.newInstance("Beige",
        Color.parseColor("#fefefe"), Color.parseColor("#d3d8c2"),
        ContextCompat.getColor(this, R.color.black),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);

attributes = ListTheme.newInstance("Orange",
        Color.parseColor("#ff6c52"), Color.parseColor("#e0341e"),
        ContextCompat.getColor(this, R.color.white),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);

attributes = ListTheme.newInstance("Arsenic",
        Color.parseColor("#545c67"), Color.parseColor("#1d242c"),
        ContextCompat.getColor(this, R.color.white),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);

attributes = ListTheme.newInstance("Acapulco",
        Color.parseColor("#8dbab3"), Color.parseColor("#58857e"),
        ContextCompat.getColor(this, R.color.white),
        17f, 10f, 10f, false, false, false);
listOfAttributes.add(attributes);
// ListTheme.saveToBackendlessAsync(attributes);

int count = 0;
//Server.Processing: java.lang.RuntimeException: java.lang.NullPointerException
for (ListTheme attribute : listOfAttributes) {
    listAttributesRepositoryImpl.insert(attribute);;
    count++;
}

long endTime = System.currentTimeMillis();
long duration = endTime - startTime;
String resultMessage = "Requested " + listOfAttributes.size() + " Attributes asyncSave to Backendless.";
MyLog.i("uploadTestAttributes", resultMessage);
showOkDialog(this, "Saved Attributes", resultMessage);

}

Could you also attach the ListThemeRepositoryImpl class? I’d like the code to be as close as possible to yours so we can reproduce the problem.

Regards,
Mark

Hi Loren,

Could you please help us and provide some minimal part of code, which would reproduce the behaviour you describe?

Thanks in advance!

It would also help if you could debug on which exact objects the save operation fails (I suppose it is related to the properties values they contain).

Sorry for being slow in replying to your questions. When i was doing the above work i was traveling using my laptop. I’m now back home using my desktop machine. With out any changes to my code, I am now unable to recreate this error. Very strange.

Could this error (Server.Processing: java.lang.RuntimeException: java.lang.NullPointerException) be produced by some kind of Internet communication error? Instead of an error in my code?

Thanks again for prompt responses. It is much appreciated.

Loren,

Without knowing the specifics leading to this error: “Server.Processing: java.lang.RuntimeException: java.lang.NullPointerException”, it would be very hard to say what might be causing it.

Mark