Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error messages for failed casts using Integer() subtly different to MRI #3346

Closed
dwaller opened this issue Sep 24, 2015 · 1 comment
Closed

Comments

@dwaller
Copy link

dwaller commented Sep 24, 2015

A trivial problem that I fell over because I had tests that asserted on the error message. But maybe it has an equally trivial solution.

MRI gives the error message invalid value for Integer(): "3a"

JRuby gives the error message invalid value for Integer: "3a" Note, no () after Integer

➜  code  ruby --version
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
➜  code  irb
 :001 > Integer('3a')
ArgumentError: invalid value for Integer(): "3a"
    from (irb):1:in `Integer'
    from (irb):1
    from /Users/dwaller/.rvm/rubies/ruby-2.2.3/bin/irb:15:in `<main>'
 :002 > Integer('')
ArgumentError: invalid value for Integer(): ""
    from (irb):2:in `Integer'
    from (irb):2
    from /Users/dwaller/.rvm/rubies/ruby-2.2.3/bin/irb:15:in `<main>'
 :003 > Integer(nil)
TypeError: can't convert nil into Integer
    from (irb):3:in `Integer'
    from (irb):3
    from /Users/dwaller/.rvm/rubies/ruby-2.2.3/bin/irb:15:in `<main>'
➜  code  rvm use jruby-9.0.1.0-d19
Using /Users/dwaller/.rvm/gems/jruby-9.0.1.0-d19
➜  code  ruby --version
jruby 9.0.1.0 (2.2.2) 2015-09-02 583f336 Java HotSpot(TM) 64-Bit Server VM 25.45-b02 on 1.8.0_45-b14 +jit [darwin-x86_64]
➜  code  irb
jruby-9.0.1.0-d19 :001 > Integer('3a')
ArgumentError: invalid value for Integer: "3a"
    from org/jruby/RubyKernel.java:427:in `Integer'
    from (irb):1:in `<eval>'
    from org/jruby/RubyKernel.java:978:in `eval'
    from org/jruby/RubyKernel.java:1291:in `loop'
    from org/jruby/RubyKernel.java:1098:in `catch'
    from org/jruby/RubyKernel.java:1098:in `catch'
    from /Users/dwaller/.rvm/rubies/jruby-9.0.1.0-d19/bin/irb:13:in `<top>'
jruby-9.0.1.0-d19 :002 > Integer('')
ArgumentError: invalid value for Integer: ""
    from org/jruby/RubyKernel.java:427:in `Integer'
    from (irb):2:in `<eval>'
    from org/jruby/RubyKernel.java:978:in `eval'
    from org/jruby/RubyKernel.java:1291:in `loop'
    from org/jruby/RubyKernel.java:1098:in `catch'
    from org/jruby/RubyKernel.java:1098:in `catch'
    from /Users/dwaller/.rvm/rubies/jruby-9.0.1.0-d19/bin/irb:13:in `<top>'
jruby-9.0.1.0-d19 :003 > Integer(nil)
TypeError: can't convert nil into Integer
    from org/jruby/RubyKernel.java:427:in `Integer'
    from (irb):3:in `<eval>'
    from org/jruby/RubyKernel.java:978:in `eval'
    from org/jruby/RubyKernel.java:1291:in `loop'
    from org/jruby/RubyKernel.java:1098:in `catch'
    from org/jruby/RubyKernel.java:1098:in `catch'
    from /Users/dwaller/.rvm/rubies/jruby-9.0.1.0-d19/bin/irb:13:in `<top>'
@kares
Copy link
Member

kares commented Nov 14, 2015

should be part of 1.7.23 and later 9.0.5.0 as 1.7 branch gets merged over.

@kares kares closed this as completed Nov 14, 2015
kares added a commit that referenced this issue Nov 15, 2015
* jruby-1_7: (46 commits)
  make previous commit null-safe + review JRuby home verification - normalize once!
  normalize JRubyHome for windows.
  backport ruby 1.9.3 test_bigdecimal from MRI (NAN.round no longer supposed to fail)
  make sure BigDecimal test restores exception modes + make nan asserts 1.8 compat
  handle BigDecimal#round-ing for NaN (does not raise since 1.8.7 current MRI 2.2.3)
  update to latest jruby-openssl release: 0.9.12
  update options library to latest 1.3 release
  re-format code - mislined line + unused variable & use indexOf(char) instead of str
  avoid expensive pattern compiling in arg processing loop (split() and replaceAll())
  [nkf] handle 1.9.3 NKF library compatibility - returning encoding objects (see #338)
  avoid double convertToInteger and double NKF map lookup in EncodingService
  define NKF version constants (based on MRI 1.8.7 ... which is how NKF is compatible)
  make NKF shared public static map final
  correct ArgumentError message format to match MRI >= 1.9.3 (fixes #3346)
  be failsafe when trying to load META-INF/maven/org.yaml/snakeyaml/pom.properties
  fix generics (for master backport) to dispatch to correct CallableSelector override
  move CallableCache internal interface were it fits + add matching methods for arities
  invent a "true" null (java) callable cache for invokers + make get/put signature final
  refactor (internal) Java.__jcreate! impl to use same cache as RubyToJavaInvoker-s ... introducing an internal CallableCache interface to loose coupling in CallableSelector
  Use Cliff Click's high-scale collections instead of IntHashMap.
  ...

Conflicts:
	core/pom.xml
	core/src/main/java/org/jruby/RubyFile.java
	core/src/main/java/org/jruby/RubyInstanceConfig.java
	core/src/main/java/org/jruby/RubyProc.java
	core/src/main/java/org/jruby/exceptions/RaiseException.java
	core/src/main/java/org/jruby/ext/bigdecimal/RubyBigDecimal.java
	core/src/main/java/org/jruby/ext/psych/PsychLibrary.java
	core/src/main/java/org/jruby/java/dispatch/CallableSelector.java
	core/src/main/java/org/jruby/java/invokers/RubyToJavaInvoker.java
	core/src/main/java/org/jruby/javasupport/Java.java
	core/src/main/java/org/jruby/runtime/Helpers.java
	core/src/main/java/org/jruby/runtime/backtrace/TraceType.java
	core/src/main/java/org/jruby/runtime/encoding/EncodingService.java
	core/src/main/java/org/jruby/util/cli/ArgumentProcessor.java
	default.build.properties
	lib/pom.rb
	lib/pom.xml
	maven/jruby-dist/pom.rb
	maven/jruby-dist/pom.xml
	maven/jruby-dist/src/main/assembly/jruby.xml
	maven/jruby-stdlib/pom.rb
	maven/jruby/src/it/runnable/spec/one_spec.rb
	pom.xml
	rakelib/test.rake
	spec/profiler/json_profile_printer_spec.rb
	spec/profiler/runtime_spec.rb
	test/externals/ruby1.9/bigdecimal/test_bigdecimal.rb
	test/pom.rb
	test/pom.xml
	test/test_big_decimal.rb
	test/test_file.rb
	test/test_pathname.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants