Tue, 26 Oct 2010 10:58:44 -0700
Merge
1.1 --- a/src/share/classes/com/sun/tools/apt/mirror/declaration/AnnotationProxyMaker.java Thu Oct 21 17:12:55 2010 -0700 1.2 +++ b/src/share/classes/com/sun/tools/apt/mirror/declaration/AnnotationProxyMaker.java Tue Oct 26 10:58:44 2010 -0700 1.3 @@ -250,9 +250,13 @@ 1.4 /** 1.5 * Sets "value" to an ExceptionProxy indicating a type mismatch. 1.6 */ 1.7 - private void typeMismatch(final Method method, final Attribute attr) { 1.8 - value = new ExceptionProxy() { 1.9 + private void typeMismatch(Method method, final Attribute attr) { 1.10 + class AnnotationTypeMismatchExceptionProxy extends ExceptionProxy { 1.11 private static final long serialVersionUID = 8473323277815075163L; 1.12 + transient final Method method; 1.13 + AnnotationTypeMismatchExceptionProxy(Method method) { 1.14 + this.method = method; 1.15 + } 1.16 public String toString() { 1.17 return "<error>"; // eg: @Anno(value=<error>) 1.18 } 1.19 @@ -260,7 +264,8 @@ 1.20 return new AnnotationTypeMismatchException(method, 1.21 attr.type.toString()); 1.22 } 1.23 - }; 1.24 + } 1.25 + value = new AnnotationTypeMismatchExceptionProxy(method); 1.26 } 1.27 } 1.28
2.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java Thu Oct 21 17:12:55 2010 -0700 2.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java Tue Oct 26 10:58:44 2010 -0700 2.3 @@ -553,12 +553,24 @@ 2.4 //the enclosing tree E, as follows: if E is a cast, then use the 2.5 //target type of the cast expression as a return type; if E is an 2.6 //expression statement, the return type is 'void' - otherwise the 2.7 - //return type is simply 'Object'. 2.8 - switch (env.outer.tree.getTag()) { 2.9 + //return type is simply 'Object'. A correctness check ensures that 2.10 + //env.next refers to the lexically enclosing environment in which 2.11 + //the polymorphic signature call environment is nested. 2.12 + 2.13 + switch (env.next.tree.getTag()) { 2.14 case JCTree.TYPECAST: 2.15 - restype = ((JCTypeCast)env.outer.tree).clazz.type; break; 2.16 + JCTypeCast castTree = (JCTypeCast)env.next.tree; 2.17 + restype = (castTree.expr == env.tree) ? 2.18 + castTree.clazz.type : 2.19 + syms.objectType; 2.20 + break; 2.21 case JCTree.EXEC: 2.22 - restype = syms.voidType; break; 2.23 + JCTree.JCExpressionStatement execTree = 2.24 + (JCTree.JCExpressionStatement)env.next.tree; 2.25 + restype = (execTree.expr == env.tree) ? 2.26 + syms.voidType : 2.27 + syms.objectType; 2.28 + break; 2.29 default: 2.30 restype = syms.objectType; 2.31 }
3.1 --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Oct 21 17:12:55 2010 -0700 3.2 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Tue Oct 26 10:58:44 2010 -0700 3.3 @@ -668,9 +668,9 @@ 3.4 public void visitTree(JCTree tree) { 3.5 } 3.6 3.7 - 3.8 public void visitErroneous(JCErroneous tree) { 3.9 - memberEnter(tree.errs, env); 3.10 + if (tree.errs != null) 3.11 + memberEnter(tree.errs, env); 3.12 } 3.13 3.14 public Env<AttrContext> getMethodEnv(JCMethodDecl tree, Env<AttrContext> env) {
4.1 --- a/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Thu Oct 21 17:12:55 2010 -0700 4.2 +++ b/src/share/classes/com/sun/tools/javac/main/JavaCompiler.java Tue Oct 26 10:58:44 2010 -0700 4.3 @@ -511,7 +511,7 @@ 4.4 4.5 protected boolean shouldStop(CompileState cs) { 4.6 if (shouldStopPolicy == null) 4.7 - return (errorCount() > 0); 4.8 + return (errorCount() > 0 || unrecoverableError()); 4.9 else 4.10 return cs.ordinal() > shouldStopPolicy.ordinal(); 4.11 }
5.1 --- a/src/share/classes/com/sun/tools/javac/model/AnnotationProxyMaker.java Thu Oct 21 17:12:55 2010 -0700 5.2 +++ b/src/share/classes/com/sun/tools/javac/model/AnnotationProxyMaker.java Tue Oct 26 10:58:44 2010 -0700 5.3 @@ -250,9 +250,13 @@ 5.4 /** 5.5 * Sets "value" to an ExceptionProxy indicating a type mismatch. 5.6 */ 5.7 - private void typeMismatch(final Method method, final Attribute attr) { 5.8 - value = new ExceptionProxy() { 5.9 + private void typeMismatch(Method method, final Attribute attr) { 5.10 + class AnnotationTypeMismatchExceptionProxy extends ExceptionProxy { 5.11 static final long serialVersionUID = 269; 5.12 + transient final Method method; 5.13 + AnnotationTypeMismatchExceptionProxy(Method method) { 5.14 + this.method = method; 5.15 + } 5.16 public String toString() { 5.17 return "<error>"; // eg: @Anno(value=<error>) 5.18 } 5.19 @@ -260,7 +264,8 @@ 5.20 return new AnnotationTypeMismatchException(method, 5.21 attr.type.toString()); 5.22 } 5.23 - }; 5.24 + } 5.25 + value = new AnnotationTypeMismatchExceptionProxy(method); 5.26 } 5.27 } 5.28
6.1 --- a/src/share/classes/com/sun/tools/javac/model/JavacElements.java Thu Oct 21 17:12:55 2010 -0700 6.2 +++ b/src/share/classes/com/sun/tools/javac/model/JavacElements.java Tue Oct 26 10:58:44 2010 -0700 6.3 @@ -66,32 +66,26 @@ 6.4 private Types types; 6.5 private Enter enter; 6.6 6.7 - private static final Context.Key<JavacElements> KEY = 6.8 - new Context.Key<JavacElements>(); 6.9 - 6.10 public static JavacElements instance(Context context) { 6.11 - JavacElements instance = context.get(KEY); 6.12 - if (instance == null) { 6.13 + JavacElements instance = context.get(JavacElements.class); 6.14 + if (instance == null) 6.15 instance = new JavacElements(context); 6.16 - context.put(KEY, instance); 6.17 - } 6.18 return instance; 6.19 } 6.20 6.21 /** 6.22 * Public for use only by JavacProcessingEnvironment 6.23 */ 6.24 - // TODO JavacElements constructor should be protected 6.25 - public JavacElements(Context context) { 6.26 + protected JavacElements(Context context) { 6.27 setContext(context); 6.28 } 6.29 6.30 /** 6.31 * Use a new context. May be called from outside to update 6.32 * internal state for a new annotation-processing round. 6.33 - * This instance is *not* then registered with the new context. 6.34 */ 6.35 public void setContext(Context context) { 6.36 + context.put(JavacElements.class, this); 6.37 javaCompiler = JavaCompiler.instance(context); 6.38 syms = Symtab.instance(context); 6.39 names = Names.instance(context);
7.1 --- a/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Thu Oct 21 17:12:55 2010 -0700 7.2 +++ b/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Tue Oct 26 10:58:44 2010 -0700 7.3 @@ -47,32 +47,26 @@ 7.4 private Symtab syms; 7.5 private Types types; 7.6 7.7 - private static final Context.Key<JavacTypes> KEY = 7.8 - new Context.Key<JavacTypes>(); 7.9 - 7.10 public static JavacTypes instance(Context context) { 7.11 - JavacTypes instance = context.get(KEY); 7.12 - if (instance == null) { 7.13 + JavacTypes instance = context.get(JavacTypes.class); 7.14 + if (instance == null) 7.15 instance = new JavacTypes(context); 7.16 - context.put(KEY, instance); 7.17 - } 7.18 return instance; 7.19 } 7.20 7.21 /** 7.22 * Public for use only by JavacProcessingEnvironment 7.23 */ 7.24 - // TODO JavacTypes constructor should be protected 7.25 - public JavacTypes(Context context) { 7.26 + protected JavacTypes(Context context) { 7.27 setContext(context); 7.28 } 7.29 7.30 /** 7.31 * Use a new context. May be called from outside to update 7.32 * internal state for a new annotation-processing round. 7.33 - * This instance is *not* then registered with the new context. 7.34 */ 7.35 public void setContext(Context context) { 7.36 + context.put(JavacTypes.class, this); 7.37 syms = Symtab.instance(context); 7.38 types = Types.instance(context); 7.39 }
8.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Thu Oct 21 17:12:55 2010 -0700 8.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java Tue Oct 26 10:58:44 2010 -0700 8.3 @@ -173,12 +173,12 @@ 8.4 platformAnnotations = initPlatformAnnotations(); 8.5 foundTypeProcessors = false; 8.6 8.7 - // Initialize services before any processors are initialzied 8.8 + // Initialize services before any processors are initialized 8.9 // in case processors use them. 8.10 filer = new JavacFiler(context); 8.11 messager = new JavacMessager(context, this); 8.12 - elementUtils = new JavacElements(context); 8.13 - typeUtils = new JavacTypes(context); 8.14 + elementUtils = JavacElements.instance(context); 8.15 + typeUtils = JavacTypes.instance(context); 8.16 processorOptions = initProcessorOptions(context); 8.17 unmatchedProcessorOptions = initUnmatchedProcessorOptions(); 8.18 messages = JavacMessages.instance(context); 8.19 @@ -865,8 +865,6 @@ 8.20 this(prev.nextContext(), prev.number+1, prev.compiler.log.nwarnings); 8.21 this.genClassFiles = prev.genClassFiles; 8.22 8.23 - updateProcessingState(); 8.24 - 8.25 List<JCCompilationUnit> parsedFiles = compiler.parseFiles(newSourceFiles); 8.26 roots = cleanTrees(prev.roots).appendList(parsedFiles); 8.27 8.28 @@ -1029,15 +1027,6 @@ 8.29 log.reportDeferredDiagnostics(kinds); 8.30 } 8.31 8.32 - /** Update the processing state for the current context. */ 8.33 - private void updateProcessingState() { 8.34 - filer.newRound(context); 8.35 - messager.newRound(context); 8.36 - 8.37 - elementUtils.setContext(context); 8.38 - typeUtils.setContext(context); 8.39 - } 8.40 - 8.41 /** Print info about this round. */ 8.42 private void printRoundInfo(boolean lastRound) { 8.43 if (printRounds || verbose) { 8.44 @@ -1100,6 +1089,11 @@ 8.45 JavaCompiler nextCompiler = JavaCompiler.instance(next); 8.46 nextCompiler.initRound(oldCompiler); 8.47 8.48 + filer.newRound(next); 8.49 + messager.newRound(next); 8.50 + elementUtils.setContext(next); 8.51 + typeUtils.setContext(next); 8.52 + 8.53 JavacTaskImpl task = context.get(JavacTaskImpl.class); 8.54 if (task != null) { 8.55 next.put(JavacTaskImpl.class, task);
9.1 --- a/src/share/classes/com/sun/tools/javah/JNI.java Thu Oct 21 17:12:55 2010 -0700 9.2 +++ b/src/share/classes/com/sun/tools/javah/JNI.java Tue Oct 26 10:58:44 2010 -0700 9.3 @@ -59,72 +59,76 @@ 9.4 } 9.5 9.6 public void write(OutputStream o, TypeElement clazz) throws Util.Exit { 9.7 - String cname = mangler.mangle(clazz.getQualifiedName(), Mangle.Type.CLASS); 9.8 - PrintWriter pw = wrapWriter(o); 9.9 - pw.println(guardBegin(cname)); 9.10 - pw.println(cppGuardBegin()); 9.11 + try { 9.12 + String cname = mangler.mangle(clazz.getQualifiedName(), Mangle.Type.CLASS); 9.13 + PrintWriter pw = wrapWriter(o); 9.14 + pw.println(guardBegin(cname)); 9.15 + pw.println(cppGuardBegin()); 9.16 9.17 - /* Write statics. */ 9.18 - List<VariableElement> classfields = getAllFields(clazz); 9.19 + /* Write statics. */ 9.20 + List<VariableElement> classfields = getAllFields(clazz); 9.21 9.22 - for (VariableElement v: classfields) { 9.23 - if (!v.getModifiers().contains(Modifier.STATIC)) 9.24 - continue; 9.25 - String s = null; 9.26 - s = defineForStatic(clazz, v); 9.27 - if (s != null) { 9.28 - pw.println(s); 9.29 + for (VariableElement v: classfields) { 9.30 + if (!v.getModifiers().contains(Modifier.STATIC)) 9.31 + continue; 9.32 + String s = null; 9.33 + s = defineForStatic(clazz, v); 9.34 + if (s != null) { 9.35 + pw.println(s); 9.36 + } 9.37 } 9.38 + 9.39 + /* Write methods. */ 9.40 + List<ExecutableElement> classmethods = ElementFilter.methodsIn(clazz.getEnclosedElements()); 9.41 + for (ExecutableElement md: classmethods) { 9.42 + if(md.getModifiers().contains(Modifier.NATIVE)){ 9.43 + TypeMirror mtr = types.erasure(md.getReturnType()); 9.44 + String sig = signature(md); 9.45 + TypeSignature newtypesig = new TypeSignature(elems); 9.46 + CharSequence methodName = md.getSimpleName(); 9.47 + boolean longName = false; 9.48 + for (ExecutableElement md2: classmethods) { 9.49 + if ((md2 != md) 9.50 + && (methodName.equals(md2.getSimpleName())) 9.51 + && (md2.getModifiers().contains(Modifier.NATIVE))) 9.52 + longName = true; 9.53 + 9.54 + } 9.55 + pw.println("/*"); 9.56 + pw.println(" * Class: " + cname); 9.57 + pw.println(" * Method: " + 9.58 + mangler.mangle(methodName, Mangle.Type.FIELDSTUB)); 9.59 + pw.println(" * Signature: " + newtypesig.getTypeSignature(sig, mtr)); 9.60 + pw.println(" */"); 9.61 + pw.println("JNIEXPORT " + jniType(mtr) + 9.62 + " JNICALL " + 9.63 + mangler.mangleMethod(md, clazz, 9.64 + (longName) ? 9.65 + Mangle.Type.METHOD_JNI_LONG : 9.66 + Mangle.Type.METHOD_JNI_SHORT)); 9.67 + pw.print(" (JNIEnv *, "); 9.68 + List<? extends VariableElement> paramargs = md.getParameters(); 9.69 + List<TypeMirror> args = new ArrayList<TypeMirror>(); 9.70 + for (VariableElement p: paramargs) { 9.71 + args.add(types.erasure(p.asType())); 9.72 + } 9.73 + if (md.getModifiers().contains(Modifier.STATIC)) 9.74 + pw.print("jclass"); 9.75 + else 9.76 + pw.print("jobject"); 9.77 + 9.78 + for (TypeMirror arg: args) { 9.79 + pw.print(", "); 9.80 + pw.print(jniType(arg)); 9.81 + } 9.82 + pw.println(");" + lineSep); 9.83 + } 9.84 + } 9.85 + pw.println(cppGuardEnd()); 9.86 + pw.println(guardEnd(cname)); 9.87 + } catch (TypeSignature.SignatureException e) { 9.88 + util.error("jni.sigerror", e.getMessage()); 9.89 } 9.90 - 9.91 - /* Write methods. */ 9.92 - List<ExecutableElement> classmethods = ElementFilter.methodsIn(clazz.getEnclosedElements()); 9.93 - for (ExecutableElement md: classmethods) { 9.94 - if(md.getModifiers().contains(Modifier.NATIVE)){ 9.95 - TypeMirror mtr = types.erasure(md.getReturnType()); 9.96 - String sig = signature(md); 9.97 - TypeSignature newtypesig = new TypeSignature(elems); 9.98 - CharSequence methodName = md.getSimpleName(); 9.99 - boolean longName = false; 9.100 - for (ExecutableElement md2: classmethods) { 9.101 - if ((md2 != md) 9.102 - && (methodName.equals(md2.getSimpleName())) 9.103 - && (md2.getModifiers().contains(Modifier.NATIVE))) 9.104 - longName = true; 9.105 - 9.106 - } 9.107 - pw.println("/*"); 9.108 - pw.println(" * Class: " + cname); 9.109 - pw.println(" * Method: " + 9.110 - mangler.mangle(methodName, Mangle.Type.FIELDSTUB)); 9.111 - pw.println(" * Signature: " + newtypesig.getTypeSignature(sig, mtr)); 9.112 - pw.println(" */"); 9.113 - pw.println("JNIEXPORT " + jniType(mtr) + 9.114 - " JNICALL " + 9.115 - mangler.mangleMethod(md, clazz, 9.116 - (longName) ? 9.117 - Mangle.Type.METHOD_JNI_LONG : 9.118 - Mangle.Type.METHOD_JNI_SHORT)); 9.119 - pw.print(" (JNIEnv *, "); 9.120 - List<? extends VariableElement> paramargs = md.getParameters(); 9.121 - List<TypeMirror> args = new ArrayList<TypeMirror>(); 9.122 - for (VariableElement p: paramargs) { 9.123 - args.add(types.erasure(p.asType())); 9.124 - } 9.125 - if (md.getModifiers().contains(Modifier.STATIC)) 9.126 - pw.print("jclass"); 9.127 - else 9.128 - pw.print("jobject"); 9.129 - 9.130 - for (TypeMirror arg: args) { 9.131 - pw.print(", "); 9.132 - pw.print(jniType(arg)); 9.133 - } 9.134 - pw.println(");" + lineSep); 9.135 - } 9.136 - } 9.137 - pw.println(cppGuardEnd()); 9.138 - pw.println(guardEnd(cname)); 9.139 } 9.140 9.141
10.1 --- a/src/share/classes/com/sun/tools/javah/JavahTask.java Thu Oct 21 17:12:55 2010 -0700 10.2 +++ b/src/share/classes/com/sun/tools/javah/JavahTask.java Tue Oct 26 10:58:44 2010 -0700 10.3 @@ -46,9 +46,9 @@ 10.4 10.5 import javax.annotation.processing.AbstractProcessor; 10.6 import javax.annotation.processing.Messager; 10.7 +import javax.annotation.processing.ProcessingEnvironment; 10.8 import javax.annotation.processing.RoundEnvironment; 10.9 import javax.annotation.processing.SupportedAnnotationTypes; 10.10 -import javax.annotation.processing.SupportedSourceVersion; 10.11 10.12 import javax.lang.model.SourceVersion; 10.13 import javax.lang.model.element.ExecutableElement; 10.14 @@ -71,6 +71,9 @@ 10.15 import javax.tools.StandardJavaFileManager; 10.16 import javax.tools.StandardLocation; 10.17 import javax.tools.ToolProvider; 10.18 +import static javax.tools.Diagnostic.Kind.*; 10.19 + 10.20 +import com.sun.tools.javac.code.Symbol.CompletionFailure; 10.21 10.22 /** 10.23 * Javah generates support files for native methods. 10.24 @@ -173,7 +176,7 @@ 10.25 } 10.26 }, 10.27 10.28 - new Option(false, "-help", "--help", "-?") { 10.29 + new Option(false, "-h", "-help", "--help", "-?") { 10.30 void process(JavahTask task, String opt, String arg) { 10.31 task.help = true; 10.32 } 10.33 @@ -233,6 +236,15 @@ 10.34 task.doubleAlign = true; 10.35 } 10.36 }, 10.37 + 10.38 + new HiddenOption(false) { 10.39 + boolean matches(String opt) { 10.40 + return opt.startsWith("-XD"); 10.41 + } 10.42 + void process(JavahTask task, String opt, String arg) { 10.43 + task.javac_extras.add(opt); 10.44 + } 10.45 + }, 10.46 }; 10.47 10.48 JavahTask() { 10.49 @@ -326,6 +338,8 @@ 10.50 } catch (InternalError e) { 10.51 diagnosticListener.report(createDiagnostic("err.internal.error", e.getMessage())); 10.52 return 1; 10.53 + } catch (Util.Exit e) { 10.54 + return e.exitValue; 10.55 } finally { 10.56 log.flush(); 10.57 } 10.58 @@ -475,7 +489,9 @@ 10.59 ((JavahFileManager) fileManager).setIgnoreSymbolFile(true); 10.60 10.61 JavaCompiler c = ToolProvider.getSystemJavaCompiler(); 10.62 - List<String> opts = Arrays.asList("-proc:only"); 10.63 + List<String> opts = new ArrayList<String>(); 10.64 + opts.add("-proc:only"); 10.65 + opts.addAll(javac_extras); 10.66 CompilationTask t = c.getTask(log, fileManager, diagnosticListener, opts, internalize(classes), null); 10.67 JavahProcessor p = new JavahProcessor(g); 10.68 t.setProcessors(Collections.singleton(p)); 10.69 @@ -642,6 +658,7 @@ 10.70 boolean doubleAlign; 10.71 boolean force; 10.72 boolean old; 10.73 + Set<String> javac_extras = new LinkedHashSet<String>(); 10.74 10.75 PrintWriter log; 10.76 JavaFileManager fileManager; 10.77 @@ -652,30 +669,45 @@ 10.78 private static final String progname = "javah"; 10.79 10.80 @SupportedAnnotationTypes("*") 10.81 - @SupportedSourceVersion(SourceVersion.RELEASE_7) 10.82 class JavahProcessor extends AbstractProcessor { 10.83 + private Messager messager; 10.84 + 10.85 JavahProcessor(Gen g) { 10.86 this.g = g; 10.87 } 10.88 10.89 + @Override 10.90 + public SourceVersion getSupportedSourceVersion() { 10.91 + // since this is co-bundled with javac, we can assume it supports 10.92 + // the latest source version 10.93 + return SourceVersion.latest(); 10.94 + } 10.95 + 10.96 + @Override 10.97 + public void init(ProcessingEnvironment pEnv) { 10.98 + super.init(pEnv); 10.99 + messager = processingEnv.getMessager(); 10.100 + } 10.101 + 10.102 public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 10.103 - Messager messager = processingEnv.getMessager(); 10.104 - Set<TypeElement> classes = getAllClasses(ElementFilter.typesIn(roundEnv.getRootElements())); 10.105 - if (classes.size() > 0) { 10.106 - checkMethodParameters(classes); 10.107 - g.setProcessingEnvironment(processingEnv); 10.108 - g.setClasses(classes); 10.109 + try { 10.110 + Set<TypeElement> classes = getAllClasses(ElementFilter.typesIn(roundEnv.getRootElements())); 10.111 + if (classes.size() > 0) { 10.112 + checkMethodParameters(classes); 10.113 + g.setProcessingEnvironment(processingEnv); 10.114 + g.setClasses(classes); 10.115 + g.run(); 10.116 + } 10.117 + } catch (CompletionFailure cf) { 10.118 + messager.printMessage(ERROR, getMessage("class.not.found", cf.sym.getQualifiedName().toString())); 10.119 + } catch (ClassNotFoundException cnfe) { 10.120 + messager.printMessage(ERROR, getMessage("class.not.found", cnfe.getMessage())); 10.121 + } catch (IOException ioe) { 10.122 + messager.printMessage(ERROR, getMessage("io.exception", ioe.getMessage())); 10.123 + } catch (Util.Exit e) { 10.124 + exit = e; 10.125 + } 10.126 10.127 - try { 10.128 - g.run(); 10.129 - } catch (ClassNotFoundException cnfe) { 10.130 - messager.printMessage(Diagnostic.Kind.ERROR, getMessage("class.not.found", cnfe.getMessage())); 10.131 - } catch (IOException ioe) { 10.132 - messager.printMessage(Diagnostic.Kind.ERROR, getMessage("io.exception", ioe.getMessage())); 10.133 - } catch (Util.Exit e) { 10.134 - exit = e; 10.135 - } 10.136 - } 10.137 return true; 10.138 } 10.139
11.1 --- a/src/share/classes/com/sun/tools/javah/LLNI.java Thu Oct 21 17:12:55 2010 -0700 11.2 +++ b/src/share/classes/com/sun/tools/javah/LLNI.java Tue Oct 26 10:58:44 2010 -0700 11.3 @@ -74,16 +74,21 @@ 11.4 } 11.5 11.6 protected void write(OutputStream o, TypeElement clazz) throws Util.Exit { 11.7 - String cname = mangleClassName(clazz.getQualifiedName().toString()); 11.8 - PrintWriter pw = wrapWriter(o); 11.9 - fields = ElementFilter.fieldsIn(clazz.getEnclosedElements()); 11.10 - methods = ElementFilter.methodsIn(clazz.getEnclosedElements()); 11.11 - generateDeclsForClass(pw, clazz, cname); 11.12 - // FIXME check if errors occurred on the PrintWriter and throw exception if so 11.13 + try { 11.14 + String cname = mangleClassName(clazz.getQualifiedName().toString()); 11.15 + PrintWriter pw = wrapWriter(o); 11.16 + fields = ElementFilter.fieldsIn(clazz.getEnclosedElements()); 11.17 + methods = ElementFilter.methodsIn(clazz.getEnclosedElements()); 11.18 + generateDeclsForClass(pw, clazz, cname); 11.19 + // FIXME check if errors occurred on the PrintWriter and throw exception if so 11.20 + } catch (TypeSignature.SignatureException e) { 11.21 + util.error("llni.sigerror", e.getMessage()); 11.22 + } 11.23 } 11.24 11.25 protected void generateDeclsForClass(PrintWriter pw, 11.26 - TypeElement clazz, String cname) throws Util.Exit { 11.27 + TypeElement clazz, String cname) 11.28 + throws TypeSignature.SignatureException, Util.Exit { 11.29 doneHandleTypes = new HashSet<String>(); 11.30 /* The following handle types are predefined in "typedefs.h". Suppress 11.31 inclusion in the output by generating them "into the blue" here. */ 11.32 @@ -127,7 +132,8 @@ 11.33 .replace(innerDelim, '_'); 11.34 } 11.35 11.36 - protected void forwardDecls(PrintWriter pw, TypeElement clazz) { 11.37 + protected void forwardDecls(PrintWriter pw, TypeElement clazz) 11.38 + throws TypeSignature.SignatureException { 11.39 TypeElement object = elems.getTypeElement("java.lang.Object"); 11.40 if (clazz.equals(object)) 11.41 return; 11.42 @@ -403,7 +409,7 @@ 11.43 11.44 protected void methodSectionForClass(PrintWriter pw, 11.45 TypeElement clazz, String cname) 11.46 - throws Util.Exit { 11.47 + throws TypeSignature.SignatureException, Util.Exit { 11.48 String methods = methodDecls(clazz, cname); 11.49 11.50 if (methods.length() != 0) { 11.51 @@ -418,7 +424,8 @@ 11.52 } 11.53 } 11.54 11.55 - protected String methodDecls(TypeElement clazz, String cname) throws Util.Exit { 11.56 + protected String methodDecls(TypeElement clazz, String cname) 11.57 + throws TypeSignature.SignatureException, Util.Exit { 11.58 11.59 String res = ""; 11.60 for (ExecutableElement method: methods) { 11.61 @@ -430,7 +437,7 @@ 11.62 11.63 protected String methodDecl(ExecutableElement method, 11.64 TypeElement clazz, String cname) 11.65 - throws Util.Exit { 11.66 + throws TypeSignature.SignatureException, Util.Exit { 11.67 String res = null; 11.68 11.69 TypeMirror retType = types.erasure(method.getReturnType()); 11.70 @@ -474,7 +481,8 @@ 11.71 } 11.72 11.73 protected final String jniMethodName(ExecutableElement method, String cname, 11.74 - boolean longName) { 11.75 + boolean longName) 11.76 + throws TypeSignature.SignatureException { 11.77 String res = "Java_" + cname + "_" + method.getSimpleName(); 11.78 11.79 if (longName) {
12.1 --- a/src/share/classes/com/sun/tools/javah/Mangle.java Thu Oct 21 17:12:55 2010 -0700 12.2 +++ b/src/share/classes/com/sun/tools/javah/Mangle.java Tue Oct 26 10:58:44 2010 -0700 12.3 @@ -114,7 +114,7 @@ 12.4 } 12.5 12.6 public String mangleMethod(ExecutableElement method, TypeElement clazz, 12.7 - int mtype) { 12.8 + int mtype) throws TypeSignature.SignatureException { 12.9 StringBuffer result = new StringBuffer(100); 12.10 result.append("Java_"); 12.11
13.1 --- a/src/share/classes/com/sun/tools/javah/TypeSignature.java Thu Oct 21 17:12:55 2010 -0700 13.2 +++ b/src/share/classes/com/sun/tools/javah/TypeSignature.java Tue Oct 26 10:58:44 2010 -0700 13.3 @@ -51,7 +51,13 @@ 13.4 * @author Sucheta Dambalkar 13.5 */ 13.6 13.7 -public class TypeSignature{ 13.8 +public class TypeSignature { 13.9 + static class SignatureException extends Exception { 13.10 + private static final long serialVersionUID = 1L; 13.11 + SignatureException(String reason) { 13.12 + super(reason); 13.13 + } 13.14 + } 13.15 13.16 Elements elems; 13.17 13.18 @@ -78,14 +84,15 @@ 13.19 /* 13.20 * Returns the type signature of a field according to JVM specs 13.21 */ 13.22 - public String getTypeSignature(String javasignature){ 13.23 + public String getTypeSignature(String javasignature) throws SignatureException { 13.24 return getParamJVMSignature(javasignature); 13.25 } 13.26 13.27 /* 13.28 * Returns the type signature of a method according to JVM specs 13.29 */ 13.30 - public String getTypeSignature(String javasignature, TypeMirror returnType){ 13.31 + public String getTypeSignature(String javasignature, TypeMirror returnType) 13.32 + throws SignatureException { 13.33 String signature = null; //Java type signature. 13.34 String typeSignature = null; //Internal type signature. 13.35 List<String> params = new ArrayList<String>(); //List of parameters. 13.36 @@ -166,7 +173,7 @@ 13.37 /* 13.38 * Returns internal signature of a parameter. 13.39 */ 13.40 - private String getParamJVMSignature(String paramsig) { 13.41 + private String getParamJVMSignature(String paramsig) throws SignatureException { 13.42 String paramJVMSig = ""; 13.43 String componentType =""; 13.44 13.45 @@ -197,7 +204,7 @@ 13.46 /* 13.47 * Returns internal signature of a component. 13.48 */ 13.49 - private String getComponentType(String componentType){ 13.50 + private String getComponentType(String componentType) throws SignatureException { 13.51 13.52 String JVMSig = ""; 13.53 13.54 @@ -216,8 +223,7 @@ 13.55 TypeElement classNameDoc = elems.getTypeElement(componentType); 13.56 13.57 if(classNameDoc == null){ 13.58 - System.out.println("Invalid class type for " + componentType); 13.59 - new Exception().printStackTrace(); 13.60 + throw new SignatureException(componentType); 13.61 }else { 13.62 String classname = classNameDoc.getQualifiedName().toString(); 13.63 String newclassname = classname.replace('.', '/');
14.1 --- a/src/share/classes/com/sun/tools/javah/resources/l10n.properties Thu Oct 21 17:12:55 2010 -0700 14.2 +++ b/src/share/classes/com/sun/tools/javah/resources/l10n.properties Tue Oct 26 10:58:44 2010 -0700 14.3 @@ -45,6 +45,8 @@ 14.4 Can''t mix options -jni and -llni. Try -help. 14.5 jni.no.stubs=\ 14.6 JNI does not require stubs, please refer to the JNI documentation. 14.7 +jni.sigerror=\ 14.8 + Cannot determine signature for {0} 14.9 dir.file.mixed=\ 14.10 Can''t mix options -d and -o. Try -help. 14.11 no.classes.specified=\ 14.12 @@ -94,7 +96,7 @@ 14.13 \ -d <dir> Output directory 14.14 main.opt.v=\ 14.15 \ -v -verbose Enable verbose output 14.16 -main.opt.help=\ 14.17 +main.opt.h=\ 14.18 \ -h --help -? Print this message 14.19 main.opt.version=\ 14.20 \ -version Print version information
15.1 --- a/test/tools/javac/T6705935.java Thu Oct 21 17:12:55 2010 -0700 15.2 +++ b/test/tools/javac/T6705935.java Tue Oct 26 10:58:44 2010 -0700 15.3 @@ -31,6 +31,8 @@ 15.4 import java.util.*; 15.5 import javax.tools.*; 15.6 import com.sun.tools.javac.file.*; 15.7 +import com.sun.tools.javac.file.ZipArchive.ZipFileObject; 15.8 +import com.sun.tools.javac.file.ZipFileIndexArchive.ZipFileIndexFileObject; 15.9 15.10 public class T6705935 { 15.11 public static void main(String... args) throws Exception { 15.12 @@ -43,11 +45,22 @@ 15.13 java_home = java_home.getParentFile(); 15.14 15.15 JavaCompiler c = ToolProvider.getSystemJavaCompiler(); 15.16 - JavaFileManager fm = c.getStandardFileManager(null, null, null); 15.17 + StandardJavaFileManager fm = c.getStandardFileManager(null, null, null); 15.18 + //System.err.println("platform class path: " + asList(fm.getLocation(StandardLocation.PLATFORM_CLASS_PATH))); 15.19 + 15.20 for (JavaFileObject fo: fm.list(StandardLocation.PLATFORM_CLASS_PATH, 15.21 "java.lang", 15.22 Collections.singleton(JavaFileObject.Kind.CLASS), 15.23 false)) { 15.24 + test++; 15.25 + 15.26 + if (!(fo instanceof ZipFileObject || fo instanceof ZipFileIndexFileObject)) { 15.27 + System.out.println("Skip " + fo.getClass().getSimpleName() + " " + fo.getName()); 15.28 + skip++; 15.29 + continue; 15.30 + } 15.31 + 15.32 + //System.err.println(fo.getName()); 15.33 String p = fo.getName(); 15.34 int bra = p.indexOf("("); 15.35 int ket = p.indexOf(")"); 15.36 @@ -61,5 +74,26 @@ 15.37 throw new Exception("bad path: " + p); 15.38 15.39 } 15.40 + 15.41 + if (test == 0) 15.42 + throw new Exception("no files found"); 15.43 + 15.44 + if (skip == 0) 15.45 + System.out.println(test + " files found"); 15.46 + else 15.47 + System.out.println(test + " files found, " + skip + " files skipped"); 15.48 + 15.49 + if (test == skip) 15.50 + System.out.println("Warning: all files skipped; no platform classes found in zip files."); 15.51 } 15.52 + 15.53 + private <T> List<T> asList(Iterable<? extends T> items) { 15.54 + List<T> list = new ArrayList<T>(); 15.55 + for (T item: items) 15.56 + list.add(item); 15.57 + return list; 15.58 + } 15.59 + 15.60 + private int skip; 15.61 + private int test; 15.62 }
16.1 --- a/test/tools/javac/api/6406133/Erroneous.java Thu Oct 21 17:12:55 2010 -0700 16.2 +++ b/test/tools/javac/api/6406133/Erroneous.java Tue Oct 26 10:58:44 2010 -0700 16.3 @@ -1,4 +1,26 @@ 16.4 +/* 16.5 + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. 16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.7 + * 16.8 + * This code is free software; you can redistribute it and/or modify it 16.9 + * under the terms of the GNU General Public License version 2 only, as 16.10 + * published by the Free Software Foundation. 16.11 + * 16.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 16.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16.15 + * version 2 for more details (a copy is included in the LICENSE file that 16.16 + * accompanied this code). 16.17 + * 16.18 + * You should have received a copy of the GNU General Public License version 16.19 + * 2 along with this work; if not, write to the Free Software Foundation, 16.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 16.21 + * 16.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 16.23 + * or visit www.oracle.com if you need additional information or have any 16.24 + * questions. 16.25 + */ 16.26 + 16.27 @Deprecated 16.28 -class A { 16.29 - class A {} 16.30 +class A extends Missing { 16.31 }
17.1 --- a/test/tools/javac/diags/CheckExamples.java Thu Oct 21 17:12:55 2010 -0700 17.2 +++ b/test/tools/javac/diags/CheckExamples.java Tue Oct 26 10:58:44 2010 -0700 17.3 @@ -40,7 +40,7 @@ 17.4 * compiler.properties bundle. A list of exceptions may be given in the 17.5 * not-yet.txt file. Entries on the not-yet.txt list should not be 17.6 * covered by examples. 17.7 - * When new keys are added to the resource buncle, it is strongly recommended 17.8 + * When new keys are added to the resource bundle, it is strongly recommended 17.9 * that corresponding new examples be added here, if at all practical, instead 17.10 * of simply and lazily being added to the not-yet.txt list. 17.11 */
18.1 --- a/test/tools/javac/diags/FileManager.java Thu Oct 21 17:12:55 2010 -0700 18.2 +++ b/test/tools/javac/diags/FileManager.java Tue Oct 26 10:58:44 2010 -0700 18.3 @@ -177,12 +177,14 @@ 18.4 } 18.5 18.6 void checkRead() throws IOException { 18.7 - if (cantRead != null && cantRead.matcher(getName()).matches()) 18.8 + String canonName = getName().replace(File.separatorChar, '/'); 18.9 + if (cantRead != null && cantRead.matcher(canonName).matches()) 18.10 throw new IOException("FileManager: Can't read"); 18.11 } 18.12 18.13 void checkWrite() throws IOException { 18.14 - if (cantWrite != null && cantWrite.matcher(getName()).matches()) 18.15 + String canonName = getName().replace(File.separatorChar, '/'); 18.16 + if (cantWrite != null && cantWrite.matcher(canonName).matches()) 18.17 throw new IOException("FileManager: Can't write"); 18.18 } 18.19
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/test/tools/javac/meth/TestCP.java Tue Oct 26 10:58:44 2010 -0700 19.3 @@ -0,0 +1,111 @@ 19.4 +/* 19.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 19.7 + * 19.8 + * This code is free software; you can redistribute it and/or modify it 19.9 + * under the terms of the GNU General Public License version 2 only, as 19.10 + * published by the Free Software Foundation. 19.11 + * 19.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 19.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 19.15 + * version 2 for more details (a copy is included in the LICENSE file that 19.16 + * accompanied this code). 19.17 + * 19.18 + * You should have received a copy of the GNU General Public License version 19.19 + * 2 along with this work; if not, write to the Free Software Foundation, 19.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19.21 + * 19.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19.23 + * or visit www.oracle.com if you need additional information or have any 19.24 + * questions. 19.25 + */ 19.26 + 19.27 +/* 19.28 + * @test 19.29 + * @bug 6991980 19.30 + * @summary polymorphic signature calls don't share the same CP entries 19.31 + * @run main TestCP 19.32 + */ 19.33 + 19.34 +import com.sun.tools.classfile.Instruction; 19.35 +import com.sun.tools.classfile.Attribute; 19.36 +import com.sun.tools.classfile.ClassFile; 19.37 +import com.sun.tools.classfile.Code_attribute; 19.38 +import com.sun.tools.classfile.ConstantPool.*; 19.39 +import com.sun.tools.classfile.Method; 19.40 + 19.41 +import java.dyn.*; 19.42 +import java.io.*; 19.43 + 19.44 +public class TestCP { 19.45 + 19.46 + static class TestClass { 19.47 + void test(MethodHandle mh) throws Throwable { 19.48 + Number n = mh.<Number>invokeExact("daddy",1,'n'); 19.49 + n = (Number)mh.invokeExact("bunny",1,'d'); 19.50 + } 19.51 + } 19.52 + 19.53 + static final String PS_TYPE = "(Ljava/lang/String;IC)Ljava/lang/Number;"; 19.54 + static final int PS_CALLS_COUNT = 2; 19.55 + static final String SUBTEST_NAME = TestClass.class.getName() + ".class"; 19.56 + static final String TEST_METHOD_NAME = "test"; 19.57 + 19.58 + public static void main(String... args) throws Exception { 19.59 + new TestCP().run(); 19.60 + } 19.61 + 19.62 + public void run() throws Exception { 19.63 + String workDir = System.getProperty("test.classes"); 19.64 + File compiledTest = new File(workDir, SUBTEST_NAME); 19.65 + verifyMethodHandleInvocationDescriptors(compiledTest); 19.66 + } 19.67 + 19.68 + void verifyMethodHandleInvocationDescriptors(File f) { 19.69 + System.err.println("verify: " + f); 19.70 + try { 19.71 + int count = 0; 19.72 + ClassFile cf = ClassFile.read(f); 19.73 + Method testMethod = null; 19.74 + for (Method m : cf.methods) { 19.75 + if (m.getName(cf.constant_pool).equals(TEST_METHOD_NAME)) { 19.76 + testMethod = m; 19.77 + break; 19.78 + } 19.79 + } 19.80 + if (testMethod == null) { 19.81 + throw new Error("Test method not found"); 19.82 + } 19.83 + Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code); 19.84 + if (testMethod == null) { 19.85 + throw new Error("Code attribute for test() method not found"); 19.86 + } 19.87 + int instr_count = 0; 19.88 + int cp_entry = -1; 19.89 + 19.90 + for (Instruction i : ea.getInstructions()) { 19.91 + if (i.getMnemonic().equals("invokevirtual")) { 19.92 + instr_count++; 19.93 + if (cp_entry == -1) { 19.94 + cp_entry = i.getUnsignedShort(1); 19.95 + } else if (cp_entry != i.getUnsignedShort(1)) { 19.96 + throw new Error("Unexpected CP entry in polymorphic signature call"); 19.97 + } 19.98 + CONSTANT_Methodref_info methRef = 19.99 + (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry); 19.100 + String type = methRef.getNameAndTypeInfo().getType(); 19.101 + if (!type.equals(PS_TYPE)) { 19.102 + throw new Error("Unexpected type in polymorphic signature call: " + type); 19.103 + } 19.104 + } 19.105 + } 19.106 + if (instr_count != PS_CALLS_COUNT) { 19.107 + throw new Error("Wrong number of polymorphic signature call found: " + instr_count); 19.108 + } 19.109 + } catch (Exception e) { 19.110 + e.printStackTrace(); 19.111 + throw new Error("error reading " + f +": " + e); 19.112 + } 19.113 + } 19.114 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/test/tools/javac/processing/environment/round/TestContext.java Tue Oct 26 10:58:44 2010 -0700 20.3 @@ -0,0 +1,96 @@ 20.4 +/* 20.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 20.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 20.7 + * 20.8 + * This code is free software; you can redistribute it and/or modify it 20.9 + * under the terms of the GNU General Public License version 2 only, as 20.10 + * published by the Free Software Foundation. 20.11 + * 20.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 20.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 20.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20.15 + * version 2 for more details (a copy is included in the LICENSE file that 20.16 + * accompanied this code). 20.17 + * 20.18 + * You should have received a copy of the GNU General Public License version 20.19 + * 2 along with this work; if not, write to the Free Software Foundation, 20.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20.21 + * 20.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20.23 + * or visit www.oracle.com if you need additional information or have any 20.24 + * questions. 20.25 + */ 20.26 + 20.27 +/* 20.28 + * @test 20.29 + * @bug 6988836 20.30 + * @summary A new JavacElements is created for each round of annotation processing 20.31 + * @library ../../../lib 20.32 + * @build JavacTestingAbstractProcessor TestContext 20.33 + * @compile/process -processor TestContext -XprintRounds TestContext 20.34 + */ 20.35 + 20.36 +import java.io.*; 20.37 +import java.util.*; 20.38 +import javax.annotation.processing.*; 20.39 +import javax.lang.model.element.*; 20.40 +import javax.tools.*; 20.41 +import static javax.tools.Diagnostic.Kind.*; 20.42 + 20.43 +import com.sun.source.util.Trees; 20.44 +import com.sun.tools.javac.api.JavacTrees; 20.45 +import com.sun.tools.javac.model.JavacElements; 20.46 +import com.sun.tools.javac.model.JavacTypes; 20.47 +import com.sun.tools.javac.processing.JavacProcessingEnvironment; 20.48 +import com.sun.tools.javac.util.Context; 20.49 + 20.50 +public class TestContext extends JavacTestingAbstractProcessor { 20.51 + 20.52 + Trees treeUtils; 20.53 + int round = 0; 20.54 + 20.55 + @Override 20.56 + public void init(ProcessingEnvironment pEnv) { 20.57 + super.init(pEnv); 20.58 + treeUtils = Trees.instance(processingEnv); 20.59 + } 20.60 + 20.61 + @Override 20.62 + public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { 20.63 + round++; 20.64 + 20.65 + JavacProcessingEnvironment jpe = (JavacProcessingEnvironment) processingEnv; 20.66 + Context c = jpe.getContext(); 20.67 + check(c.get(JavacElements.class), eltUtils); 20.68 + check(c.get(JavacTypes.class), typeUtils); 20.69 + check(c.get(JavacTrees.class), treeUtils); 20.70 + 20.71 + final int MAXROUNDS = 3; 20.72 + if (round < MAXROUNDS) 20.73 + generateSource("Gen" + round); 20.74 + 20.75 + return true; 20.76 + } 20.77 + 20.78 + <T> void check(T actual, T expected) { 20.79 +// messager.printMessage(NOTE, "expect: " + expected); 20.80 +// messager.printMessage(NOTE, "actual: " + actual); 20.81 + 20.82 + if (actual != expected) { 20.83 + messager.printMessage(ERROR, 20.84 + "round " + round + " unexpected value for " + expected.getClass().getName() + ": " + actual); 20.85 + } 20.86 + } 20.87 + 20.88 + void generateSource(String name) { 20.89 + String text = "class " + name + " { }\n"; 20.90 + 20.91 + try (Writer out = filer.createSourceFile(name).openWriter()) { 20.92 + out.write(text); 20.93 + } catch (IOException e) { 20.94 + throw new Error(e); 20.95 + } 20.96 + } 20.97 + 20.98 +} 20.99 +
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/test/tools/javac/processing/errors/TestParseErrors/ParseErrors.java Tue Oct 26 10:58:44 2010 -0700 21.3 @@ -0,0 +1,42 @@ 21.4 +/* 21.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 21.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 21.7 + * 21.8 + * This code is free software; you can redistribute it and/or modify it 21.9 + * under the terms of the GNU General Public License version 2 only, as 21.10 + * published by the Free Software Foundation. 21.11 + * 21.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 21.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 21.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 21.15 + * version 2 for more details (a copy is included in the LICENSE file that 21.16 + * accompanied this code). 21.17 + * 21.18 + * You should have received a copy of the GNU General Public License version 21.19 + * 2 along with this work; if not, write to the Free Software Foundation, 21.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21.21 + * 21.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21.23 + * or visit www.oracle.com if you need additional information or have any 21.24 + * questions. 21.25 + */ 21.26 + 21.27 +import java.util.List; 21.28 +import java.util.Vector; 21.29 + 21.30 +class test { 21.31 + 21.32 + public String m(List<? extends String> v, String s ) { 21.33 + return null; 21.34 + } 21.35 + 21.36 + public String m2(Vector<String> vs, String s) { 21.37 + return null; 21.38 + } 21.39 + 21.40 + public void m3(testclass<String>, 21.41 +} 21.42 + 21.43 +class testclass<T> { 21.44 + T t; 21.45 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/test/tools/javac/processing/errors/TestParseErrors/TestParseErrors.java Tue Oct 26 10:58:44 2010 -0700 22.3 @@ -0,0 +1,43 @@ 22.4 +/* 22.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 22.7 + * 22.8 + * This code is free software; you can redistribute it and/or modify it 22.9 + * under the terms of the GNU General Public License version 2 only, as 22.10 + * published by the Free Software Foundation. 22.11 + * 22.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 22.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 22.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 22.15 + * version 2 for more details (a copy is included in the LICENSE file that 22.16 + * accompanied this code). 22.17 + * 22.18 + * You should have received a copy of the GNU General Public License version 22.19 + * 2 along with this work; if not, write to the Free Software Foundation, 22.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22.21 + * 22.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22.23 + * or visit www.oracle.com if you need additional information or have any 22.24 + * questions. 22.25 + */ 22.26 + 22.27 +/* 22.28 + * @test 22.29 + * @bug 6988407 22.30 + * @summary javac crashes running processor on errant code; it used to print error message 22.31 + * @library ../../../lib 22.32 + * @build JavacTestingAbstractProcessor TestParseErrors 22.33 + * @compile/fail/ref=TestParseErrors.out -XDrawDiagnostics -proc:only -processor TestParseErrors ParseErrors.java 22.34 + */ 22.35 + 22.36 +import java.util.*; 22.37 +import javax.annotation.processing.*; 22.38 +import javax.lang.model.element.*; 22.39 + 22.40 +public class TestParseErrors extends JavacTestingAbstractProcessor { 22.41 + 22.42 + public boolean process(Set<? extends TypeElement> annotations, 22.43 + RoundEnvironment roundEnvironment) { 22.44 + throw new Error("Should not be called"); 22.45 + } 22.46 +}
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/test/tools/javac/processing/errors/TestParseErrors/TestParseErrors.out Tue Oct 26 10:58:44 2010 -0700 23.3 @@ -0,0 +1,8 @@ 23.4 +ParseErrors.java:37:37: compiler.err.expected: token.identifier 23.5 +ParseErrors.java:38:1: compiler.err.illegal.start.of.type 23.6 +ParseErrors.java:38:2: compiler.err.expected: ')' 23.7 +ParseErrors.java:40:6: compiler.err.expected: ';' 23.8 +ParseErrors.java:40:20: compiler.err.illegal.start.of.type 23.9 +ParseErrors.java:41:5: compiler.err.expected: '(' 23.10 +ParseErrors.java:41:8: compiler.err.expected: token.identifier 23.11 +7 errors
24.1 --- a/test/tools/javadoc/T4994049/FileWithTabs.java Thu Oct 21 17:12:55 2010 -0700 24.2 +++ b/test/tools/javadoc/T4994049/FileWithTabs.java Tue Oct 26 10:58:44 2010 -0700 24.3 @@ -22,5 +22,5 @@ 24.4 */ 24.5 24.6 public class FileWithTabs { 24.7 - public void tabbedMethod() {} 24.8 +\tpublic void tabbedMethod() {} 24.9 }
25.1 --- a/test/tools/javadoc/T4994049/T4994049.java Thu Oct 21 17:12:55 2010 -0700 25.2 +++ b/test/tools/javadoc/T4994049/T4994049.java Tue Oct 26 10:58:44 2010 -0700 25.3 @@ -30,7 +30,7 @@ 25.4 */ 25.5 25.6 import com.sun.javadoc.*; 25.7 -import java.io.File; 25.8 +import java.io.*; 25.9 import static com.sun.tools.javadoc.Main.execute; 25.10 25.11 public class T4994049 extends Doclet { 25.12 @@ -52,12 +52,47 @@ 25.13 return false; 25.14 } 25.15 25.16 - public static void main(String... args) { 25.17 + public static void main(String... args) throws Exception { 25.18 + File testSrc = new File(System.getProperty("test.src")); 25.19 + File tmpSrc = new File("tmpSrc"); 25.20 + initTabs(testSrc, tmpSrc); 25.21 + 25.22 for (String file : args) { 25.23 - File source = new File(System.getProperty("test.src", "."), file); 25.24 - if (execute("javadoc", "T4994049", T4994049.class.getClassLoader(), 25.25 - new String[]{source.getPath()} ) != 0) 25.26 - throw new Error(); 25.27 + File source = new File(tmpSrc, file); 25.28 + int rc = execute("javadoc", "T4994049", T4994049.class.getClassLoader(), 25.29 + new String[]{ source.getPath() } ); 25.30 + if (rc != 0) 25.31 + throw new Error("Unexpected return code from javadoc: " + rc); 25.32 + } 25.33 + } 25.34 + 25.35 + static void initTabs(File from, File to) throws IOException { 25.36 + for (File f: from.listFiles()) { 25.37 + File t = new File(to, f.getName()); 25.38 + if (f.isDirectory()) { 25.39 + initTabs(f, t); 25.40 + } else if (f.getName().endsWith(".java")) { 25.41 + write(t, read(f).replace("\\t", "\t")); 25.42 + } 25.43 + } 25.44 + } 25.45 + 25.46 + static String read(File f) throws IOException { 25.47 + StringBuilder sb = new StringBuilder(); 25.48 + try (BufferedReader in = new BufferedReader(new FileReader(f))) { 25.49 + String line; 25.50 + while ((line = in.readLine()) != null) { 25.51 + sb.append(line); 25.52 + sb.append("\n"); 25.53 + } 25.54 + } 25.55 + return sb.toString(); 25.56 + } 25.57 + 25.58 + static void write(File f, String s) throws IOException { 25.59 + f.getParentFile().mkdirs(); 25.60 + try (Writer out = new FileWriter(f)) { 25.61 + out.write(s); 25.62 } 25.63 } 25.64
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/test/tools/javah/4942232/ParamClassTest.java Tue Oct 26 10:58:44 2010 -0700 26.3 @@ -0,0 +1,36 @@ 26.4 +/* 26.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 26.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 26.7 + * 26.8 + * This code is free software; you can redistribute it and/or modify it 26.9 + * under the terms of the GNU General Public License version 2 only, as 26.10 + * published by the Free Software Foundation. 26.11 + * 26.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 26.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 26.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 26.15 + * version 2 for more details (a copy is included in the LICENSE file that 26.16 + * accompanied this code). 26.17 + * 26.18 + * You should have received a copy of the GNU General Public License version 26.19 + * 2 along with this work; if not, write to the Free Software Foundation, 26.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 26.21 + * 26.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 26.23 + * or visit www.oracle.com if you need additional information or have any 26.24 + * questions. 26.25 + */ 26.26 + 26.27 +public class ParamClassTest { 26.28 + static { 26.29 + System.loadLibrary("Test"); 26.30 + } 26.31 + 26.32 + public native void method(Param s); 26.33 + 26.34 + public static void main(String[] a) { 26.35 + } 26.36 +} 26.37 + 26.38 +class Param { 26.39 +}
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/test/tools/javah/4942232/Test.java Tue Oct 26 10:58:44 2010 -0700 27.3 @@ -0,0 +1,141 @@ 27.4 +/* 27.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 27.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 27.7 + * 27.8 + * This code is free software; you can redistribute it and/or modify it 27.9 + * under the terms of the GNU General Public License version 2 only, as 27.10 + * published by the Free Software Foundation. 27.11 + * 27.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 27.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 27.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 27.15 + * version 2 for more details (a copy is included in the LICENSE file that 27.16 + * accompanied this code). 27.17 + * 27.18 + * You should have received a copy of the GNU General Public License version 27.19 + * 2 along with this work; if not, write to the Free Software Foundation, 27.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 27.21 + * 27.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 27.23 + * or visit www.oracle.com if you need additional information or have any 27.24 + * questions. 27.25 + */ 27.26 + 27.27 +/* 27.28 + * @test 27.29 + * @bug 4942232 27.30 + * @summary missing param class processes without error 27.31 + * @build ParamClassTest Test 27.32 + * @run main Test 27.33 + */ 27.34 + 27.35 +import java.io.*; 27.36 +import java.util.*; 27.37 + 27.38 +public class Test { 27.39 + public static void main(String... args) throws Exception { 27.40 + new Test().run(); 27.41 + } 27.42 + 27.43 + void run() throws Exception { 27.44 + File testSrc = new File(System.getProperty("test.src")); 27.45 + File testClasses = new File(System.getProperty("test.classes")); 27.46 + 27.47 + // standard use of javah on valid class file 27.48 + String[] test1Args = { 27.49 + "-d", mkdir("test1/out").getPath(), 27.50 + "-classpath", testClasses.getPath(), 27.51 + "ParamClassTest" 27.52 + }; 27.53 + test(test1Args, 0); 27.54 + 27.55 + // extended use of javah on valid source file 27.56 + String[] test2Args = { 27.57 + "-d", mkdir("test2/out").getPath(), 27.58 + "-classpath", testSrc.getPath(), 27.59 + "ParamClassTest" 27.60 + }; 27.61 + test(test2Args, 0); 27.62 + 27.63 + // javah on class file with missing referents 27.64 + File test3Classes = mkdir("test3/classes"); 27.65 + copy(new File(testClasses, "ParamClassTest.class"), test3Classes); 27.66 + String[] test3Args = { 27.67 + "-d", mkdir("test3/out").getPath(), 27.68 + "-classpath", test3Classes.getPath(), 27.69 + "ParamClassTest" 27.70 + }; 27.71 + test(test3Args, 1); 27.72 + 27.73 + // javah on source file with missing referents 27.74 + File test4Src = mkdir("test4/src"); 27.75 + String paramClassTestSrc = readFile(new File(testSrc, "ParamClassTest.java")); 27.76 + writeFile(new File(test4Src, "ParamClassTest.java"), 27.77 + paramClassTestSrc.replaceAll("class Param \\{\\s+\\}", "")); 27.78 + String[] test4Args = { 27.79 + "-d", mkdir("test4/out").getPath(), 27.80 + "-classpath", test4Src.getPath(), 27.81 + "ParamClassTest" 27.82 + }; 27.83 + test(test4Args, 15); 27.84 + 27.85 + if (errors > 0) 27.86 + throw new Exception(errors + " errors occurred"); 27.87 + } 27.88 + 27.89 + void test(String[] args, int expect) { 27.90 + System.err.println("test: " + Arrays.asList(args)); 27.91 + int rc = javah(args); 27.92 + if (rc != expect) 27.93 + error("Unexpected return code: " + rc + "; expected: " + expect); 27.94 + } 27.95 + 27.96 + int javah(String... args) { 27.97 + StringWriter sw = new StringWriter(); 27.98 + PrintWriter pw = new PrintWriter(sw); 27.99 + int rc = com.sun.tools.javah.Main.run(args, pw); 27.100 + pw.close(); 27.101 + String out = sw.toString(); 27.102 + if (!out.isEmpty()) 27.103 + System.err.println(out); 27.104 + return rc; 27.105 + } 27.106 + 27.107 + File mkdir(String path) { 27.108 + File f = new File(path); 27.109 + f.mkdirs(); 27.110 + return f; 27.111 + } 27.112 + 27.113 + void copy(File from, File to) throws IOException { 27.114 + if (to.isDirectory()) 27.115 + to = new File(to, from.getName()); 27.116 + try (DataInputStream in = new DataInputStream(new FileInputStream(from)); 27.117 + FileOutputStream out = new FileOutputStream(to)) { 27.118 + byte[] buf = new byte[(int) from.length()]; 27.119 + in.readFully(buf); 27.120 + out.write(buf); 27.121 + } 27.122 + } 27.123 + 27.124 + String readFile(File f) throws IOException { 27.125 + try (DataInputStream in = new DataInputStream(new FileInputStream(f))) { 27.126 + byte[] buf = new byte[(int) f.length()]; 27.127 + in.readFully(buf); 27.128 + return new String(buf); 27.129 + } 27.130 + } 27.131 + 27.132 + void writeFile(File f, String body) throws IOException { 27.133 + try (FileWriter out = new FileWriter(f)) { 27.134 + out.write(body); 27.135 + } 27.136 + } 27.137 + 27.138 + void error(String msg) { 27.139 + System.err.println(msg); 27.140 + errors++; 27.141 + } 27.142 + 27.143 + int errors; 27.144 +}
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 28.2 +++ b/test/tools/javah/TestHelpOpts.java Tue Oct 26 10:58:44 2010 -0700 28.3 @@ -0,0 +1,81 @@ 28.4 +/* 28.5 + * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 28.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 28.7 + * 28.8 + * This code is free software; you can redistribute it and/or modify it 28.9 + * under the terms of the GNU General Public License version 2 only, as 28.10 + * published by the Free Software Foundation. 28.11 + * 28.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 28.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 28.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 28.15 + * version 2 for more details (a copy is included in the LICENSE file that 28.16 + * accompanied this code). 28.17 + * 28.18 + * You should have received a copy of the GNU General Public License version 28.19 + * 2 along with this work; if not, write to the Free Software Foundation, 28.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 28.21 + * 28.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 28.23 + * or visit www.oracle.com if you need additional information or have any 28.24 + * questions. 28.25 + */ 28.26 + 28.27 +/* 28.28 + * @test 28.29 + * @bug 6893932 6990390 28.30 + * @summary javah help screen lists -h and -? but does not accept them 28.31 + */ 28.32 + 28.33 +import java.io.*; 28.34 +import java.util.*; 28.35 + 28.36 +public class TestHelpOpts { 28.37 + public static void main(String... args) throws Exception { 28.38 + new TestHelpOpts().run(); 28.39 + } 28.40 + 28.41 + void run() throws Exception { 28.42 + Locale prev = Locale.getDefault(); 28.43 + try { 28.44 + Locale.setDefault(Locale.ENGLISH); 28.45 + 28.46 + String[] opts = { "-h", "-help", "-?", "--help" }; 28.47 + for (String opt: opts) 28.48 + test(opt); 28.49 + } finally { 28.50 + Locale.setDefault(prev); 28.51 + } 28.52 + 28.53 + if (errors > 0) 28.54 + throw new Exception(errors + " errors occurred"); 28.55 + } 28.56 + 28.57 + void test(String opt) { 28.58 + System.err.println("test " + opt); 28.59 + String[] args = { opt }; 28.60 + 28.61 + StringWriter sw = new StringWriter(); 28.62 + PrintWriter pw = new PrintWriter(sw); 28.63 + int rc = com.sun.tools.javah.Main.run(args, pw); 28.64 + pw.close(); 28.65 + String out = sw.toString(); 28.66 + if (!out.isEmpty()) 28.67 + System.err.println(out); 28.68 + if (rc != 0) 28.69 + error("Unexpected exit: rc=" + rc); 28.70 + 28.71 + String flat = out.replaceAll("\\s+", " "); // canonicalize whitespace 28.72 + if (!flat.contains("Usage: javah [options] <classes> where [options] include:")) 28.73 + error("expected text not found"); 28.74 + if (flat.contains("main.opt")) 28.75 + error("key not found in resource bundle: " + flat.replaceAll(".*(main.opt.[^ ]*).*", "$1")); 28.76 + } 28.77 + 28.78 + void error(String msg) { 28.79 + System.err.println(msg); 28.80 + errors++; 28.81 + } 28.82 + 28.83 + int errors; 28.84 +}