Skip to content

Commit ac5daa1

Browse files
myronmarstonclaude
andcommitted
Work around JRuby absolute_path bug on load with bare relative path.
JRuby's `Thread::Backtrace::Location#absolute_path` returns a relative path (same as `#path`) when the file was loaded via `load "file.rb"` (bare relative, no `./` prefix). MRI correctly resolves to full absolute path. This broke `Pathname#relative_path_from` in schema_artifact_manager. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2527957 commit ac5daa1

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

elasticgraph-schema_definition/lib/elastic_graph/schema_definition/jruby_patches.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,22 @@
1616
# Reported upstream: https://github.com/jruby/jruby/issues/9242
1717
# TODO: remove once JRuby fixes this upstream.
1818

19+
# Bug: `Thread::Backtrace::Location#absolute_path` returns a relative path (same as `#path`)
20+
# when the source file was loaded via `load` with a bare relative path (e.g. `load "schema.rb"`).
21+
# On MRI, `absolute_path` correctly resolves to the full absolute path in this case.
22+
# Workaround: override `absolute_path` to expand relative paths.
23+
# Reported upstream: https://github.com/jruby/jruby/issues/XXXX
24+
# TODO: remove once JRuby fixes this upstream.
25+
class ::Thread::Backtrace::Location
26+
alias_method :__original_absolute_path__, :absolute_path
27+
28+
def absolute_path
29+
result = __original_absolute_path__
30+
return result if result.nil? || result.start_with?("/")
31+
::File.expand_path(result)
32+
end
33+
end
34+
1935
require "elastic_graph/schema_definition/mixins/has_indices"
2036

2137
module ElasticGraph

elasticgraph-schema_definition/lib/elastic_graph/schema_definition/schema_artifact_manager.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
require "tempfile"
1616
require "yaml"
1717

18+
# :nocov: -- only loaded on JRuby
19+
require "elastic_graph/schema_definition/jruby_patches" if RUBY_ENGINE == "jruby"
20+
# :nocov:
21+
1822
ElasticGraph::Support::GraphQLGemLoader.load
1923

2024
module ElasticGraph

0 commit comments

Comments
 (0)