Skip to content

NullPointerException during encoding when creating a transaction with null data #2236

@furkilic

Description

@furkilic

NullPointerException during encoding when creating a transaction with null data

We are creating a RawTransaction.createTransaction with data = null (data is nullable for a transaction)

Looking at the code data is nullable as null is handled here

this.data = data != null ? Numeric.cleanHexPrefix(data) : null;

However during encoding TransactionEncoder.encode we reach this code where nullsafety is not handled

byte[] data = Numeric.hexStringToByteArray(getData());

Internally Numeric.hexStringToByteArray(getData()) throws a NullPointerException as data is null

Steps To Reproduce

TransactionEncoder.encode(
  RawTransaction.createTransaction(
    BigInteger.ONE,BigInteger.ONE,BigInteger.ONE,"0x0", null
  )
)

Expected behavior

Encoded Transaction returned

Actual behavior

NullPointerException

Environment

  • Web3j 4.12.2 (still present in main)

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA bug in behaviour or functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions