Index: src/org/jruby/RubyDir.java
===================================================================
--- src/org/jruby/RubyDir.java	(revision 7980)
+++ src/org/jruby/RubyDir.java	(working copy)
@@ -106,7 +106,7 @@
         RubyString newPath = _newPath.convertToString();
         getRuntime().checkSafeString(newPath);
 
-        String adjustedPath = RubyFile.adjustRootPathOnWindows(getRuntime(), newPath.toString(), null);
+        String adjustedPath = RubyFile.adjustRootPathOnWindows(getRuntime(), newPath.getUnicodeValue(), null);
         checkDirIsTwoSlashesOnWindows(getRuntime(), adjustedPath);
 
         dir = JRubyFile.create(getRuntime().getCurrentDirectory(), adjustedPath);
@@ -219,7 +219,7 @@
         Ruby runtime = recv.getRuntime();
 
         String adjustedPath = RubyFile.adjustRootPathOnWindows(
-                runtime, path.convertToString().toString(), null);
+                runtime, path.convertToString().getUnicodeValue(), null);
         checkDirIsTwoSlashesOnWindows(runtime, adjustedPath);
 
         final JRubyFile directory = JRubyFile.create(
@@ -247,8 +247,10 @@
     public static IRubyObject chdir(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block block) {
         RubyString path = args.length == 1 ? 
             (RubyString) args[0].convertToString() : getHomeDirectoryPath(context);
+            
         String adjustedPath = RubyFile.adjustRootPathOnWindows(
-                recv.getRuntime(), path.toString(), null);
+                recv.getRuntime(), path.getUnicodeValue(), null);
+        
         checkDirIsTwoSlashesOnWindows(recv.getRuntime(), adjustedPath);
         JRubyFile dir = getDir(recv.getRuntime(), adjustedPath, true);
         String realPath = null;
@@ -296,7 +298,7 @@
      */
     @JRubyMethod(name = {"rmdir", "unlink", "delete"}, required = 1, meta = true)
     public static IRubyObject rmdir(IRubyObject recv, IRubyObject path) {
-        JRubyFile directory = getDir(recv.getRuntime(), path.convertToString().toString(), true);
+        JRubyFile directory = getDir(recv.getRuntime(), path.convertToString().getUnicodeValue(), true);
         
         if (!directory.delete()) {
             throw recv.getRuntime().newSystemCallError("No such directory");
@@ -343,8 +345,8 @@
     public static IRubyObject mkdir(IRubyObject recv, IRubyObject[] args) {
         Ruby runtime = recv.getRuntime();
         runtime.checkSafeString(args[0]);
-        String path = args[0].toString();
-
+        
+        String path = args[0].convertToString().getUnicodeValue();
         File newDir = getDir(runtime, path, false);
         if (File.separatorChar == '\\') {
             newDir = new File(newDir.getPath());
Index: src/org/jruby/RubyFile.java
===================================================================
--- src/org/jruby/RubyFile.java	(revision 7980)
+++ src/org/jruby/RubyFile.java	(working copy)
@@ -772,7 +772,7 @@
                 throw runtime.newErrnoENOENTError("No such file or directory - " + filename);
             }
             
-            boolean result = 0 == runtime.getPosix().chmod(filename.toString(), (int)mode.getLongValue());
+            boolean result = 0 == runtime.getPosix().chmod(filename.convertToString().getUnicodeValue(), (int)mode.getLongValue());
             if (result) {
                 count++;
             }
@@ -1324,7 +1324,6 @@
         Ruby runtime = context.getRuntime();
         RubyString fromStr = RubyString.stringValue(from);
         RubyString toStr = RubyString.stringValue(to);
-        
         try {
             if (runtime.getPosix().link(
                     fromStr.getUnicodeValue(),toStr.getUnicodeValue()) == -1) {
@@ -1347,8 +1346,10 @@
     @JRubyMethod(required = 2, meta = true)
     public static IRubyObject rename(ThreadContext context, IRubyObject recv, IRubyObject oldName, IRubyObject newName) {
         Ruby runtime = context.getRuntime();
+        
         RubyString oldNameString = RubyString.stringValue(oldName);
         RubyString newNameString = RubyString.stringValue(newName);
+        
         runtime.checkSafeString(oldNameString);
         runtime.checkSafeString(newNameString);
 
@@ -1418,11 +1419,11 @@
             String realPath = runtime.getPosix().readlink(path.convertToString().getUnicodeValue());
         
             if (!RubyFileTest.exist_p(recv, path).isTrue()) {
-                throw runtime.newErrnoENOENTError("No such file or directory - " + path);
+                throw runtime.newErrnoENOENTError("No such file or directory - " + path.convertToString().getUnicodeValue());
             }
         
             if (!RubyFileTest.symlink_p(recv, path).isTrue()) {
-                throw runtime.newErrnoEINVALError("invalid argument - " + path);
+                throw runtime.newErrnoEINVALError("invalid argument - " + path.convertToString().getUnicodeValue());
             }
         
             if (realPath == null) {
@@ -1448,12 +1449,12 @@
         if ( childFile.isAbsolute() ) {
           testFile = childFile ;
         } else {
-          testFile = new File(runtime.getCurrentDirectory(), filename.getByteList().toString());
+          testFile = new File(runtime.getCurrentDirectory(), filename.getUnicodeValue());
         }
 
         if (!testFile.exists()) {
             throw runtime.newErrnoENOENTError(
-                    "No such file or directory - " + filename.getByteList().toString());
+                    "No such file or directory - " + filename.getUnicodeValue());
         }
 
         if (newLength.getLongValue() < 0) {
Index: test/test_dir.rb
===================================================================
--- test/test_dir.rb	(revision 7980)
+++ test/test_dir.rb	(working copy)
@@ -4,13 +4,16 @@
 class TestDir < Test::Unit::TestCase
   WINDOWS = Config::CONFIG['host_os'] =~ /Windows|mswin/
 
+  # Special character to test character encoding
+  DIR='testDirÜ_'
+
   def setup
     @save_dir = Dir.pwd
     1.upto(5) do |i|
-      Dir["testDir_#{i}/*"].each do |f|
+      Dir["#{DIR}#{i}/*"].each do |f|
         File.unlink f rescue nil
       end
-      Dir.delete("testDir_#{i}") rescue nil
+      Dir.delete("#{DIR}#{i}") rescue nil
     end
   end
 
@@ -19,34 +22,44 @@
     setup
   end
 
+  def test_initialize_unicode
+    Dir.mkdir("./#{DIR}1")
+    d = Dir.new "#{DIR}1"
+    assert_equal "#{DIR}1", d.path
+  end
+
   def test_pwd_and_getwd_equivalent
     assert_equal(Dir.pwd, Dir.getwd)
   end
 
   def test_dir_enumerable
-    Dir.mkdir("./testDir_1")
+    Dir.mkdir("./#{DIR}1")
 
-    d = Dir.new("./testDir_1")
+    d = Dir.new("./#{DIR}1")
     assert(d.kind_of?(Enumerable))
     assert_equal(['.', '..'], d.entries)
   end
 
   def test_dir_entries
-    Dir.mkdir("./testDir_1")
+    Dir.mkdir("./#{DIR}1")
     (1..2).each {|i|
-      File.open("./testDir_1/file" + i.to_s, "w") {|f|
+      File.open("./#{DIR}1/file" + i.to_s, "w") {|f|
         f.write("hello")
       }
     }
 
-    assert_equal(['.', '..', "file1", "file2"], Dir.entries('./testDir_1').sort)
-    assert_equal(['.', '..', "file1", "file2"], Dir.new('./testDir_1').entries.sort)
-    Dir.chdir("./testDir_1")
+    assert File.exist? "./#{DIR}1"
+
+    assert_equal(['.', '..', "file1", "file2"], Dir.entries("./#{DIR}1").sort)
+    assert_equal(['.', '..', "file1", "file2"], Dir.new("./#{DIR}1").entries.sort)
+    Dir.chdir("./#{DIR}1")
+    assert Dir.getwd.include? "#{DIR}1"
+
     assert_equal(['.', '..', "file1", "file2"], Dir.entries('.').sort)
     Dir.chdir("..")
 
     files = []
-    Dir.foreach('./testDir_1') {|f| files << f }
+    Dir.foreach("./#{DIR}1") {|f| files << f }
     assert_equal(['.', '..', "file1", "file2"], files.sort)
   end
 
@@ -64,14 +77,14 @@
   def test_glob_double_star
     # Test that glob expansion of ** works ok with non-patterns as path 
     # elements. This used to throw NPE.
-    Dir.mkdir("testDir_2")
-    open("testDir_2/testDir_tmp1", "w").close
+    Dir.mkdir("#{DIR}2")
+    open("#{DIR}2/testDir_tmp1", "w").close
     Dir.glob('./**/testDir_tmp1').each {|f| assert File.exist?(f) }
   end
 
   def test_glob_with_blocks
-    Dir.mkdir("testDir_3")
-    open("testDir_3/testDir_tmp1", "w").close
+    Dir.mkdir("#{DIR}3")
+    open("#{DIR}3/testDir_tmp1", "w").close
     vals = []
     glob_val = Dir.glob('**/*tmp1'){|f| vals << f}
     assert_equal(true, glob_val.nil?)
@@ -97,24 +110,24 @@
   def test_chdir_and_pwd
     java_test_classes = File.expand_path(File.dirname(__FILE__) + '/../build/classes/test')
     java_test_classes = File.expand_path(File.dirname(__FILE__) + '/..') unless File.exist?(java_test_classes)
-    Dir.mkdir("testDir_4")
-    Dir.chdir("testDir_4") do
+    Dir.mkdir("#{DIR}4")
+    Dir.chdir("#{DIR}4") do
       pwd = `ruby -e "puts Dir.pwd"`
       pwd.gsub! '\\', '/'
-      assert_equal("testDir_4", pwd.split("/")[-1].strip)
+      assert_equal("#{DIR}4", pwd.split("/")[-1].strip)
 
       pwd = `jruby -e "puts Dir.pwd"`
       pwd.gsub! '\\', '/'
-      assert_equal("testDir_4", pwd.split("/")[-1].strip)
+      assert_equal("#{DIR}4", pwd.split("/")[-1].strip)
 
       pwd = `java -cp "#{java_test_classes}" org.jruby.util.Pwd`
       pwd.gsub! '\\', '/'
-      assert_equal("testDir_4", pwd.split("/")[-1].strip)
+      assert_equal("#{DIR}4", pwd.split("/")[-1].strip)
     end
     Dir.chdir("testDir_4")
     pwd = `java -cp "#{java_test_classes}" org.jruby.util.Pwd`
     pwd.gsub! '\\', '/'
-    assert_equal("testDir_4", pwd.split("/")[-1].strip)
+    assert_equal("#{DIR}4", pwd.split("/")[-1].strip)
   end
 
   def test_glob_inside_jar_file
@@ -353,10 +366,11 @@
   else
     # http://jira.codehaus.org/browse/JRUBY-1375
     def test_mkdir_on_protected_directory_fails
-      Dir.mkdir("testDir_5") unless File.exists?("testDir_5")
-      File.chmod(0400, 'testDir_5')
+      Dir.mkdir("#{DIR}5") unless File.exists?("#{DIR}5")
+      assert File.exists?("#{DIR}5")
+      File.chmod(0400, "#{DIR}5")
       assert_raises(SystemCallError) do 
-        Dir.mkdir("testDir_5/another_dir")
+        Dir.mkdir("#{DIR}5/another_dir")
       end
     end
   end
Index: test/test_file.rb
===================================================================
--- test/test_file.rb	(revision 7980)
+++ test/test_file.rb	(working copy)
@@ -4,6 +4,10 @@
 
 class TestFile < Test::Unit::TestCase
   WINDOWS = Config::CONFIG['host_os'] =~ /Windows|mswin/
+  
+  # special character for testing correct coercion to Java's UTF-16
+  NON_TRIVIAL_CHAR='ü'; NTC=NON_TRIVIAL_CHAR
+  
   def jruby_specific_test
     flunk("JRuby specific test") unless defined?(JRUBY_VERSION)
   end
@@ -356,26 +360,26 @@
   def test_io_readlines
     # IO#readlines, IO::readlines, open, close, delete, ...
     assert_raises(Errno::ENOENT) { File.open("NO_SUCH_FILE_EVER") }
-    f = open("testFile_tmp", "w")
+    f = open("testFile_tmp#{NTC}", "w")
     f.write("one\ntwo\nthree\n")
     f.close
 
-    f = open("testFile_tmp")
+    f = open("testFile_tmp#{NTC}")
     assert_equal(["one", "two", "three"],
                f.readlines.collect {|l| l.strip })
     f.close
 
     assert_equal(["one", "two", "three"],
-               IO.readlines("testFile_tmp").collect {|l| l.strip })
-    assert(File.delete("testFile_tmp"))
+               IO.readlines("testFile_tmp#{NTC}").collect {|l| l.strip })
+    assert(File.delete("testFile_tmp#{NTC}"))
   end
 
   def test_mkdir
     begin
-      Dir.mkdir("dir_tmp")
-      assert(File.lstat("dir_tmp").directory?)
+      Dir.mkdir("dir_tmp#{NTC}")
+      assert(File.lstat("dir_tmp#{NTC}").directory?)
     ensure
-      Dir.rmdir("dir_tmp")
+      Dir.rmdir("dir_tmp#{NTC}")
     end
   end
 
@@ -434,32 +438,87 @@
     end
   end
 
+
+  # TODO: This one's still failing. It seems to be a String coercion issue,
+  # the OpenFile class holds the UTF-16 version of the path, and it seems like
+  # it is not properly encoded back to UTF-8? Or something like this..
+  def test_openfile_path
+    FileUtils.copy_file "build.xml", "build.xml#{NTC}"
+    file = File.open("build.xml#{NTC}", "wb")
+    assert_equal "build.xml#{NTC}", file.path
+  ensure
+    File.unlink "build.xml#{NTC}"
+  end
+
+  # TODO: dirname and extname suffer from the same coercion issue like the case above.
+  # This problems have been there before, the test cases just uncover them.
+  # So it'd be safe to simply outcomment the tests now
+  def test_dirname_extname_unicode
+    subdir = "./testDir_1#{NTC}"
+    Dir.mkdir(subdir)
+    assert File.exist? "testDir_1#{NTC}"
+
+    FileUtils.copy_file "build.xml", subdir + "/build.xml#{NTC}"
+
+    assert_equal ".xml#{NTC}", File.extname(subdir + "/build.xml#{NTC}")
+    assert_equal "./testDir-1#{NTC}", File.dirname(subdir + "/build.xml#{NTC}")
+
+  ensure
+# TODO: rm_rf doesn't work with special chars!! Another test case and fix needed!
+#    FileUtils.rm_rf(subdir)
+    File.unlink subdir + "/build.xml#{NTC}"
+    Dir.rmdir subdir
+    assert !File.exist?("testDir_1#{NTC}")
+  end
+
+
+  def test_ftype_unicode
+    FileUtils.copy_file "build.xml", "build.xml#{NTC}"
+    assert_equal "file", File.ftype("build.xml#{NTC}")
+  ensure
+    File.unlink "build.xml#{NTC}"
+  end
+
+  def test_rename_unicode
+    FileUtils.copy_file "build.xml", "build.xml#{NTC}"
+    File.rename("build.xml#{NTC}", "build.xml#{NTC}2")
+    assert File.exist? "build.xml#{NTC}2"
+  ensure
+    File.unlink "build.xml#{NTC}2"
+  end
+
+
   # JRUBY-1886
   def test_file_truncated_after_changing_directory
-    subdir = "./testDir_1"
+    subdir = "./testDir_1#{NTC}"
     Dir.mkdir(subdir)
+   
+    assert File.exist?(subdir)
     Dir.chdir(subdir) { |dir|
       begin
-        file = File.open("__dummy_file.txt", "wb") { |file|
+        file = File.open("__dummy_file#{NTC}.txt", "wb") { |file|
           file.write("dummy text")
           file
         }
-        assert_nothing_raised { File.truncate(file.path, 0) }
+
+        assert_nothing_raised { File.truncate("__dummy_file#{NTC}.txt", 0) }
       ensure
-        File.unlink(file.path)
+        File.unlink("__dummy_file#{NTC}.txt")
       end
     }
   ensure
     Dir.rmdir(subdir)
+    assert !File.exist?(subdir)
   end
 
+
   def test_file_size_query
     assert(File.size?('build.xml'))
   end
 
   # JRUBY-2275
   def test_file_size_empty_file
-    filename = "__empty_test__file"
+    filename = "__empty_test__file#{NTC}"
     File.open(filename, "w+") { }
     assert_equal(nil, File.size?(filename))
     assert_equal(nil, FileTest.size?(filename))
@@ -510,9 +569,11 @@
   end
   
   def test_file_open_utime
-    filename = "__test__file"
+    filename = "__test__file#{NTC}"
     File.open(filename, "w") {|f| }
     time = Time.now - 3600
+    assert File.exist? filename
+    
     File.utime(time, time, filename)
     # File mtime resolution may not be sub-second on all platforms (e.g., windows)
     # allow for some slop
@@ -521,7 +582,7 @@
   end
   
   def test_file_utime_nil_mtime
-    filename = '__test__file'
+    filename = "__test__file#{NTC}"
     File.open(filename, 'w') {|f| }
     time = File.mtime(filename)
     sleep 2
@@ -532,7 +593,7 @@
   
   def test_file_utime_bad_mtime_raises_typeerror
     args = [ [], {}, '4000' ]
-    filename = '__test__file'
+    filename = "__test__file#{NTC}"
     File.open(filename, 'w') {|f| }
     args.each do |arg|
       assert_raises(TypeError) {  File.utime(arg, arg, filename) }
@@ -542,7 +603,7 @@
   
   # JRUBY-1982 and JRUBY-1983
   def test_file_mtime_after_fileutils_touch
-    filename = '__test__file'
+    filename = "__test__file#{NTC}"
     File.open(filename, 'w') {|f| }
     time = File.mtime(filename)
     
@@ -553,6 +614,8 @@
   end
 
   def test_file_stat # File::Stat tests
+    # TODO
+    
     stat = File.stat('test');
     stat2 = File.stat('build.xml');
     assert(stat.directory?)
@@ -587,21 +650,58 @@
   end
 
   unless(WINDOWS) # no symlinks on Windows
+    def test_chmod
+      File.unlink("build.xml#{NTC}") if File.exist? "build.xml#{NTC}"
+      FileUtils.copy_file("build.xml", "build.xml#{NTC}")
+      m1 = File.stat("build.xml#{NTC}").mode
+      File.chmod 0700, "build.xml#{NTC}"
+      assert_not_equal m1, File.stat("build.xml#{NTC}").mode
+    end
+
+    # TODO: this is a new test but failing on my machine. Should it work?
+    # You may simply remove or outcomment it
+    def test_readlink
+      File.unlink("build.xml.link#{NTC}") if File.exist? "build.xml.link#{NTC}"
+      FileUtils.copy_file("build.xml", "build.xml#{NTC}")
+      File.readlink("build.xml#{NTC}")
+    ensure
+      File.unlink "build.xml#{NTC}"
+    end
+
     def test_file_symlink
       # Test File.symlink? if possible
-      system("ln -s build.xml build.xml.link")
-      if File.exist? "build.xml.link"
-        assert(File.symlink?("build.xml.link"))
-        # JRUBY-683 -  Test that symlinks don't effect Dir and File.expand_path
-        assert_equal(['build.xml.link'], Dir['build.xml.link'])
-        assert_equal(File.expand_path('.') + '/build.xml.link', File.expand_path('build.xml.link'))
-        File.delete("build.xml.link")
-      end
+      #system("ln -s build.xml build.xml.link#{NTC}")
+      File.unlink "build.xml.link#{NTC}" if File.exist? "build.xml.link#{NTC}"
+      File.symlink "build.xml", "build.xml.link#{NTC}"
+
+      assert(File.symlink?("build.xml.link#{NTC}"))
+      # JRUBY-683 -  Test that symlinks don't effect Dir and File.expand_path
+      assert_equal(["build.xml.link#{NTC}"], Dir["build.xml.link#{NTC}"])
+      assert_equal(File.expand_path('.') + "/build.xml.link#{NTC}", File.expand_path("build.xml.link#{NTC}"))
+      File.delete("build.xml.link#{NTC}")
+      assert !File.exist?("build.xml.link#{NTC}")
     end
   end
 
   def test_file_times
     # Note: atime, mtime, ctime are all implemented using modification time
+
+    begin
+      FileUtils.copy_file("build.xml", "build.xml#{NTC}")
+      assert File.exist? "build.xml#{NTC}"
+
+      assert_nothing_raised {
+        File.mtime("build.xml#{NTC}")
+        File.atime("build.xml#{NTC}")
+        File.ctime("build.xml#{NTC}")
+        File.new("build.xml#{NTC}").mtime
+        File.new("build.xml#{NTC}").atime
+        File.new("build.xml#{NTC}").ctime
+      }
+    ensure
+      File.unlink("build.xml#{NTC}")
+    end
+
     assert_nothing_raised {
       File.mtime("build.xml")
       File.atime("build.xml")
@@ -648,7 +748,7 @@
 
   def test_truncate
     # JRUBY-1025: negative int passed to truncate should raise EINVAL
-    filename = "__truncate_test_file"
+    filename = "__truncate_test_file#{NTC}"
     assert_raises(Errno::EINVAL) {
       begin
         f = File.open(filename, 'w')
@@ -664,9 +764,9 @@
     File.delete(filename)
   end
 
-  def test_file_utf8
+  def test_file_unicode
     # name contains a German "umlaut", maybe this should be encoded as Unicode integer (\u00FC) somehow
-    filename = 'jrüby'  
+    filename = "jr#{NTC}by"  
     f = File.new(filename, File::CREAT)
     begin
       assert_equal(nil, f.read(1))
@@ -720,7 +820,7 @@
   end
 
   def test_flock
-    filename = '__lock_test__'
+    filename = "__lock_test#{NTC}__"
     file = File.open(filename,'w')
     file.flock(File::LOCK_EX | File::LOCK_NB)
     assert_equal(0, file.flock(File::LOCK_UN | File::LOCK_NB))
@@ -730,7 +830,7 @@
 
   # JRUBY-1214
   def test_flock_exclusive_on_readonly
-    filename = '__lock_test_2_'
+    filename = "__lock_test#{NTC}_2_"
     File.open(filename, "w+") { }
     File.open(filename, "r") do |file|
       begin
@@ -745,7 +845,7 @@
   end
 
   def test_truncate_doesnt_create_file
-    name = "___foo_bar___"
+    name = "___foo_bar#{NTC}___"
     assert(!File.exists?(name))
 
     assert_raises(Errno::ENOENT) { File.truncate(name, 100) }
@@ -755,7 +855,7 @@
 
   # JRUBY-2340
   def test_opening_readonly_file_for_write_raises_eacces
-    filename = "__read_only__"
+    filename = "__read_only#{NTC}__"
 
     begin
       File.open(filename, "w+", 0444) { }
@@ -767,6 +867,11 @@
   
   # JRUBY-2397
   unless(WINDOWS)
+    def test_chown_unicode
+      FileUtils.copy_file "build.xml", "build.xml#{NTC}"
+      assert_equal(1, File.chown(-1, -1, "build.xml#{NTC}"))
+    end
+
     def test_chown_accepts_nil_and_minus_one
       # chown
       assert_equal(1, File.chown(-1, -1, 'build.xml'))
