2
0
mirror of synced 2025-02-23 06:48:15 +00:00

bind/java: do not return null String for empty Go string

Fixes golang/go#13430

Change-Id: Ic018761af6a40f6b04ec4449110f54af8f543a53
Reviewed-on: https://go-review.googlesource.com/17273
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Hyang-Ah Hana Kim 2015-12-01 14:26:32 -05:00
parent 01216d9779
commit 0a581ceb1e
7 changed files with 16 additions and 9 deletions

View File

@ -530,7 +530,7 @@ func (g *javaGen) genFunc(o *types.Func, method bool) {
}
if returnsError {
g.Printf(`String _err = _out.readString();
if (_err != null) {
if (_err != null && !_err.isEmpty()) {
throw new Exception(_err);
}
`)

View File

@ -81,6 +81,13 @@ public class SeqTest extends AndroidTestCase {
String want = "a short string";
String got = Testpkg.StrDup(want);
assertEquals("Strings should match", want, got);
want = "";
got = Testpkg.StrDup(want);
assertEquals("Strings should match (empty string)", want, got);
got = Testpkg.StrDup(null);
assertEquals("Strings should match (null string)", want, got);
}
public void testLongString() {

View File

@ -282,7 +282,7 @@ JNIEXPORT jstring JNICALL
Java_go_Seq_readUTF16(JNIEnv *env, jobject obj) {
int32_t size = *MEM_READ(obj, int32_t);
if (size == 0) {
return NULL;
return (*env)->NewString(env, NULL, 0);
}
return (*env)->NewString(env, (jchar*)mem_read(env, obj, 2*size, 1), size);
}

View File

@ -40,7 +40,7 @@ public abstract class Basictypes {
go.Seq _out = new go.Seq();
Seq.send(DESCRIPTOR, CALL_Error, _in, _out);
String _err = _out.readString();
if (_err != null) {
if (_err != null && !_err.isEmpty()) {
throw new Exception(_err);
}
}
@ -52,7 +52,7 @@ public abstract class Basictypes {
Seq.send(DESCRIPTOR, CALL_ErrorPair, _in, _out);
_result = _out.readInt();
String _err = _out.readString();
if (_err != null) {
if (_err != null && !_err.isEmpty()) {
throw new Exception(_err);
}
return _result;

View File

@ -25,7 +25,7 @@ public abstract class Interfaces {
_in.writeRef(e.ref());
Seq.send(DESCRIPTOR, CALL_CallErr, _in, _out);
String _err = _out.readString();
if (_err != null) {
if (_err != null && !_err.isEmpty()) {
throw new Exception(_err);
}
}
@ -79,7 +79,7 @@ public abstract class Interfaces {
_in.writeRef(ref);
Seq.send(DESCRIPTOR, CALL_Err, _in, _out);
String _err = _out.readString();
if (_err != null) {
if (_err != null && !_err.isEmpty()) {
throw new Exception(_err);
}
}

View File

@ -83,7 +83,7 @@ public abstract class Issue12403 {
Seq.send(DESCRIPTOR, CALL_ToJSON, _in, _out);
_result = _out.readString();
String _err = _out.readString();
if (_err != null) {
if (_err != null && !_err.isEmpty()) {
throw new Exception(_err);
}
return _result;

View File

@ -27,7 +27,7 @@ public abstract class Structs {
Seq.send(DESCRIPTOR, CALL_IdentityWithError, _in, _out);
_result = new S(_out.readRef());
String _err = _out.readString();
if (_err != null) {
if (_err != null && !_err.isEmpty()) {
throw new Exception(_err);
}
return _result;
@ -92,7 +92,7 @@ public abstract class Structs {
Seq.send(DESCRIPTOR, CALL_Identity, _in, _out);
_result = new S(_out.readRef());
String _err = _out.readString();
if (_err != null) {
if (_err != null && !_err.isEmpty()) {
throw new Exception(_err);
}
return _result;