def resolve_path(path, try_extensions: true)
      extensions_to_try = if try_extensions && !REQUIRABLE_EXTENSIONS.include?(File.extname(path))
                            REQUIRABLE_EXTENSION_KEYS
                          else
                            ['']
                          end

      abs_path = File.absolute_path(path)
      path = abs_path if path.start_with?('./', '../')

      paths_with_ext = extensions_to_try.map { |ext| path + ext }

      refresh_loaded_features_set

      # Doing this check in every case instead of only for absolute_path because ruby has some
      # built-in $LOADED_FEATURES which aren't an absolute path. Ex: enumerator.so, thread.rb
      path_from_loaded_features = first_path_from_loaded_features_set(paths_with_ext)
      return path_from_loaded_features if path_from_loaded_features

      if path == abs_path
        paths_with_ext.each do |path_with_ext|
          next unless File.exist?(path_with_ext)

          # https://github.com/jruby/jruby/issues/5465
          path_with_ext = File.realpath(path_with_ext) if RUBY_PLATFORM == 'java' && JRUBY_VERSION >= '9.2.5'
          return path_with_ext
        end
      else
        possible_paths = paths_with_load_paths(paths_with_ext)
        path_from_loaded_features = first_path_from_loaded_features_set(possible_paths)
        return path_from_loaded_features if path_from_loaded_features

        possible_paths.each do |possible_path|
          next unless File.exist?(possible_path)
          # Ruby 2.5 changed some behaviors of require related to symlinks in $LOAD_PATH
          # https://bugs.ruby-lang.org/issues/10222
          return File.realpath(possible_path) if RUBY_VERSION >= '2.5'
          return possible_path
        end
      end
      nil
    end
def resolve_path(path, try_extensions: true)
      extensions_to_try = if try_extensions && !REQUIRABLE_EXTENSIONS.include?(File.extname(path))
                            REQUIRABLE_EXTENSION_KEYS
                          else
                            ['']
                          end

      abs_path = File.absolute_path(path)
      path = abs_path if path.start_with?('./', '../')

      paths_with_ext = extensions_to_try.map { |ext| path + ext }

      refresh_loaded_features_set

      # Doing this check in every case instead of only for absolute_path because ruby has some
      # built-in $LOADED_FEATURES which aren't an absolute path. Ex: enumerator.so, thread.rb
      path_from_loaded_features = first_path_from_loaded_features_set(paths_with_ext)
      return path_from_loaded_features if path_from_loaded_features

      if path == abs_path
        paths_with_ext.each do |path_with_ext|
          next unless File.exist?(path_with_ext)

          # https://github.com/jruby/jruby/issues/5465
          path_with_ext = File.realpath(path_with_ext) if RUBY_PLATFORM == 'java' && JRUBY_VERSION >= '9.2.5'
          return path_with_ext
        end
      else
        possible_paths = paths_with_load_paths(paths_with_ext)
        path_from_loaded_features = first_path_from_loaded_features_set(possible_paths)
        return path_from_loaded_features if path_from_loaded_features

        possible_paths.each do |possible_path|
          next unless File.exist?(possible_path)
          # Ruby 2.5 changed some behaviors of require related to symlinks in $LOAD_PATH
          # https://bugs.ruby-lang.org/issues/10222
          return File.realpath(possible_path) if RUBY_VERSION >= '2.5'
          return possible_path
        end
      end
      nil
    end
Returns a path to an existing file or nil if none can be found.
 The search follows how ruby search for files using the $LOAD_PATH, but limits
 those it checks based on the LoadPathsSubset.

 An absolute path is returned directly if it exists, otherwise nil is returned
 without searching anywhere else.