From 499826d6385140197a63bfbf0b35d770e10a3cd7 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Thu, 26 Oct 2023 01:55:46 -0500 Subject: [PATCH] Properly extract the 'perm' kwarg to File.open The logic here was incorrectly ported. The original code checks the vperm pointer passed in to know whether it can be dereferenced. The broken code in JRuby ends up requiring a a non-null positional vperm argument in order to use the kwarg, which then immediately errors anyway. The new code if the perm kwarg and the positional vperm are both set, but if only the kwarg is given, it will be used for the new file. Fixes failures switching from our own native Tempfile to the tempfile gem. See #7973 --- .../src/main/java/org/jruby/util/io/EncodingUtils.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/jruby/util/io/EncodingUtils.java b/core/src/main/java/org/jruby/util/io/EncodingUtils.java index d8e25a2cf8c3..476fc0eae1fd 100644 --- a/core/src/main/java/org/jruby/util/io/EncodingUtils.java +++ b/core/src/main/java/org/jruby/util/io/EncodingUtils.java @@ -262,11 +262,13 @@ public static void extractModeEncoding(ThreadContext context, v = hashARef(runtime, options, "perm"); if (!v.isNil()) { - if (vperm(vmodeAndVperm_p) != null) { - if (!vperm(vmodeAndVperm_p).isNil()) throw runtime.newArgumentError("perm specified twice"); - - vperm(vmodeAndVperm_p, v); + if (vperm(vmodeAndVperm_p) != null && !vperm(vmodeAndVperm_p).isNil()) { + throw runtime.newArgumentError("perm specified twice"); } + + vperm(vmodeAndVperm_p, v); + } else { + /* perm no use, just ignore */ } IRubyObject extraFlags = hashARef(runtime, options, "flags");