JDK-6996914 : Diamond inference: problem when accessing protected constructor
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,linux
  • CPU: unknown,x86
  • Submitted: 2010-11-02
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b120Fixed
Related Reports
Duplicate :  
Description
The following code does not compile:

import java.nio.file.*;

public final class _DiamondSyntaxErrors {
  public interface InterfaceA<T> {
  }

  public abstract static class ClassA<T>
      implements InterfaceA<T> {
    protected ClassA() {
    }
  }

  public static void main(String... args) {
    // no error
    InterfaceA<Path> classA = new ClassA<>() {
    };

    // error: cannot infer type arguments for SimpleFileVisitor<>
    FileVisitor<Path> visitor = new SimpleFileVisitor<>() {
    };
  }
}

Javac prints the following output:

Test.java:5: cannot infer type arguments for SimpleFileVisitor<>
        FileVisitor<Path> visitor = new SimpleFileVisitor<>() {
                                    ^
1 error

Comments
EVALUATION http://hg.openjdk.java.net/jdk7/build/langtools/rev/bce19889597e
2010-12-04

EVALUATION The problem is caused by the fact that when constructors of the target type are added to the synthetic scopes, access modifier should be adjusted accordingly - an anonymous inner class creation expression is allowed to access protected constructors in the superclass.
2010-11-11

SUGGESTED FIX A webrev of this fix is available at the following URL: http://hg.openjdk.java.net/jdk7/tl/langtools/rev/bce19889597e
2010-11-11