Bug 97220 - Should not issue nls warning for annotation
Summary: Should not issue nls warning for annotation
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.1.1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 98217 102130 119269 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-05-30 07:03 EDT by Jerome Lanneluc CLA
Modified: 2011-08-03 14:05 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jerome Lanneluc CLA 2005-05-30 07:03:19 EDT
3.1 RC1

In the following case, we issue a 'Non-externalized string literal' warning for
"deprecation":
@SuppressWarnings("deprecation")
public class X {
}

However this is always a constant (and will never be externalized). We should
not issue a 'Non-externalized string literal' warning here (and for any
annotation in general).
Comment 1 Philipe Mulet CLA 2005-05-30 10:57:55 EDT
Olivier - how much changes would this take ? depending on it, we could consider
this for RC2.
Comment 2 Olivier Thomann CLA 2005-05-30 13:38:31 EDT
This doesn't look trivial as the non externalized string checking is done
without any context. In order to fix this, we would need to disable in within
the SuppressWarnings annotation.
So this would require to move that check later (after type resolution).
Comment 3 Olivier Thomann CLA 2005-05-30 14:28:01 EDT
Will reconsider post 3.1.
Comment 4 Olivier Thomann CLA 2005-06-02 21:20:46 EDT
*** Bug 98217 has been marked as a duplicate of this bug. ***
Comment 5 Frederic Fusier CLA 2005-06-29 10:35:24 EDT
*** Bug 102130 has been marked as a duplicate of this bug. ***
Comment 6 Philipe Mulet CLA 2005-06-29 14:57:05 EDT
reopen
Comment 7 Olivier Thomann CLA 2005-06-30 12:45:38 EDT
Fixed and released in 3.1 maintenance.
Regression tests added in
org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest.test169-173.
Comment 8 Olivier Thomann CLA 2005-07-01 12:12:11 EDT
The support has been added only for the SuppressWarnings annotation. For others,
the compiler cannot make assumptions on the fact that a string should be
externalized or not.
We can imagine for example a Copyright annotation. You might want to provide a
translated version of the copyright.
@interface Copyright {
   String message();
}

Copyright(message="Copyright in English") .....

The user might want to translate this one. If I add the support for all
annotations, then this won't need to be tagged as a non-nls string by the user.
Comment 9 Olivier Thomann CLA 2005-07-01 12:12:34 EDT
Update title accordingly.
Comment 10 Philipe Mulet CLA 2005-07-01 13:14:06 EDT
Only constant values can be specified on annotation attributes, so it should not
be restricted to @SuppressWarnings.
Comment 11 Olivier Thomann CLA 2005-07-04 18:04:35 EDT
Fixed and released in HEAD.
All annotations are supported.
Regression tests added in
org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest.test169-176
Comment 12 Jerome Lanneluc CLA 2005-08-09 12:46:14 EDT
Verified with 3.2 M1
Comment 13 Nick Crossley CLA 2005-09-19 06:11:39 EDT
I think the fix is incomplete.

Although literal strings in the uses of annotations need no longer be marked 
with a non-nls comment, the uses of strings in default clauses in the 
declaration of annotations still generate NLS warnings.

For example, consider this case:

import java.lang.annotation.*;

@Target({ElementType.TYPE, ElementType.FIELD, ElementType.METHOD,
         ElementType.PARAMETER, ElementType.CONSTRUCTOR,
         ElementType.LOCAL_VARIABLE, ElementType.PACKAGE})
@Retention(RetentionPolicy.CLASS)
public @interface MySuppressWarnings
{
    String[] value() default {};
    String justification() default "";
}

The declaration of 'justification' gives an NLS warning in 3.2M1.
Since default strings must be constant expressions, the warning is not 
appropriate.
Comment 14 Olivier Thomann CLA 2005-09-26 11:20:58 EDT
I opened bug 110613 for this last issue. It resides in annotation type
declaration and not within the usage of annotation.
Comment 15 Maxime Daniel CLA 2005-09-26 11:31:24 EDT
I believe that comment#13 should be the subject of a specific bug, since it
applies to a use case that is quite a bit different (the focus being on the
annotation declaration instead of the annotation use site).

As far as the initial bug is concerned:
Verified for 3.1.1 using build M20050923-1430.
Comment 16 Maxime Daniel CLA 2005-09-26 11:32:48 EDT
(Collision -- agree with Olivier and IMHO this one is verified for 3.1.1.)
Comment 17 Olivier Thomann CLA 2005-09-26 11:34:31 EDT
Verified for 3.1.1 using M20050923-1430.
Comment 18 Markus Keller CLA 2011-08-03 14:05:22 EDT
*** Bug 119269 has been marked as a duplicate of this bug. ***