diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/ArraySymbol.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/ArraySymbol.cs index c78c42d63..cb59c5b16 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/ArraySymbol.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Symbols/ArraySymbol.cs @@ -106,8 +106,8 @@ public string[] PostCall (CodeGenerationOptions opt, string var_name) { string native_name = opt.GetSafeIdentifier (TypeNameUtilities.GetNativeName (var_name)); string[] result = new string [4]; - result [0] = String.Format ("if ({0} != null) {{", var_name); - result [1] = String.Format ("\tJNIEnv.CopyArray ({0}, {1});", native_name, var_name); + result [0] = String.Format ("if ({0} != null) {{", opt.GetSafeIdentifier (var_name)); + result [1] = String.Format ("\tJNIEnv.CopyArray ({0}, {1});", native_name, opt.GetSafeIdentifier (var_name)); result [2] = String.Format ("\tJNIEnv.DeleteLocalRef ({0});", native_name); result [3] = "}"; return result; diff --git a/tools/generator/Tests/Unit-Tests/CodeGeneratorTests.cs b/tools/generator/Tests/Unit-Tests/CodeGeneratorTests.cs index 81849d6a1..25ec4f0f8 100644 --- a/tools/generator/Tests/Unit-Tests/CodeGeneratorTests.cs +++ b/tools/generator/Tests/Unit-Tests/CodeGeneratorTests.cs @@ -862,5 +862,22 @@ public void WriteMethodWithInvalidJavaName () Assert.False (result.Contains ("cb_has-hyp$hen")); Assert.True (result.Contains ("cb_has_x45_hyp_x36_hen")); } + + [Test] + public void WriteMethodWithInvalidParameterName () + { + var @class = new TestClass ("java.lang.Object", "com.mypackage.foo"); + var method = new TestMethod (@class, "DoStuff"); + + method.Parameters.Add (new Parameter ("$this", "byte[]", "byte[]", false)); + + Assert.IsTrue (method.Validate (options, new GenericParameterDefinitionList (), new CodeGeneratorContext ()), "method.Validate failed!"); + generator.WriteMethod (method, string.Empty, @class, true); + + var result = writer.ToString ().NormalizeLineEndings (); + + // Ensure we escape dollar signs + Assert.False (result.Contains ("$this")); + } } }