diff --git a/bind/genclasses.go b/bind/genclasses.go index 0de3f23..30f375d 100644 --- a/bind/genclasses.go +++ b/bind/genclasses.go @@ -573,9 +573,11 @@ func (g *ClassGen) genRefRead(to, from string, intfName, proxyName string, hasPr g.Printf("if %s_ref != nil {\n", to) g.Printf(" if %s < 0 { // go object\n", from) g.Printf(" %s = %s_ref.Get().(%s)\n", to, to, intfName) + g.Printf(" } else { // foreign object\n") if hasProxy { - g.Printf(" } else { // foreign object\n") g.Printf(" %s = (*%s)(%s_ref)\n", to, proxyName, to) + } else { + g.Printf(" %s = %s_ref\n", to, to) } g.Printf(" }\n") g.Printf("}\n") diff --git a/bind/java/ClassesTest.java b/bind/java/ClassesTest.java index 6193307..720fc75 100644 --- a/bind/java/ClassesTest.java +++ b/bind/java/ClassesTest.java @@ -108,6 +108,12 @@ public class ClassesTest extends InstrumentationTestCase { assertEquals("IOException message", Javapkg.IOExceptionMessage, exc.getMessage()); } + public void testUnknownType() { + GoObject o = new GoObject(); + o.toString(); // Set this + assertTrue("GoObject.getClass not null", o.checkClass()); + } + public void testInnerClass() { Character.Subset s = new Character.Subset(""){}; Character.Subset s2 = new GoSubset(""); diff --git a/bind/testpkg/javapkg/classes.go b/bind/testpkg/javapkg/classes.go index 865c0ab..834dce7 100644 --- a/bind/testpkg/javapkg/classes.go +++ b/bind/testpkg/javapkg/classes.go @@ -77,12 +77,22 @@ func (_ *GoFuture) IsDone() bool { type GoObject struct { lang.Object + this lang.Object } -func (_ *GoObject) ToString(this lang.Object) string { +func (o *GoObject) ToString(this lang.Object) string { + o.this = this return ToStringPrefix + this.Super().ToString() } +func (r *GoObject) CheckClass() bool { + // Verify that GetClass returns interface{} because java.lang.Class + // is unreferenced. + var f func() interface{} = r.this.GetClass + // But it should return a value + return f() != nil +} + func (_ *GoObject) HashCode() int32 { return 42 }