Repository: embulk/embulk
Issue: embulk mkbundle failed with the reason "undefined local variable or method `__internal_argv__'"

Issue Type: Bug Report
-----------------------

The environment is the same #1347

* Write the following environmental information.
  * OS version: macOS 10.15.7
  * Java version: 1.8.0_251
  * Embulk version: 0.10.21
  * Your Embulk configuration (YAML): no config
  * Plugin versions: no plugin

## Write all what you did, e.g. your commands executed

`embulk mkbundle` after `embulk gem install bundler` I got the another error

gem installed the `bundler -v 2.1.4`. It seems that this version is too new.
`embulk mkbundle worked`  fine with bundler -v 1.16.0


## Write what you expected and observed actually


* Embulk: 0.10.21
* OS: 10.15.7
* Java: 1.8.0_251


```
embulk-dev mkbundle hoge
2020-11-30 09:39:25.026 +0900 [INFO] (main): embulk_home is set from command-line: /path/to/.embulk-dev
Initializing hoge...
  Creating Gemfile
  Creating .bundle/config
  Creating embulk/input/example.rb
  Creating embulk/output/example.rb
  Creating embulk/filter/example.rb
2020-11-30 09:39:27.520 +0900 [INFO] (main): Environment variable "GEM_HOME" is not set. Setting "GEM_HOME" to "/path/to/.embulk-dev/lib/gems" from Embulk system property "gem_home" for the "bundle" command.
--- ERROR REPORT TEMPLATE -------------------------------------------------------
# Error Report

## Questions

Please fill out answers to these questions, it'll help us figure out
why things are going wrong.

- **What did you do?**

  I ran the command `<script> `

- **What did you expect to happen?**

  I expected Bundler to...

- **What happened instead?**

  Instead, what happened was...

- **Have you tried any solutions posted on similar issues in our issue tracker, stack overflow, or google?**

  I tried...

- **Have you read our issues document, https://github.com/bundler/bundler/blob/master/doc/contributing/ISSUES.md?**

  ...

## Backtrace

NameError: undefined local variable or method `__internal_argv__' for main:Object
  <script>:1:in `block in (root)'
  /path/to/.embulk-dev/lib/gems/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
  <script>:1:in `block in (root)'
  org/jruby/RubyDir.java:323:in `chdir'
  <script>:1:in `<main>'

## Environment

Bundler       2.1.4
  Platforms   ruby, universal-java-1.8
Ruby          2.3.3p0 (2017-12-07 revision 56859) [java]
  Full Path   /Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk/Contents/Home/jre/bin/java -cp :/path/to/.embulk/jars/jruby-complete-9.1.15.0.jar org.jruby.Main
  Config Dir  uri:classloader:/META-INF/jruby.home/etc
RubyGems      2.6.14
  Gem Home    /path/to/.embulk-dev/lib/gems
  Gem Path    /path/to/.embulk-dev/lib/gems
  User Home   /Users/hsato
  User Path   /path/to/.gem/jruby/2.3.0
  Bin Dir     /path/to/.embulk-dev/lib/gems/bin
Tools
  Git         2.28.0
  RVM         not installed
  rbenv       rbenv 1.1.2
  chruby      not installed

## Bundler Build Metadata

Built At          2020-01-05
Git SHA           32a4159325
Released Version  true

## Bundler settings

gem.test
  Set for the current user (/path/to/.bundle/config): "minitest"
gem.mit
  Set for the current user (/path/to/.bundle/config): false
gem.coc
  Set for the current user (/path/to/.bundle/config): false
build.thin
  Set for the current user (/path/to/.bundle/config): "--with-cflags=-Wno-error=implicit-function-declaration"

## Gemfile

### Gemfile

source 'https://rubygems.org/'

# No versions are specified for 'embulk' to use the gem embedded in embulk.jar.
# Note that prerelease versions (e.g. "0.9.0.beta") do not match the statement.
# Specify the exact prerelease version (like '= 0.9.0.beta') for prereleases.
gem 'embulk'

#
# 1. Use following syntax to specify versions of plugins
#    to install this bundle directory:
#
#gem 'embulk-output-mysql'                     # the latest version
#gem 'embulk-input-baz', '= 0.2.0'             # specific version
#gem 'embulk-input-xyz', '~> 0.3.0'            # latest major version
#gem 'embulk-output-postgresql', '>= 0.1.0'    # newer than specific version
#
#gem 'embulk-output-awesome', git: 'https://github.com/you/embulk-output-awesome.git', branch: 'master'
#

#
# 2. When you modify this file, run following command to
#    install plugins:
#
#   $ cd this_directory
#   $ embulk bundle
#

#
# 3. Then you can use plugins with -b, --bundle BUNDLE_PATH command:
#
#   $ embulk guess -b path/to/this/directory  ...
#   $ embulk run -b path/to/this/directory  ...
#   $ embulk preview -b path/to/this/directory  ...
#

### Gemfile.lock

<No /private/tmp/hoge/Gemfile.lock found>

--- TEMPLATE END ----------------------------------------------------------------

Unfortunately, an unexpected error occurred, and Bundler cannot continue.

First, try this link to see if there are any existing issue reports for this error:
https://github.com/bundler/bundler/search?q=undefined+local+variable+or+method+%60__internal_argv__%27+for+main+Object&type=Issues

If there aren't any reports for this error yet, please create copy and paste the report template above into a new issue. Don't forget to anonymize any private data! The new issue form is located at:
https://github.com/bundler/bundler/issues/new
```


```
embulk-dev gem install bundler
embulk-dev gem list
*** LOCAL GEMS ***

bundler (2.1.4)
did_you_mean (default: 1.0.1)
embulk (0.10.21 java)
jar-dependencies (default: 0.3.10)
jruby-openssl (0.9.21 java)
jruby-readline (1.2.0 java)
json (1.8.3 java)
minitest (default: 5.4.1)
net-telnet (default: 0.1.1)
power_assert (default: 0.2.3)
psych (2.2.4 java)
rake (default: 10.4.2)
rdoc (default: 4.2.0)
test-unit (default: 3.1.1)
```



Changed files:
embulk-core/src/main/java/org/embulk/cli/EmbulkRun.java

diff --git a/embulk-core/src/main/java/org/embulk/cli/EmbulkRun.java b/embulk-core/src/main/java/org/embulk/cli/EmbulkRun.java
index 41e93ef3..6487ec35 100644
--- a/embulk-core/src/main/java/org/embulk/cli/EmbulkRun.java
+++ b/embulk-core/src/main/java/org/embulk/cli/EmbulkRun.java
@@ -250,7 +250,10 @@ public class EmbulkRun {
             localJRubyContainer.runScriptlet("Bundler.with_friendly_errors { Bundler::CLI.start(Array.new(__internal_argv_java__), debug: true) }");
         } else {
             localJRubyContainer.put("__internal_working_dir__", path.toString());
-            localJRubyContainer.runScriptlet("Dir.chdir(__internal_working_dir__) { Bundler.with_friendly_errors { Bundler::CLI.start(__internal_argv__, debug: true) } }");
+            localJRubyContainer.runScriptlet(
+                    "Dir.chdir(__internal_working_dir__) {"
+                    + "  Bundler.with_friendly_errors { Bundler::CLI.start(Array.new(__internal_argv_java__), debug: true) }"
+                    + "}");
             localJRubyContainer.remove("__internal_working_dir__");
         }
         localJRubyContainer.remove("__internal_argv_java__");