[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

byte -> char conversions in property setting code

From: Daniel Rall <dlr_at_collab.net>
Date: 2007-05-02 02:27:32 CEST

On Tue, 01 May 2007, Hyrum K. Wright wrote:

> Blair Zajac wrote:
...
> >>>> While I'm not absolutely sure what the Right Thing is here, getting
> >>>> the byte[] representation of a Java String using the JVM's default
> >>>> encoding (which unfortunately might not be UTF-8), then basically
> >>>> transforming each byte in that array into a character, is definitely
> >>>> not correct.
> >>>
> >>> To clarify: That's what we used to do.
> >>>
> >>> Now we seem to do the opposite. However, if we don't know what
> >>> encoding to create a String from using those bytes, using the JVM's
> >>> default encoding may not be correct, either.
> >>
> >> Can't we use
...
> > value.getBytes( "UTF-8" );
>
> The attached patch uses a byte array instead of a String to move the
> property values from the Java layer to the C++ layer. I have a little
> misgiving about using a ClientException, but I don't see a better way to
> implement the error handling when specifying the UTF-8 encoding.

--- subversion/bindings/javahl/native/SVNClient.cpp (revision 24864)
+++ subversion/bindings/javahl/native/SVNClient.cpp (working copy)
...
 void SVNClient::propertySet(const char *path, const char *name,
- const char *value, bool recurse, bool force)
+ JNIByteArray &value, bool recurse, bool force)
 {
     Pool requestPool;
     SVN_JNI_NULL_PTR_EX(path, "path", );
     SVN_JNI_NULL_PTR_EX(name, "name", );
- SVN_JNI_NULL_PTR_EX(value, "value", );
- svn_string_t *val = svn_string_create(value, requestPool.pool());
+ if (value.isNull())
+ {
+ JNIUtil::throwNullPointerException("value");
+ return;
+ }
+ svn_string_t *val = svn_string_ncreate((const char *)value.getBytes(),
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Is this really kosher? An element from an array of bytes from a UTF-8
string may or may not correspond to a UTF-8 character. This is
similar to what we used to be doing -- does it "just work" for some
reason?

+ value.getLength(),
+ requestPool.pool());
     propertySet(path, name, val, recurse, force, SVN_INVALID_REVNUM);
 }

  • application/pgp-signature attachment: stored
Received on Wed May 2 02:27:44 2007

This is an archived mail posted to the Subversion Dev mailing list.