groovy

@Deprecated does not have effect in Groovy

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.5.1
  • Fix Version/s: 1.6.4, 1.7-beta-1
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    1

Description

I have create a class in Groovy:

public class AClass
{
@Deprecated public void foo() { System.out.println("foo"); }
}

I compiled it using groovyc

groovyc AClass.groovy

Now I created a Java class as shown below:
class Test
{
public static void main(String[] args)

{ AClass obj = new AClass(); obj.foo(); }

}

When I compile the Java code

javac Test.java

I don't get any deprecation warnings.

If I compile AClass.groovy using javac (after copying to AClass.java) and then compile Test.java using javac, I get a deprecation warning.

Activity

Hide
Paul King added a comment -

Proposed patch. Jochen (and others), any thoughts?
OK to not make modifiers final in ClassNode?
I have been holding off but seems the best way to solve this.
Do we need any special treatment for properties?
Should we have a flag and indicate with a warning if we encounter a deprecated node like javac does?
And support a mode like javac's -deprecation to warm for them all?

Show
Paul King added a comment - Proposed patch. Jochen (and others), any thoughts? OK to not make modifiers final in ClassNode? I have been holding off but seems the best way to solve this. Do we need any special treatment for properties? Should we have a flag and indicate with a warning if we encounter a deprecated node like javac does? And support a mode like javac's -deprecation to warm for them all?
Hide
blackdrag blackdrag added a comment -

if (visited.getClassNode().getTypeClass() == Deprecated.class)

this code is not safe, and will lead possible lead to an exception if the ClassNode is a primary one. You have to check visited.getClassNode().isResolved() here first. Also the warning comment is wrong, since in javac it is the usage of deprecated methods, that causes the warning, not declaring a method as such.

Show
blackdrag blackdrag added a comment - if (visited.getClassNode().getTypeClass() == Deprecated.class) this code is not safe, and will lead possible lead to an exception if the ClassNode is a primary one. You have to check visited.getClassNode().isResolved() here first. Also the warning comment is wrong, since in javac it is the usage of deprecated methods, that causes the warning, not declaring a method as such.
Hide
Paul King added a comment -

Yes, of course. Will amend the code and move the TODO comment to the appropriate place.

Show
Paul King added a comment - Yes, of course. Will amend the code and move the TODO comment to the appropriate place.
Hide
Paul King added a comment -

Fixed. Thanks for raising the issue.

Show
Paul King added a comment - Fixed. Thanks for raising the issue.
Hide
Peter Niederwieser added a comment -

I think it's worthwhile to note that this style of comparison is only safe for JDK classes. For other classes it will fail in environments where an isolated class loader is used for resolving types (e.g. GMaven). A safer idiom is visited.getClassNode().getTypeClass().getName().equals(Deprecated.class.getName()).

Show
Peter Niederwieser added a comment - I think it's worthwhile to note that this style of comparison is only safe for JDK classes. For other classes it will fail in environments where an isolated class loader is used for resolving types (e.g. GMaven). A safer idiom is visited.getClassNode().getTypeClass().getName().equals(Deprecated.class.getName()).
Hide
Paul King added a comment -

Good point. I'll amend accordingly.

Show
Paul King added a comment - Good point. I'll amend accordingly.
Hide
Paul King added a comment -

reopen pending suggested refactor

Show
Paul King added a comment - reopen pending suggested refactor
Hide
Paul King added a comment -

suggested refactoring applied

Show
Paul King added a comment - suggested refactoring applied

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: