2
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
26
* @summary Javac doesn't report errors on service implementation which cannot be initialized
29
* jdk.compiler/com.sun.tools.javac.api
30
* jdk.compiler/com.sun.tools.javac.main
31
* jdk.jdeps/com.sun.tools.javap
32
* @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
33
* @run main AbstractOrInnerClassServiceImplTest
36
import java.nio.file.Files;
37
import java.nio.file.Path;
39
import toolbox.JavacTask;
41
import toolbox.ToolBox;
43
public class AbstractOrInnerClassServiceImplTest extends ModuleTestBase {
44
public static void main(String... args) throws Exception {
45
AbstractOrInnerClassServiceImplTest t = new AbstractOrInnerClassServiceImplTest();
50
public void testAbstractServiceImpl(Path base) throws Exception {
51
Path src = base.resolve("src");
52
tb.writeJavaFiles(src,
53
"module m { provides p1.Service with p2.Impl; }",
54
"package p1; public interface Service { }",
55
"package p2; public interface Impl extends p1.Service { }");
56
Path classes = base.resolve("classes");
57
Files.createDirectories(classes);
59
String log = new JavacTask(tb)
60
.options("-XDrawDiagnostics")
62
.files(findJavaFiles(src))
63
.run(Task.Expect.FAIL)
65
.getOutput(Task.OutputKind.DIRECT);
66
if (!log.contains("module-info.java:1:39: compiler.err.service.implementation.is.abstract: p2.Impl"))
67
throw new Exception("expected output not found");
71
public void testInnerClassServiceImpl(Path base) throws Exception {
72
Path src = base.resolve("src");
73
tb.writeJavaFiles(src,
74
"module m { provides p1.Service with p2.Outer.Inner; }",
75
"package p1; public interface Service { }",
76
"package p2; public class Outer { public class Inner implements p1.Service {} }");
77
Path classes = base.resolve("classes");
78
Files.createDirectories(classes);
80
String log = new JavacTask(tb)
81
.options("-XDrawDiagnostics")
83
.files(findJavaFiles(src))
84
.run(Task.Expect.FAIL)
86
.getOutput(Task.OutputKind.DIRECT);
87
if (!log.contains("module-info.java:1:45: compiler.err.service.implementation.is.inner: p2.Outer.Inner"))
88
throw new Exception("expected output not found");
92
public void testInnerInterfaceServiceImpl(Path base) throws Exception {
93
Path src = base.resolve("src");
94
tb.writeJavaFiles(src,
95
"module m { provides p1.Service with p2.Outer.Inner; }",
96
"package p1; public interface Service { }",
97
"package p2; public class Outer { public interface Inner extends p1.Service {} }");
98
Path classes = base.resolve("classes");
99
Files.createDirectories(classes);
101
String log = new JavacTask(tb)
102
.options("-XDrawDiagnostics")
104
.files(findJavaFiles(src))
105
.run(Task.Expect.FAIL)
107
.getOutput(Task.OutputKind.DIRECT);
108
if (!log.contains("module-info.java:1:45: compiler.err.service.implementation.is.abstract: p2.Outer.Inner"))
109
throw new Exception("expected output not found");