25 messages in org.codehaus.groovy.userRe: [groovy-user] File encoding problem
FromSent OnAttachments
Michael BaehrMar 23, 2007 7:25 am 
Guillaume LaforgeMar 23, 2007 9:31 am 
Michael BaehrMar 23, 2007 9:57 am 
Guillaume LaforgeMar 23, 2007 10:07 am 
Michael BaehrMar 23, 2007 10:16 am 
Guillaume LaforgeMar 23, 2007 10:20 am 
Michael BaehrMar 23, 2007 10:24 am 
Guillaume LaforgeMar 23, 2007 12:19 pm 
Michael BaehrMar 23, 2007 12:36 pm.groovy
Russel WinderMar 23, 2007 12:41 pm 
Guillaume LaforgeMar 23, 2007 12:47 pm 
Michael BaehrMar 23, 2007 12:52 pm 
Russel WinderMar 23, 2007 12:53 pm 
Michael BaehrMar 23, 2007 12:54 pm 
Russel WinderMar 23, 2007 12:58 pm 
Michael BaehrMar 23, 2007 1:01 pm 
Russel WinderMar 23, 2007 1:04 pm 
Michael BaehrMar 23, 2007 1:05 pm 
Russel WinderMar 23, 2007 1:06 pm 
Michael BaehrMar 23, 2007 1:24 pm 
Russel WinderMar 23, 2007 1:31 pm 
Michael BaehrMar 23, 2007 1:40 pm 
Gavin GroverMar 23, 2007 4:51 pm 
Barzilai SpinakMar 23, 2007 6:39 pm 
Jochen TheodorouMar 25, 2007 9:59 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [groovy-user] File encoding problemActions...
From:Jochen Theodorou (blac@gmx.org)
Date:Mar 25, 2007 9:59:26 am
List:org.codehaus.groovy.user

Barzilai Spinak schrieb: [...]

D:\temp>ren utf8.groovy utf8.groovy.OLD D:\temp>groovy utf8 Caught: java.io.FileNotFoundException: utf8 (D:\temp\utf8)

See? *EVEN THOUGH* it has a completely valid .class file, it tries to look for the source .groovy file and it fails after not finding it.

I think recompilation is off by default, so it should use the .class file. But the above is clearly an error, because the .grovoy file is the fall back for a non existing .class file, which means groovy can't find the .class file as well here. You are sure it was there?

[...]

2) Second tests, execute the "groovy" command specifying the encoding. D:\temp>ren utf8.groovy utf8.groovy.otra

D:\temp>groovy -c utf8 utf8 Caught: BUG! exception in phase 'parsing' in source unit 'utf8.groovy' charsetName

D:\temp>groovy --encoding utf8 utf8 Caught: BUG! exception in phase 'parsing' in source unit 'utf8.groovy' charsetName

(And other attempts to specify an encoding)

The problem here: a) If it didn't try to parse/compile anything (since it's already compiled and up to date!), this problem would not happen.

I agree partially... even if it recompiles, there should be no problem with the charset name.... would be nice of you to post a bigger trace for this (run groovy with -d)

b) The --encoding or -c options are *ignored* or not passed down to "groovyc" (maybe groovyStarter doesn't know what to do with it?).

I don't think it is the fault of groovyc or groovyStarter.

As Michael discovered, it can be "fixed" by setting JAVA_OPTS=-Dfile.encoding=UTF-8 since that will change the default encoding for the compiler AND the Java Virtual Machine.

I think we should more ask how file.encoding does take effect. It effects the default encoding used by the java api for reader and inputstreams. And of course the groovy compilers uses this api. But should it really affect the compiler? Normally the compiler should use the encoding given to him, but since file.encoding takes effect it means that there are places where the compiler does not use an explicit encoding, therefor the configuration we gave in with the --encoding option is naturally ignored.

I see a suspicous line in GroovyClassLoader:

su = unit.addSource(codeSource.getName(), codeSource.getInputStream());

getInputStream is implemented as:

public InputStream getInputStream() { try { if (file!=null) return new FileInputStream(file); } catch (FileNotFoundException fnfe) {} return inputStream; }

so if file is not null, we will create a new FileInputStream *using the default encoding*. A big bug!

This does of course not explain the problem with not calling a .class file, but it exaplains the prolem with the encoing.

bye blackdrag