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

Add null check for BaseNCodec decodning #461

Closed
wants to merge 1 commit into from

Conversation

mipo256
Copy link

@mipo256 mipo256 commented Dec 6, 2021

Add null check for BaseNCodec decodning

Add null check for BaseNCodec decodning
@markt-asf
Copy link
Contributor

Why?

@mipo256
Copy link
Author

mipo256 commented Dec 7, 2021

Becuase this code, for example : new Base64().decode(myString) will produce NPE in case of myString is null. This is becuase of inner delegation to public byte[] decode(final byte[] pArray) method (in BaseNCodec class), which cannot handle null values.

@BlueSkyT

This comment was marked as spam.

@zhengdi1992

This comment was marked as spam.

@markt-asf
Copy link
Contributor

So don't call decode((String) null).

@gmshake
Copy link

gmshake commented Dec 7, 2021

Becuase this code, for example : new Base64().decode(myString) will produce NPE in case of myString is null. This is becuase of inner delegation to public byte[] decode(final byte[] pArray) method (in BaseNCodec class), which cannot handle null values.

It make sense to encode a empty string, but it does not make sense to encode or decode a null string.

@mipo256
Copy link
Author

mipo256 commented Dec 7, 2021

But guys, I am, as a framework user, expect that the framework will take care of this check. Do you really think I am doing the
decode((String) null) - I have a string in application, which can be null, and I, as a framework user, do not want to take care about making checks about it.

Indeed, fellows, I guess you have used Apache Commons. Take a look into its utility classes - they withdraw this boring responsibilities from the framework client.

@mipo256
Copy link
Author

mipo256 commented Dec 7, 2021

Becuase this code, for example : new Base64().decode(myString) will produce NPE in case of myString is null. This is becuase of inner delegation to public byte[] decode(final byte[] pArray) method (in BaseNCodec class), which cannot handle null values.

It make sense to encode a empty string, but it does not make sense to encode or decode a null string.

I agree with that, but it forces the client the be aware of the fact that string is not null. I am responsible to check it, as a Client - why? I genuinely do not understand the logic behind it

@markt-asf
Copy link
Contributor

  1. Please avoid use of gender specific terminology such as "guys" or "fellows" when referring to members of the Tomcat community.

  2. This code is not part of a framework. It is Tomcat's internal API. Applications should not be calling this code.

The logic behind the current design is simple: Tomcat never calls that method with null so a null check is unnecessary.

@mipo256
Copy link
Author

mipo256 commented Dec 7, 2021

Ok, I am sorry, I will reference you directly :) I disagree with you, @markt-asf. The class Base64 is used directly by the clients. Just a couple of examples: this, and this, also this and e.t.c.) - and, as I already mentioned, Base64 delegates to BaseNCodec, which does not tolerate null.

@markt-asf I really do not understand why it is so hard to apply this minor, non-breaking change :) As I mentioned above, people are using this API in thier code (it is public b.t.w), so why not make their life easier?)

@markt-asf
Copy link
Contributor

All those references you provided are for org.apache.commons.codec.binary.BaseNCodec not org.apache.tomcat.util.codec.binary.BaseNCodec

That the class is public is irrelevant. It has to be public as it is a utility class used by various Tomcat packages. Tomcat's public API is documented in the RELEASE-NOTES.

The change won't be applied because it isn't necessary and there is no desire to add unnecessary code bloat to Tomcat.

It your application wants to use Commons Codec then it should package it in WEB-INF/lib.

@mipo256
Copy link
Author

mipo256 commented Dec 7, 2021

Ok, that make sence. I will use the public API

@mipo256 mipo256 closed this Dec 7, 2021
@ChristopherSchultz
Copy link
Contributor

@mikhail2048 Your patch also doesn't even compile, so it wouldn't have been accepted, anyway.

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