appml / google-diff-match-patch

Automatically exported from code.google.com/p/google-diff-match-patch
Apache License 2.0
0 stars 0 forks source link

Null-safe diff #27

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
diff_main accepts two Strings as arguments. When one of them is null, diff_main 
fails with a NullPointerException.

How about making it null-pointer safe, like the apache-commons StringUtils?

Patch is attached

Original issue reported on code.google.com by Sven.Lil...@gmail.com on 10 Jun 2010 at 7:39

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by neil.fra...@gmail.com on 10 Jun 2010 at 11:47

GoogleCodeExporter commented 8 years ago
After reviewing this issue internally we came to the decision that the opposite 
behaviour is preferable.  Passing a null could be the result of an error 
somewhere upstream, so it is safer to throw an error immediately than to 
quietly interpret the null as an empty string.  Accordingly all versions of DMP 
have been changed to throw an error if null is passed to any of the three main 
functions: diff_main, match_main and patch_make.

Previously, some languages (e.g. C++) would automatically do the null to string 
conversion, whereas others (e.g. Java) would throw an error at some random call 
deep within the code.  Now all languages throw an error immediately.

I'm sorry this isn't the behaviour you had asked for.  But we do think the 
resulting safety is worth the two-line wrapper you'll need to replace nulls 
with empty strings before calling DMP.

Original comment by neil.fra...@gmail.com on 21 Jun 2010 at 9:59