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 Converter Bug Blob #1385

Closed
shainsingh89 opened this issue Jul 26, 2017 · 3 comments
Closed

Type Converter Bug Blob #1385

shainsingh89 opened this issue Jul 26, 2017 · 3 comments
Labels
Milestone

Comments

@shainsingh89
Copy link

shainsingh89 commented Jul 26, 2017

DBFlow Version: 4.0.1
Issue Kind (Bug, Question, Feature): Bug

Description: Type Converter Bug

import com.raizlabs.android.dbflow.converter.TypeConverter;
import com.raizlabs.android.dbflow.data.Blob;

@com.raizlabs.android.dbflow.annotation.TypeConverter
public class BlobConverter extends TypeConverter<Blob, byte[]> {


    @Override
    public Blob getDBValue(byte[] model) {
        return model == null ? null: new Blob(model);
    }

    @Override
    public byte[] getModelValue(Blob data) {
        return data == null ? null: data.getBlob();
    }
}
import com.raizlabs.android.dbflow.converter.TypeConverter;
import com.raizlabs.android.dbflow.data.Blob;

@com.raizlabs.android.dbflow.annotation.TypeConverter
public class BlobConverter extends TypeConverter<Blob, byte[]> {


@Override
  public final void bindToInsertStatement(DatabaseStatement statement, Conversation model,
      int start) {
    statement.bindStringOrNull(1 + start, model.getUuid());
    statement.bindStringOrNull(2 + start, model.getName());
    statement.bindLong(3 + start, model.getPhoneNo());
    statement.bindLong(4 + start, model.getStatus());
    **Blob refseed = model.getSeed() != null ? typeConverterBlobConverter.getDBValue(model.getSeed()) : null;
    statement.bindBlobOrNull(5 + start, refseed.getBlob());**
    Blob refprivateKey = model.getPrivateKey() != null ? typeConverterBlobConverter.getDBValue(model.getPrivateKey()) : null;
    statement.bindBlobOrNull(6 + start, refprivateKey.getBlob());
    Blob refpublicKey = model.getPublicKey() != null ? typeConverterBlobConverter.getDBValue(model.getPublicKey()) : null;
    statement.bindBlobOrNull(7 + start, refpublicKey.getBlob());
    statement.bindLong(8 + start, model.getKeyValidity());
  }

Here Auto generated method not checking where Blob is null or not (Check bold line)
statement.bindBlobOrNull(5 + start, refseed.getBlob());

Its giving null pointer exception when tying to save the data

    @Column( typeConverter = BlobConverter.class, name = "key_seed")
    private byte[] seed;
@agrosner agrosner added the bug label Aug 26, 2017
@agrosner
Copy link
Owner

need more info. like what your model class looks like. have you tested with 4.0.5 yet?

@danvwells
Copy link
Contributor

The pull request I just submitted I think fixes this. An alternative is to just use the dbflow Blob type in the model instead of a byte array directly (a dbflow Blob just wraps the byte array).

@agrosner agrosner added this to the 4.1.1 milestone Aug 29, 2017
@agrosner
Copy link
Owner

in develop for 4.1.1

@agrosner agrosner mentioned this issue Aug 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants