Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 337799 - [1.7][compiler][varargs] Eclipse fails to report error on incorrect SafeVarargs usage
Summary: [1.7][compiler][varargs] Eclipse fails to report error on incorrect SafeVarar...
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7.1   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-22 04:24 EST by Srikanth Sankaran CLA
Modified: 2015-02-10 08:44 EST (History)
3 users (show)

See Also:


Attachments
Patch under test (8.79 KB, patch)
2011-02-22 07:41 EST, Srikanth Sankaran CLA
no flags Details | Diff
Revised patch. (12.83 KB, patch)
2011-02-22 09:50 EST, Srikanth Sankaran CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Srikanth Sankaran CLA 2011-02-22 04:24:50 EST
The following program is supposed to elicit two compiler
errors on the application of the SafeVarargs annotation
to (a) a non varargs method (b) a non final instance method.
javac correctly complains on these while eclipse fails to.

import java.util.List;
public class X {
	@SafeVarargs
	public static <T> List<T> asList() {  // Error, not varargs
		return null;
	}
	@SafeVarargs
	public <T> List<T> asList2(T ... a) {    // error not static or final
		return null;
	}
	@SafeVarargs
	public static <T> List<T> asList3(T ... a) {  // OK, varargs & static
		return null;
	}
	@SafeVarargs
	public final <T> List<T> asList4(T ... a) {  // OK varargs & final
		return null;
	}
	@SafeVarargs
	public final static <T> List<T> asList5(T ... a) {  // OK, varargs & static & final
		return null;
	}
}
Comment 1 Srikanth Sankaran CLA 2011-02-22 07:41:37 EST
Created attachment 189480 [details]
Patch under test
Comment 2 Srikanth Sankaran CLA 2011-02-22 09:50:20 EST
Created attachment 189497 [details]
Revised patch.

This revised patch

    - extends the treatment to constructors also.
    - massages an existing test case that was "failing" due to expected
      output differing due to new IProblem introduction.
    - Adds suitable copyright message
    - Adds more tests
    - Passes all tests
Comment 3 Srikanth Sankaran CLA 2011-02-22 10:14:04 EST
Released the patch on the BETA_JAVA7 branch.
Comment 4 Srikanth Sankaran CLA 2011-02-22 10:33:56 EST
Resolved.
Comment 5 Olivier Thomann CLA 2011-06-28 09:14:03 EDT
Verified.
Comment 6 Christian Damus CLA 2015-02-10 08:44:58 EST
On the subject of the @SafeVarArgs on non-final instance methods:  I get the error (b) from comment 0 on a method in a final class (which happens to be a static nested class) that is not, itself, declared as final because that would be redundant.  All methods of a final class are effectively final, so why is this error presented on the "add(...)" method below?

    public static final class ImmutableEListBuilder<E> {
        
        // ...

        @SafeVarargs
        public ImmutableEListBuilder<E> add(E element1, E element2, E element3, E element4, E... elements) {
            // ...
        }