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

Java client throws a NPE when the BatchWrite class is initialised with Operation array with null value #397

Closed
zsfVishnu opened this issue Jan 29, 2025 · 4 comments

Comments

@zsfVishnu
Copy link

  • When the BatchWrite instance was created with an array of Operation type but with null values. Example :
Operation[] ops1 = new Operation[3];
ops1[0] = Operation.put(new Bin(BinName4, 100));
ops1[1] = ExpOperation.read(ResultName1, rexp1, ExpReadFlags.DEFAULT);
  • In this case, the 3 element in the array would be null . The BatchWrite class internally tries to access all the elements of the array as
for (Operation op : ops) {
			if (op.type.isWrite) {
				hasWrite = true;
			}
			size += Buffer.estimateSizeUtf8(op.binName) + Command.OPERATION_HEADER_SIZE;
			size += op.value.estimateSize();
		}
  • This would cause a crash.
  • Adding individual checks doesn't seem helpful since the same array might be passed down to other classes like BatchAttr, hence filtering at constructor level seems to make sense .
@zsfVishnu
Copy link
Author

Let me know if these 2 PRs looks good to be merged (latest master jdk21 and jdk 8 )
: #395
: #396

@shrutiverma29
Copy link

shrutiverma29 commented Jan 29, 2025

The same issue can happen on BatchRead as well. Made similar changes for that class as well.
#398
#399

@BrianNichols
Copy link
Member

If one of the operations in the array is null, a null pointer exception is generated which is not a crash. This is the intended behavior.

The pull request silently reduces the operations array size if there is a null operation. This will cause errors when the user code retrieves results for each operation because the expected offset in the results may now be different.

@zsfVishnu zsfVishnu changed the title Java client crashes when the BatchWrite class is initialised with Operation array with null value Java client throws a NPE when the BatchWrite class is initialised with Operation array with null value Jan 29, 2025
@zsfVishnu
Copy link
Author

Ok, thanks for the explanation @BrianNichols .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants