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:
parent
01216d9779
commit
0a581ceb1e
@ -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);
|
||||
}
|
||||
`)
|
||||
|
@ -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() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
4
bind/testdata/basictypes.java.golden
vendored
4
bind/testdata/basictypes.java.golden
vendored
@ -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;
|
||||
|
4
bind/testdata/interfaces.java.golden
vendored
4
bind/testdata/interfaces.java.golden
vendored
@ -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);
|
||||
}
|
||||
}
|
||||
|
2
bind/testdata/issue12403.java.golden
vendored
2
bind/testdata/issue12403.java.golden
vendored
@ -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;
|
||||
|
4
bind/testdata/structs.java.golden
vendored
4
bind/testdata/structs.java.golden
vendored
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user