United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6996914 Diamond inference: problem when accessing protected constructor
JDK-6996914 : Diamond inference: problem when accessing protected constructor

Details
Type:
Bug
Submit Date:
2010-11-02
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
tools
OS:
linux,generic
Sub-Component:
javac
CPU:
x86,unknown
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Duplicate:

Sub Tasks

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
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
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
EVALUATION

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



Hardware and Software, Engineered to Work Together