[ 
https://issues.apache.org/jira/browse/GROOVY-8044?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15821790#comment-15821790
 ] 

Jochen Theodorou commented on GROOVY-8044:
------------------------------------------

it is not so easy to explain, it is an issue of the grammar. 
"de.my.package.lib.myJavaFile theJavaFile = new de.my.package.lib.myJavaFile()" 
is in Groovy a valid method call. It asks the property de, for a property my, 
for a property package, for a propery lib for a method myJavaFile and executes 
it with a variable of name theJavaFile, to which it did = new 
de.my.package.lib.myJavaFile() before. And in this new-instance expression 
Groovy knows it must be a class  Your special case with assignment might be 
solvable though if we disallow the assignment in a method call expression. So 
maybe we can solve your issue by removing a rule in the grammar. Something like 
"de.my.package.lib.myJavaFile theJavaFile" would stay problematic though.

> MissingPropertyException for java style local variables
> -------------------------------------------------------
>
>                 Key: GROOVY-8044
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8044
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-runtime
>    Affects Versions: 2.4.7
>         Environment: KUbuntu16.10 but also present on Windows 7, Mac OS 10.9.5
>            Reporter: MeFisto94
>              Labels: newbie
>
> Hey Guys,
> First off: Sorry if this is a fault on my side but I highly doubt it.
> I am using Groovy to compile java and groovy files on the fly to use them as 
> regular Class instances.
> I use my implementation of GroovyResourceLoader but I can confirm that it 
> works, since if I break it purposely, Groovy complains about unknown class 
> definitions during compile-time (of the script).
> So what happens is that I can successfully instantiate the freshly loaded 
> class but as soon as I call a method which has a java style definition, it 
> crashes during runtime.
> So a few examples:
> {code}
> @Override
>     public URL loadGroovySource(String fileName) throws MalformedURLException 
> {
>         if (fileName.startsWith("de.my.packages")) {
>             String className = 
> fileName.substring("de.my.packages".length()).replace('.', '/');
>             
>             for (String extension : new String[] { ".java", ".groovy" }) {
>                 File classFile = new File(basicPath, className + extension);
>                 if (classFile.exists()) {
>                     System.out.println("FOUND " + 
> classFile.getAbsolutePath());
>                     return classFile.toURI().toURL();
>                 }
>             }
>         }
>         
>         return null;
>     }
> {code}
> Please ignore the fact that the variable names are misleading. Actually 
> fileName should be className and className should be fileName...
> Now the code to get those Classes:
> {code}
> groovyClassLoader = new 
> GroovyClassLoader(Thread.currentThread().getContextClassLoader());
> groovyClassLoader.setResourceLoader(new CustomGroovyResourceLoader(current));
> File f = new File(filePath);
> if (!f.exists()) {
>   throw new FileNotFoundException(filePath);
> }   
> return groovyClassLoader.parseClass(f);
> {code}
> The error now is:
> {code}
> No such property: de for class: de.my.package.script2
> Possible solutions: name
> groovy.lang.MissingPropertyException: No such property: de for class: 
> de.my.package.script2
> Possible solutions: name
>         at 
> org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53)
>         at 
> org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GetEffectivePogoPropertySite.java:87)
>         at 
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307)
>         at de.my.package.script2.getInterfaceVersion(script2.java:27)
>         at java.lang.Thread.run(Thread.java:745)
> No such property: de for class: de.my.package.script2
> Possible solutions: name
> {code}
> Now my actual script file looks like this at that line:
> {code}
> de.my.package.lib.myJavaFile theJavaFile = new de.my.package.lib.myJavaFile();
> {code}
> This means that for some reason during runtime it quits after the . of de.
> Initially the code looked like this though:
> {code}
> myJavaFile theJavaFile = new myJavaFile();
> {code}
> This lead to the same Exception, I tried specifying the correct package 
> manually to rule out some errors with the resolution (Groovy definately knows 
> the myJavaFile class because parseClass would fail).
> Please note that my package isn't really "de.my.package", since package is a 
> reserved keyword but I had to edit it out.
> What does work is "def theJavaFile = new myJavaFile();".
> What ALSO works is the java style definition for files available through the 
> classpath (e.g. conventional code, anything from java.lang, ...)
> Am I probably missing some compilersettings to allow java compability?
> Thanks in Advance



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to