JRuby (please use github issues at http://bugs.jruby.org)
  1. JRuby (please use github issues at http://bugs.jruby.org)
  2. JRUBY-4671

jrubyc --java fails to java_require when class and script are named the same

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: JRuby 1.5
    • Fix Version/s: None
    • Component/s: Java Integration
    • Labels:
      None
    • Number of attachments :
      0

      Description

      This doesn't work:

      foo.rb

      require 'java'
      java_require 'foo'
      class Foo; end
      

      The problem here is that on systems that aren't case-sensitive, the Foo class gets generated into Foo.class with a require that looks for "foo". Our normal search order tries to find "foo.class" before "foo.rb", and on a non-case-sensitive filesystem it ends up finding Foo.class. This results in a require error, since you can't require a Java class.

      renaming the file solves the problem, or putting the class into a specific package, but we need some way to address this (ranging from a nicer error message to making it work...somehow).

      Here's the error that results, FWIW:

      ~/projects/jruby ➔ jrubyc --java foo.rb
      Generating Java class Foo to Foo.java
      javac -d /Users/headius/projects/jruby -cp /Users/headius/projects/jruby/lib/jruby.jar:. Foo.java
      
      ~/projects/jruby ➔ java -cp .:lib/jruby.jar Foo
      Exception in thread "main" java.lang.ExceptionInInitializerError
      Caused by: org.jruby.exceptions.RaiseException: use `java_import' to load normal Java classes
      	at (unknown).new(:1)
      	at (unknown).(unknown)(:1)
      

        Activity

        Hide
        Charles Oliver Nutter added a comment -

        Another workaround: remove the java_require line entirely and allow the script to get embedded in the class file.

        Show
        Charles Oliver Nutter added a comment - Another workaround: remove the java_require line entirely and allow the script to get embedded in the class file.
        Hide
        Charles Oliver Nutter added a comment -

        Won't fix for jruby 1.5, and there really may not be any fix. You would run into similar problems with this casing logic if you had two Java classes of differing cases on OS X.

        Show
        Charles Oliver Nutter added a comment - Won't fix for jruby 1.5, and there really may not be any fix. You would run into similar problems with this casing logic if you had two Java classes of differing cases on OS X.
        Hide
        Douglas Campos added a comment -

        Is this even detectable?

        Show
        Douglas Campos added a comment - Is this even detectable?
        Hide
        Douglas Campos added a comment -

        +1 to close it, expected behavior on case-insensitive (or preserve) filesystems.

        Show
        Douglas Campos added a comment - +1 to close it, expected behavior on case-insensitive (or preserve) filesystems.

          People

          • Assignee:
            Charles Oliver Nutter
            Reporter:
            Charles Oliver Nutter
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: