From e732f53093f29cbaab692d303f0ef464df66db63 Mon Sep 17 00:00:00 2001 From: Charles Oliver Nutter Date: Mon, 22 Apr 2024 14:14:43 -0500 Subject: [PATCH] Also flag frame names with "!" for ostruct The ostruct library aliases all methods from Object/Kernel with a bang suffix ("!") to allow them to be callable even though the OpenStruct should support them as field names. Because we use record these names in a table of known frame-aware methods, we have typically warned when aliasing them. This rarely comes up, since aliasing usually is accompanied by wrapping, which breaks their behavior on all implementations, but this aliasing in ostruct is unusual and pervasive, leading to issues like #8200. This patch assumes we're going to have issues with ostruct forever and eagerly adds the "!" names alongside the regular names for all method names that match /[a-z_]/, so taht existing methods and future methods will behavior properly and not warn when aliased. It adds a small amount to startup, since these method names must be added twice, but there are not many such names in the system. Fixes #8200 Replaces #7524 --- core/src/main/java/org/jruby/anno/AnnotationHelper.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/main/java/org/jruby/anno/AnnotationHelper.java b/core/src/main/java/org/jruby/anno/AnnotationHelper.java index 1047cb37cba..96fb4bfe0e8 100644 --- a/core/src/main/java/org/jruby/anno/AnnotationHelper.java +++ b/core/src/main/java/org/jruby/anno/AnnotationHelper.java @@ -112,6 +112,11 @@ public static void populateMethodIndex(Map, List> access for (String name : names) { if (uniqueValues.add(name)) { joiner.add(name); + + // in order to support these names aliased with "!" we eagerly add those names as well (jruby/jruby#8200) + if (name.matches("^[a-z_]+$")) { + joiner.add(name + '!'); + } } } String namesJoined = joiner.toString();