Issue Details (XML | Word | Printable)

Key: GROOVY-1464
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Paul King
Reporter: Ken Barclay
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
groovy

Optional interface modifier

Created: 17/Aug/06 07:52 AM   Updated: 08/Feb/08 01:26 AM
Component/s: command line processing
Affects Version/s: 1.0-JSR-6
Fix Version/s: 1.5.2

Time Tracking:
Not Specified

File Attachments: 1. Zip Archive bug1464.zip (0.8 kB)
2. Text File interface.modifiers.9.1.2.groovy (0.3 kB)

Environment: Win XP


 Description  « Hide
The optional modifier on an interface declaration is prepared to accept ANY Groovy modifier including private, static, transient, etc.

 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Paul King added a comment - 01/Dec/06 06:31 AM
transient and static are definitely bugs but private should be OK shouldn't it?

Andres Almiray added a comment - 28/Nov/07 06:28 PM
Looks like only 'final' and 'transient' are detected at compile time. 'abstract','static' and 'synchronized' are allowed but those modifiers are meaningless IMO. On top level interfaces there is no point in declaring an access modifier other than public but it does on inner interfaces (not yet supported) so using protected/private on them should at least give a warning for the time being?
bash-3.2$ groovyc AI.groovy
bash-3.2$ groovyc FI.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,
FI.groovy: 1: The interface 'FI' must not be final. It is by definition abstract
.
 @ line 1, column 7.
   final interface FI {}
         ^

1 error

bash-3.2$ groovyc SI.groovy
bash-3.2$ groovyc TI.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed,
TI.groovy: 1: The interface 'TI' has an incorrect modifier transient.
 @ line 1, column 11.
   transient interface TI {}
             ^

1 error

bash-3.2$ groovyc YI.groovy
bash-3.2$

Paul King added a comment - 23/Dec/07 08:16 PM
Added 'native' to the list of detected and ruled out modifiers. I attempted to add 'synchronized' but one of the tests fails. Soem of our intermediate generated classes may accidentally have this bit set. I think we can add this back in once we work out where this is occurring. For reference, the script below fails with the error message shown when trying to compile if I add the synchronized check in, so it is commented out at the moment:

Script:

interface A {
    def foo = 1
}
class B implements A {
    def foo() {foo}
}
assert new B().foo() == 1

Error:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, C:\testScript.groovy: -1: The class 'A$1' has an incorrect modifier synchronized.
 @ line -1, column -1.
1 error

Paul King added a comment - 24/Dec/07 03:35 AM
OK, synchronized is added to. That just about wraps up the essential items for this issue. There are other unused modifiers at the moment but they are happily ignored and if we end up supporting inner classes, then they will all come into play.

I did notice however that you can have invalid modifiers in interface methods. So, I'll add that in and then I think we can close this issue. Here is what you can currently have:

interface Foo {
   def strictfp /*native*/ volatile synchronized doit( String param, int o )
}

If you use native Java complains. Groovy happily ignores the other values even though they never make sense here.


Paul King added a comment - 24/Dec/07 07:36 PM
I think there are now error messages for all the obvious candidates. There are some which we don't deal with at the moment but hope to over time, e.g. a private Interface may make sense inside a Script ... one day. And we may support inner/nested classes/interfaces one day too.

Paul King added a comment - 08/Feb/08 01:26 AM
close off release 1.5.4