Mon, 16 Sep 2013 14:13:44 +0200
8021112: Spurious unchecked warning reported by javac
6480588: No way to suppress deprecation warnings when implementing deprecated interface
Summary: Fixing DeferredLintHandler configuration, so lint warnings are reported with correct @SuppressWarnings settings
Reviewed-by: jjg, vromero
duke@1 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2006, 2008, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@1 | 7 | * published by the Free Software Foundation. |
duke@1 | 8 | * |
duke@1 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 13 | * accompanied this code). |
duke@1 | 14 | * |
duke@1 | 15 | * You should have received a copy of the GNU General Public License version |
duke@1 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
duke@1 | 22 | */ |
duke@1 | 23 | |
duke@1 | 24 | /* |
duke@1 | 25 | * @test |
duke@1 | 26 | * @bug 6348193 |
duke@1 | 27 | * @summary AS8.1 UR2 BAT test failure with "javac" |
duke@1 | 28 | * @compile -proc:none T6348193.java |
duke@1 | 29 | * @run main/othervm T6348193 |
duke@1 | 30 | */ |
duke@1 | 31 | |
duke@1 | 32 | import java.io.*; |
duke@1 | 33 | import java.net.*; |
duke@1 | 34 | import java.util.*; |
duke@1 | 35 | import javax.annotation.processing.*; |
duke@1 | 36 | import javax.lang.model.element.*; |
duke@1 | 37 | import javax.tools.*; |
duke@1 | 38 | import com.sun.tools.javac.api.JavacTool; |
duke@1 | 39 | |
duke@1 | 40 | @SupportedAnnotationTypes({"*"}) |
duke@1 | 41 | public class T6348193 extends AbstractProcessor |
duke@1 | 42 | { |
duke@1 | 43 | private static final boolean verbose = true; |
duke@1 | 44 | |
duke@1 | 45 | enum NoYes { NO, YES }; |
duke@1 | 46 | enum NoGoodBad { NO, GOOD, BAD}; |
duke@1 | 47 | |
duke@1 | 48 | public static final String myName = T6348193.class.getName(); |
duke@1 | 49 | |
duke@1 | 50 | public static void main(String... args) throws IOException { |
duke@1 | 51 | if (System.getSecurityManager() != null) |
duke@1 | 52 | throw new AssertionError("unexpected security manager"); |
duke@1 | 53 | |
duke@1 | 54 | for (NoYes secMgr: EnumSet.allOf(NoYes.class)) |
duke@1 | 55 | for (NoGoodBad config: EnumSet.allOf(NoGoodBad.class)) |
duke@1 | 56 | for (NoYes proc: EnumSet.allOf(NoYes.class)) |
duke@1 | 57 | test(secMgr, config, proc); |
duke@1 | 58 | } |
duke@1 | 59 | |
duke@1 | 60 | private static File processed = new File("processed"); |
duke@1 | 61 | |
duke@1 | 62 | public static void test(NoYes secMgr, NoGoodBad config, NoYes proc) throws IOException { |
duke@1 | 63 | if (verbose) |
duke@1 | 64 | System.err.println("secMgr:" + secMgr + " config:" + config + " proc:" + proc); |
duke@1 | 65 | |
duke@1 | 66 | if (secMgr == NoYes.YES && System.getSecurityManager() == null) |
duke@1 | 67 | System.setSecurityManager(new NoLoaderSecurityManager()); |
duke@1 | 68 | |
duke@1 | 69 | installConfigFile(config); |
duke@1 | 70 | |
duke@1 | 71 | processed.delete(); |
duke@1 | 72 | |
duke@1 | 73 | List<String> args = new ArrayList<String>(); |
duke@1 | 74 | //args.add("-XprintRounds"); |
duke@1 | 75 | if (proc == NoYes.YES) { |
duke@1 | 76 | args.add("-processor"); |
duke@1 | 77 | args.add(myName); |
duke@1 | 78 | } |
duke@1 | 79 | args.add("-processorpath"); |
duke@1 | 80 | args.add(System.getProperty("java.class.path")); |
duke@1 | 81 | args.add("-d"); |
duke@1 | 82 | args.add("."); |
duke@1 | 83 | |
duke@1 | 84 | JavacTool t = JavacTool.create(); // avoid using class loader |
duke@1 | 85 | |
duke@1 | 86 | MyDiagListener dl = new MyDiagListener(); |
duke@1 | 87 | PrintWriter out = new PrintWriter(System.err, true); |
duke@1 | 88 | StandardJavaFileManager fm = t.getStandardFileManager(dl, null, null); |
duke@1 | 89 | File file = new File(System.getProperty("test.src"), myName+".java"); |
duke@1 | 90 | Iterable<? extends JavaFileObject> files = |
duke@1 | 91 | fm.getJavaFileObjectsFromFiles(Arrays.asList(file)); |
duke@1 | 92 | boolean ok = t.getTask(out, null, dl, args, null, files).call(); |
duke@1 | 93 | |
duke@1 | 94 | if (config == NoGoodBad.GOOD || proc == NoYes.YES) { |
duke@1 | 95 | if (secMgr == NoYes.YES) { |
duke@1 | 96 | if (dl.last == null) |
duke@1 | 97 | throw new AssertionError("Security manager installed, and processors present, " |
duke@1 | 98 | + " but no diagnostic received"); |
duke@1 | 99 | } |
duke@1 | 100 | else { |
duke@1 | 101 | if (!processed.exists()) |
duke@1 | 102 | throw new AssertionError("No security manager installed, and processors present, " |
duke@1 | 103 | + " but no processing occurred"); |
duke@1 | 104 | } |
duke@1 | 105 | } |
duke@1 | 106 | else if (config == NoGoodBad.BAD) { |
duke@1 | 107 | // TODO: should verify that no compiler crash occurred |
duke@1 | 108 | // needs revised JSR199 spec |
duke@1 | 109 | } |
duke@1 | 110 | else { |
duke@1 | 111 | if (processed.exists()) |
duke@1 | 112 | throw new AssertionError("No processors present, but processing occurred!"); |
duke@1 | 113 | } |
duke@1 | 114 | |
duke@1 | 115 | if (verbose) |
duke@1 | 116 | System.err.println("OK"); |
duke@1 | 117 | } |
duke@1 | 118 | |
duke@1 | 119 | // set up or remove a service configuration file |
duke@1 | 120 | static void installConfigFile(NoGoodBad type) throws IOException { |
jjg@143 | 121 | File f = new File(System.getProperty("test.classes", ".")); |
duke@1 | 122 | for (String s: new String[] { "META-INF", "services", Processor.class.getName() }) |
duke@1 | 123 | f = new File(f, s); |
duke@1 | 124 | BufferedWriter out; |
duke@1 | 125 | switch (type) { |
duke@1 | 126 | case GOOD: |
duke@1 | 127 | f.getParentFile().mkdirs(); |
duke@1 | 128 | out = new BufferedWriter(new FileWriter(f)); |
duke@1 | 129 | out.write(myName); |
duke@1 | 130 | out.newLine(); |
duke@1 | 131 | out.close(); |
duke@1 | 132 | break; |
duke@1 | 133 | case BAD: |
duke@1 | 134 | f.getParentFile().mkdirs(); |
duke@1 | 135 | out = new BufferedWriter(new FileWriter(f)); |
duke@1 | 136 | out.write("This is not a valid line"); |
duke@1 | 137 | out.newLine(); |
duke@1 | 138 | out.close(); |
duke@1 | 139 | break; |
duke@1 | 140 | case NO: |
duke@1 | 141 | f.delete(); |
duke@1 | 142 | } |
duke@1 | 143 | |
duke@1 | 144 | |
duke@1 | 145 | } |
duke@1 | 146 | |
duke@1 | 147 | // annotation processor method |
duke@1 | 148 | public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv ) |
duke@1 | 149 | { |
duke@1 | 150 | try { |
duke@1 | 151 | // touch a file to indicate we have run |
duke@1 | 152 | new FileWriter(processed).close(); |
duke@1 | 153 | } catch (IOException e) { |
duke@1 | 154 | } |
duke@1 | 155 | return true; |
duke@1 | 156 | } |
duke@1 | 157 | |
duke@1 | 158 | static class MyDiagListener implements DiagnosticListener<JavaFileObject> |
duke@1 | 159 | { |
duke@1 | 160 | public void report(Diagnostic<? extends JavaFileObject> message) { |
duke@1 | 161 | if (verbose) |
duke@1 | 162 | System.err.println(message); |
duke@1 | 163 | last = message; |
duke@1 | 164 | } |
duke@1 | 165 | |
duke@1 | 166 | Diagnostic<? extends JavaFileObject> last; |
duke@1 | 167 | } |
duke@1 | 168 | |
duke@1 | 169 | static class NoLoaderSecurityManager extends SecurityManager |
duke@1 | 170 | { |
duke@1 | 171 | public void checkCreateClassLoader() { |
duke@1 | 172 | throw new SecurityException("Not today, thanks you!"); |
duke@1 | 173 | } |
duke@1 | 174 | |
duke@1 | 175 | public void checkPropertyAccess(String key) { /*OK*/ } |
duke@1 | 176 | |
duke@1 | 177 | public void checkDelete(String file) { /*OK*/ } |
duke@1 | 178 | public void checkRead(FileDescriptor fd) { /*OK*/ } |
duke@1 | 179 | public void checkRead(String file) { /*OK*/ } |
duke@1 | 180 | public void checkRead(String file, Object context) { /*OK*/ } |
duke@1 | 181 | public void checkWrite(String file) { /*OK*/ } |
duke@1 | 182 | |
duke@1 | 183 | } |
duke@1 | 184 | } |