# HG changeset patch # User asaha # Date 1403794589 25200 # Node ID c14269602ffdddd8ea177894d970480a0536ea8a # Parent c8b8cabfc922f5aee1450bcc085f7a8f520d0400# Parent d231957fe3103e790465fcf058fb8cb33bbc4c4e Merge diff -r c8b8cabfc922 -r c14269602ffd .hgtags --- a/.hgtags Wed Jun 18 12:56:12 2014 -0700 +++ b/.hgtags Thu Jun 26 07:56:29 2014 -0700 @@ -303,3 +303,4 @@ b45fd486977d6cfe64c9947b7afd203c62ec4e98 jdk8u20-b17 a550336d045faa63ac4439d4901d9f36e0b634bf jdk8u20-b18 c04d99e00268ed87cfbdf76beb1a0ea08abd9a9c jdk8u20-b19 +e92effa22ecee1cb9965c278e45e2b1a6fbe0766 jdk8u20-b20 diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/classfile/Instruction.java --- a/src/share/classes/com/sun/tools/classfile/Instruction.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/classfile/Instruction.java Thu Jun 26 07:56:29 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,6 +25,8 @@ package com.sun.tools.classfile; +import java.util.Locale; + /** * See JVMS, chapter 6. * @@ -211,7 +213,7 @@ if (opcode == null) return "bytecode " + getUnsignedByte(0); else - return opcode.toString().toLowerCase(); + return opcode.toString().toLowerCase(Locale.US); } /** Get the length, in bytes, of this instruction, including the opcode diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java --- a/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/ConfigurationImpl.java Thu Jun 26 07:56:29 2014 -0700 @@ -37,6 +37,7 @@ import com.sun.tools.doclint.DocLint; import com.sun.tools.javac.file.JavacFileManager; import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.StringUtils; import com.sun.tools.javadoc.RootDocImpl; /** @@ -237,7 +238,7 @@ public void setSpecificDocletOptions(String[][] options) { for (int oi = 0; oi < options.length; ++oi) { String[] os = options[oi]; - String opt = os[0].toLowerCase(); + String opt = StringUtils.toLowerCase(os[0]); if (opt.equals("-footer")) { footer = os[1]; } else if (opt.equals("-header")) { @@ -325,7 +326,7 @@ return result; } // otherwise look for the options we have added - option = option.toLowerCase(); + option = StringUtils.toLowerCase(option); if (option.equals("-nodeprecatedlist") || option.equals("-noindex") || option.equals("-notree") || @@ -389,7 +390,7 @@ // otherwise look at our options for (int oi = 0; oi < options.length; ++oi) { String[] os = options[oi]; - String opt = os[0].toLowerCase(); + String opt = StringUtils.toLowerCase(os[0]); if (opt.equals("-helpfile")) { if (nohelp == true) { reporter.printError(getText("doclet.Option_conflict", diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java --- a/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/HtmlDocletWriter.java Thu Jun 26 07:56:29 2014 -0700 @@ -28,12 +28,15 @@ import java.io.*; import java.text.SimpleDateFormat; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import com.sun.javadoc.*; import com.sun.tools.doclets.formats.html.markup.*; import com.sun.tools.doclets.internal.toolkit.*; import com.sun.tools.doclets.internal.toolkit.taglets.*; import com.sun.tools.doclets.internal.toolkit.util.*; +import com.sun.tools.javac.util.StringUtils; /** * Class for the Html Format Code Generation specific to JavaDoc. @@ -138,42 +141,37 @@ if (index < 0) { return htmlstr; } - String lowerHtml = htmlstr.toLowerCase(); - // Return index of first occurrence of {@docroot} - // Note: {@docRoot} is not case sensitive when passed in w/command line option - index = lowerHtml.indexOf("{@docroot}", index); - if (index < 0) { + Matcher docrootMatcher = docrootPattern.matcher(htmlstr); + if (!docrootMatcher.find()) { return htmlstr; } StringBuilder buf = new StringBuilder(); - int previndex = 0; - while (true) { - final String docroot = "{@docroot}"; - // Search for lowercase version of {@docRoot} - index = lowerHtml.indexOf(docroot, previndex); - // If next {@docRoot} tag not found, append rest of htmlstr and exit loop - if (index < 0) { - buf.append(htmlstr.substring(previndex)); - break; - } - // If next {@docroot} tag found, append htmlstr up to start of tag - buf.append(htmlstr.substring(previndex, index)); - previndex = index + docroot.length(); - if (configuration.docrootparent.length() > 0 && htmlstr.startsWith("/..", previndex)) { + int prevEnd = 0; + do { + int match = docrootMatcher.start(); + // append htmlstr up to start of next {@docroot} + buf.append(htmlstr.substring(prevEnd, match)); + prevEnd = docrootMatcher.end(); + if (configuration.docrootparent.length() > 0 && htmlstr.startsWith("/..", prevEnd)) { // Insert the absolute link if {@docRoot} is followed by "/..". buf.append(configuration.docrootparent); - previndex += 3; + prevEnd += 3; } else { // Insert relative path where {@docRoot} was located buf.append(pathToRoot.isEmpty() ? "." : pathToRoot.getPath()); } // Append slash if next character is not a slash - if (previndex < htmlstr.length() && htmlstr.charAt(previndex) != '/') { + if (prevEnd < htmlstr.length() && htmlstr.charAt(prevEnd) != '/') { buf.append('/'); } - } + } while (docrootMatcher.find()); + buf.append(htmlstr.substring(prevEnd)); return buf.toString(); } + //where: + // Note: {@docRoot} is not case sensitive when passed in w/command line option: + private static final Pattern docrootPattern = + Pattern.compile(Pattern.quote("{@docroot}"), Pattern.CASE_INSENSITIVE); /** * Get the script to show or hide the All classes link. @@ -1689,13 +1687,13 @@ } //Redirect all relative links. - int end, begin = text.toLowerCase().indexOf("= 0){ StringBuilder textBuff = new StringBuilder(text); while(begin >=0){ if (textBuff.length() > begin + 2 && ! Character.isWhitespace(textBuff.charAt(begin+2))) { - begin = textBuff.toString().toLowerCase().indexOf("' && blockTags.contains(text.substring(tagPos, currPos).toLowerCase())) { + if (ch == '>' && blockTags.contains(StringUtils.toLowerCase(text.substring(tagPos, currPos)))) { result.append(text, startPos, lessThanPos); startPos = currPos + 1; } diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java --- a/src/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/MethodWriterImpl.java Thu Jun 26 07:56:29 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,6 +31,7 @@ import com.sun.tools.doclets.formats.html.markup.*; import com.sun.tools.doclets.internal.toolkit.*; import com.sun.tools.doclets.internal.toolkit.util.*; +import com.sun.tools.javac.util.StringUtils; /** * Writes method documentation in HTML format. @@ -331,24 +332,6 @@ } /** - * Parse the <Code> tag and return the text. - */ - protected String parseCodeTag(String tag){ - if(tag == null){ - return ""; - } - - String lc = tag.toLowerCase(); - int begin = lc.indexOf(""); - int end = lc.indexOf(""); - if(begin == -1 || end == -1 || end <= begin){ - return tag; - } else { - return tag.substring(begin + 6, end); - } - } - - /** * {@inheritDoc} */ protected static void addImplementsInfo(HtmlDocletWriter writer, diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlAttr.java --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlAttr.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlAttr.java Thu Jun 26 07:56:29 2014 -0700 @@ -25,6 +25,8 @@ package com.sun.tools.doclets.formats.html.markup; +import com.sun.tools.javac.util.StringUtils; + /** * Enum representing HTML tag attributes. * @@ -64,7 +66,7 @@ private final String value; HtmlAttr() { - this.value = name().toLowerCase(); + this.value = StringUtils.toLowerCase(name()); } HtmlAttr(String name) { diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTag.java --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTag.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlTag.java Thu Jun 26 07:56:29 2014 -0700 @@ -25,7 +25,7 @@ package com.sun.tools.doclets.formats.html.markup; -import java.util.Locale; +import com.sun.tools.javac.util.StringUtils; /** * Enum representing HTML tags. @@ -117,7 +117,7 @@ HtmlTag(BlockType blockType, EndTag endTag ) { this.blockType = blockType; this.endTag = endTag; - this.value = name().toLowerCase(Locale.US); + this.value = StringUtils.toLowerCase(name()); } /** diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/Configuration.java Thu Jun 26 07:56:29 2014 -0700 @@ -29,6 +29,7 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.tools.JavaFileManager; import com.sun.javadoc.*; import com.sun.tools.javac.sym.Profiles; @@ -36,7 +37,7 @@ import com.sun.tools.doclets.internal.toolkit.builders.BuilderFactory; import com.sun.tools.doclets.internal.toolkit.taglets.*; import com.sun.tools.doclets.internal.toolkit.util.*; -import javax.tools.JavaFileManager; +import com.sun.tools.javac.util.StringUtils; /** * Configure the output based on the options. Doclets should sub-class @@ -337,7 +338,7 @@ * Negative value means error occurred. */ public int optionLength(String option) { - option = option.toLowerCase(); + option = StringUtils.toLowerCase(option); if (option.equals("-author") || option.equals("-docfilessubdirs") || option.equals("-javafx") || @@ -454,7 +455,7 @@ // the output directory has already been created: so do that first. for (int oi = 0; oi < options.length; ++oi) { String[] os = options[oi]; - String opt = os[0].toLowerCase(); + String opt = StringUtils.toLowerCase(os[0]); if (opt.equals("-d")) { destDirName = addTrailingFileSep(os[1]); docFileDestDirName = destDirName; @@ -465,7 +466,7 @@ for (int oi = 0; oi < options.length; ++oi) { String[] os = options[oi]; - String opt = os[0].toLowerCase(); + String opt = StringUtils.toLowerCase(os[0]); if (opt.equals("-docfilessubdirs")) { copydocfilesubdirs = true; } else if (opt.equals("-docencoding")) { @@ -708,7 +709,7 @@ String encoding = ""; for (int oi = 0; oi < options.length; oi++) { String[] os = options[oi]; - String opt = os[0].toLowerCase(); + String opt = StringUtils.toLowerCase(os[0]); if (opt.equals("-docencoding")) { docencodingfound = true; if (!checkOutputFileEncoding(os[1], reporter)) { diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/MemberSummaryBuilder.java --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/MemberSummaryBuilder.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/MemberSummaryBuilder.java Thu Jun 26 07:56:29 2014 -0700 @@ -384,13 +384,13 @@ commentTextBuilder.append( MessageFormat.format( configuration.getText("doclet.PropertySetterWithName"), - Util.propertyNameFromMethodName(member.name()))); + Util.propertyNameFromMethodName(configuration, member.name()))); } if (isGetter) { commentTextBuilder.append( MessageFormat.format( configuration.getText("doclet.PropertyGetterWithName"), - Util.propertyNameFromMethodName(member.name()))); + Util.propertyNameFromMethodName(configuration, member.name()))); } if (propertyDoc.commentText() != null && !propertyDoc.commentText().isEmpty()) { diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/SerializedFormBuilder.java --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/SerializedFormBuilder.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/builders/SerializedFormBuilder.java Thu Jun 26 07:56:29 2014 -0700 @@ -31,6 +31,7 @@ import com.sun.javadoc.*; import com.sun.tools.doclets.internal.toolkit.*; import com.sun.tools.doclets.internal.toolkit.util.*; +import com.sun.tools.javac.util.StringUtils; /** * Builds the serialized form. @@ -567,7 +568,7 @@ } Tag[] serial = doc.tags("serial"); if (serial.length > 0) { - String serialtext = serial[0].text().toLowerCase(); + String serialtext = StringUtils.toLowerCase(serial[0].text()); if (serialtext.indexOf("exclude") >= 0) { return false; } else if (serialtext.indexOf("include") >= 0) { diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/SimpleTaglet.java --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/SimpleTaglet.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/SimpleTaglet.java Thu Jun 26 07:56:29 2014 -0700 @@ -28,6 +28,7 @@ import com.sun.javadoc.*; import com.sun.tools.doclets.internal.toolkit.Content; import com.sun.tools.doclets.internal.toolkit.util.DocFinder; +import com.sun.tools.javac.util.StringUtils; /** * A simple single argument custom tag. @@ -110,7 +111,7 @@ public SimpleTaglet(String tagName, String header, String locations) { this.tagName = tagName; this.header = header; - locations = locations.toLowerCase(); + locations = StringUtils.toLowerCase(locations); if (locations.indexOf(ALL) != -1 && locations.indexOf(EXCLUDED) == -1) { this.locations = PACKAGE + TYPE + FIELD + METHOD + CONSTRUCTOR + OVERVIEW; } else { diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/taglets/TagletManager.java Thu Jun 26 07:56:29 2014 -0700 @@ -35,6 +35,7 @@ import com.sun.javadoc.*; import com.sun.tools.doclets.internal.toolkit.util.*; +import com.sun.tools.javac.util.StringUtils; /** * Manages theTaglets used by doclets. @@ -304,7 +305,7 @@ return; } Taglet tag = customTags.get(tagName); - locations = locations.toLowerCase(); + locations = StringUtils.toLowerCase(locations); if (tag == null || header != null) { customTags.remove(tagName); customTags.put(tagName, new SimpleTaglet(tagName, header, locations)); @@ -375,7 +376,7 @@ name = name.substring(1, name.length()); } if (! (standardTags.contains(name) || customTags.containsKey(name))) { - if (standardTagsLowercase.contains(name.toLowerCase())) { + if (standardTagsLowercase.contains(StringUtils.toLowerCase(name))) { message.warning(tags[i].position(), "doclet.UnknownTagLowercase", tags[i].name()); continue; } else { @@ -708,7 +709,7 @@ private void initStandardTagsLowercase() { Iterator it = standardTags.iterator(); while (it.hasNext()) { - standardTagsLowercase.add(it.next().toLowerCase()); + standardTagsLowercase.add(StringUtils.toLowerCase(it.next())); } } diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/Util.java Thu Jun 26 07:56:29 2014 -0700 @@ -28,11 +28,12 @@ import java.io.*; import java.lang.annotation.ElementType; import java.util.*; +import javax.tools.StandardLocation; import com.sun.javadoc.*; import com.sun.javadoc.AnnotationDesc.ElementValuePair; import com.sun.tools.doclets.internal.toolkit.*; -import javax.tools.StandardLocation; +import com.sun.tools.javac.util.StringUtils; /** * Utilities Class for Doclets. @@ -253,8 +254,8 @@ */ private static class TypeComparator implements Comparator { public int compare(Type type1, Type type2) { - return type1.qualifiedTypeName().toLowerCase().compareTo( - type2.qualifiedTypeName().toLowerCase()); + return type1.qualifiedTypeName().compareToIgnoreCase( + type2.qualifiedTypeName()); } } @@ -589,7 +590,7 @@ typeName = "doclet.Enum"; } return config.getText( - lowerCaseOnly ? typeName.toLowerCase() : typeName); + lowerCaseOnly ? StringUtils.toLowerCase(typeName) : typeName); } /** @@ -724,7 +725,7 @@ * @param name name of the getter or setter method. * @return the name of the property of the given setter of getter. */ - public static String propertyNameFromMethodName(String name) { + public static String propertyNameFromMethodName(Configuration configuration, String name) { String propertyName = null; if (name.startsWith("get") || name.startsWith("set")) { propertyName = name.substring(3); @@ -734,7 +735,7 @@ if ((propertyName == null) || propertyName.isEmpty()){ return ""; } - return propertyName.substring(0, 1).toLowerCase() + return propertyName.substring(0, 1).toLowerCase(configuration.getLocale()) + propertyName.substring(1); } diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java Thu Jun 26 07:56:29 2014 -0700 @@ -702,7 +702,7 @@ private boolean isPropertyGetterOrSetter(MethodDoc[] members, MethodDoc methodDoc) { boolean found = false; - String propertyName = Util.propertyNameFromMethodName(methodDoc.name()); + String propertyName = Util.propertyNameFromMethodName(configuration, methodDoc.name()); if (!propertyName.isEmpty()) { String propertyMethodName = propertyName + "Property"; for (MethodDoc member: members) { diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/doclint/Checker.java --- a/src/share/classes/com/sun/tools/doclint/Checker.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclint/Checker.java Thu Jun 26 07:56:29 2014 -0700 @@ -80,6 +80,7 @@ import com.sun.source.util.TreePath; import com.sun.tools.doclint.HtmlTag.AttrKind; import com.sun.tools.javac.tree.DocPretty; +import com.sun.tools.javac.util.StringUtils; import static com.sun.tools.doclint.Messages.Group.*; @@ -243,7 +244,7 @@ markEnclosingTag(Flag.HAS_TEXT); String name = tree.getName().toString(); if (name.startsWith("#")) { - int v = name.toLowerCase().startsWith("#x") + int v = StringUtils.toLowerCase(name).startsWith("#x") ? Integer.parseInt(name.substring(2), 16) : Integer.parseInt(name.substring(1), 10); if (!Entity.isValid(v)) { diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/doclint/Env.java --- a/src/share/classes/com/sun/tools/doclint/Env.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclint/Env.java Thu Jun 26 07:56:29 2014 -0700 @@ -44,6 +44,7 @@ import com.sun.source.util.TreePath; import com.sun.tools.javac.model.JavacTypes; import com.sun.tools.javac.tree.JCTree; +import com.sun.tools.javac.util.StringUtils; /** * Utility container for current execution environment, @@ -66,7 +67,7 @@ static boolean accepts(String opt) { for (AccessKind g: values()) - if (opt.equals(g.name().toLowerCase())) return true; + if (opt.equals(StringUtils.toLowerCase(g.name()))) return true; return false; } diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/doclint/HtmlTag.java --- a/src/share/classes/com/sun/tools/doclint/HtmlTag.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclint/HtmlTag.java Thu Jun 26 07:56:29 2014 -0700 @@ -36,6 +36,7 @@ import javax.lang.model.element.Name; import static com.sun.tools.doclint.HtmlTag.Attr.*; +import com.sun.tools.javac.util.StringUtils; /** * Enum representing HTML tags. @@ -352,7 +353,7 @@ WIDTH; public String getText() { - return toLowerCase(name()); + return StringUtils.toLowerCase(name()); } static final Map index = new HashMap(); @@ -431,11 +432,11 @@ } public String getText() { - return toLowerCase(name()); + return StringUtils.toLowerCase(name()); } public Attr getAttr(Name attrName) { - return Attr.index.get(toLowerCase(attrName.toString())); + return Attr.index.get(StringUtils.toLowerCase(attrName.toString())); } public AttrKind getAttrKind(Name attrName) { @@ -457,10 +458,7 @@ } static HtmlTag get(Name tagName) { - return index.get(toLowerCase(tagName.toString())); + return index.get(StringUtils.toLowerCase(tagName.toString())); } - private static String toLowerCase(String s) { - return s.toLowerCase(Locale.US); - } } diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/doclint/Messages.java --- a/src/share/classes/com/sun/tools/doclint/Messages.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/doclint/Messages.java Thu Jun 26 07:56:29 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -42,6 +42,7 @@ import com.sun.source.doctree.DocTree; import com.sun.source.tree.Tree; import com.sun.tools.doclint.Env.AccessKind; +import com.sun.tools.javac.util.StringUtils; /** * Message reporting for DocLint. @@ -67,7 +68,7 @@ SYNTAX, REFERENCE; - String optName() { return name().toLowerCase(); } + String optName() { return StringUtils.toLowerCase(name()); } String notOptName() { return "-" + optName(); } static boolean accepts(String opt) { @@ -158,7 +159,7 @@ static boolean isValidOptions(String opts) { for (String opt: opts.split(",")) { - if (!isValidOption(opt.trim().toLowerCase())) + if (!isValidOption(StringUtils.toLowerCase(opt.trim()))) return false; } return true; @@ -203,7 +204,7 @@ setOption(ALL, Env.AccessKind.PRIVATE); else { for (String opt: opts.split(",")) - setOption(opt.trim().toLowerCase()); + setOption(StringUtils.toLowerCase(opt.trim())); } } @@ -215,7 +216,7 @@ int sep = arg.indexOf("/"); if (sep > 0) { - Env.AccessKind ak = Env.AccessKind.valueOf(arg.substring(sep + 1).toUpperCase()); + Env.AccessKind ak = Env.AccessKind.valueOf(StringUtils.toUpperCase(arg.substring(sep + 1))); setOption(arg.substring(0, sep), ak); } else { setOption(arg, null); @@ -290,7 +291,7 @@ out.println("By diagnostic kind..."); Table dkindTable = new Table(); for (Diagnostic.Kind k : Diagnostic.Kind.values()) { - dkindTable.put(k.toString().toLowerCase(), dkindCounts[k.ordinal()]); + dkindTable.put(StringUtils.toLowerCase(k.toString()), dkindCounts[k.ordinal()]); } dkindTable.print(out); out.println(); diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/code/Flags.java --- a/src/share/classes/com/sun/tools/javac/code/Flags.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Flags.java Thu Jun 26 07:56:29 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -33,6 +33,7 @@ import javax.lang.model.element.Modifier; import com.sun.tools.javac.util.Assert; +import com.sun.tools.javac.util.StringUtils; /** Access flags and other modifiers for Java classes and members. * @@ -275,6 +276,11 @@ */ public static final long LAMBDA_METHOD = 1L<<49; + /** + * Flag to control recursion in TransTypes + */ + public static final long TYPE_TRANSLATED = 1L<<50; + /** Modifier masks. */ public static final int @@ -294,7 +300,8 @@ ModifierFlags = ((long)StandardFlags & ~INTERFACE) | DEFAULT, InterfaceMethodMask = ABSTRACT | STATIC | PUBLIC | STRICTFP | DEFAULT, AnnotationTypeElementMask = ABSTRACT | PUBLIC, - LocalVarFlags = FINAL | PARAMETER; + LocalVarFlags = FINAL | PARAMETER, + ReceiverParamFlags = PARAMETER; public static Set asModifierSet(long flags) { @@ -384,11 +391,12 @@ BAD_OVERRIDE(Flags.BAD_OVERRIDE), SIGNATURE_POLYMORPHIC(Flags.SIGNATURE_POLYMORPHIC), THROWS(Flags.THROWS), - LAMBDA_METHOD(Flags.LAMBDA_METHOD); + LAMBDA_METHOD(Flags.LAMBDA_METHOD), + TYPE_TRANSLATED(Flags.TYPE_TRANSLATED); Flag(long flag) { this.value = flag; - this.lowercaseName = name().toLowerCase(); + this.lowercaseName = StringUtils.toLowerCase(name()); } @Override diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/code/Symbol.java --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java Thu Jun 26 07:56:29 2014 -0700 @@ -779,42 +779,41 @@ @Override public List getAnnotationMirrors() { - return onlyTypeVariableAnnotations(owner.getRawTypeAttributes()); - } - - private List onlyTypeVariableAnnotations( - List candidates) { - // Declaration annotations on TypeParameters are stored in type attributes + // Declaration annotations on type variables are stored in type attributes + // on the owner of the TypeVariableSymbol + List candidates = owner.getRawTypeAttributes(); + int index = owner.getTypeParameters().indexOf(this); List res = List.nil(); for (Attribute.TypeCompound a : candidates) { - if (a.position.type == TargetType.CLASS_TYPE_PARAMETER || - a.position.type == TargetType.METHOD_TYPE_PARAMETER) + if (isCurrentSymbolsAnnotation(a, index)) res = res.prepend(a); } - return res = res.reverse(); + return res.reverse(); } - - // Helper to getAnnotation[s] @Override public Attribute.Compound getAttribute(Class annoType) { - String name = annoType.getName(); // Declaration annotations on type variables are stored in type attributes // on the owner of the TypeVariableSymbol List candidates = owner.getRawTypeAttributes(); + int index = owner.getTypeParameters().indexOf(this); for (Attribute.TypeCompound anno : candidates) - if (anno.position.type == TargetType.CLASS_TYPE_PARAMETER || - anno.position.type == TargetType.METHOD_TYPE_PARAMETER) - if (name.contentEquals(anno.type.tsym.flatName())) - return anno; + if (isCurrentSymbolsAnnotation(anno, index) && + name.contentEquals(anno.type.tsym.flatName())) + return anno; return null; } - + //where: + boolean isCurrentSymbolsAnnotation(Attribute.TypeCompound anno, int index) { + return (anno.position.type == TargetType.CLASS_TYPE_PARAMETER || + anno.position.type == TargetType.METHOD_TYPE_PARAMETER) && + anno.position.parameter_index == index; + } @Override diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/code/Type.java --- a/src/share/classes/com/sun/tools/javac/code/Type.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Type.java Thu Jun 26 07:56:29 2014 -0700 @@ -72,13 +72,28 @@ public abstract class Type extends AnnoConstruct implements TypeMirror { /** Constant type: no type at all. */ - public static final JCNoType noType = new JCNoType(); + public static final JCNoType noType = new JCNoType() { + @Override + public String toString() { + return "none"; + } + }; /** Constant type: special type to be used during recovery of deferred expressions. */ - public static final JCNoType recoveryType = new JCNoType(); + public static final JCNoType recoveryType = new JCNoType(){ + @Override + public String toString() { + return "recovery"; + } + }; /** Constant type: special type to be used for marking stuck trees. */ - public static final JCNoType stuckType = new JCNoType(); + public static final JCNoType stuckType = new JCNoType() { + @Override + public String toString() { + return "stuck"; + } + }; /** If this switch is turned on, the names of type variables * and anonymous classes are printed with hashcodes appended. @@ -1643,9 +1658,6 @@ //only change bounds if request comes from substBounds super.addBound(ib, bound, types, update); } - else if (bound.hasTag(UNDETVAR) && !((UndetVar) bound).isCaptured()) { - ((UndetVar) bound).addBound(ib.complement(), this, types, false); - } } @Override diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/code/Types.java --- a/src/share/classes/com/sun/tools/javac/code/Types.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Thu Jun 26 07:56:29 2014 -0700 @@ -135,7 +135,7 @@ else return wildUpperBound(w.type); } - else return t; + else return t.unannotatedType(); } /** @@ -147,7 +147,7 @@ TypeVar v = (TypeVar) t.unannotatedType(); return v.isCaptured() ? cvarUpperBound(v.bound) : v; } - else return t; + else return t.unannotatedType(); } /** @@ -156,10 +156,10 @@ */ public Type wildLowerBound(Type t) { if (t.hasTag(WILDCARD)) { - WildcardType w = (WildcardType) t; + WildcardType w = (WildcardType) t.unannotatedType(); return w.isExtendsBound() ? syms.botType : wildLowerBound(w.type); } - else return t; + else return t.unannotatedType(); } /** @@ -167,10 +167,11 @@ * @param t a type */ public Type cvarLowerBound(Type t) { - if (t.hasTag(TYPEVAR) && ((TypeVar) t).isCaptured()) { - return cvarLowerBound(t.getLowerBound()); + if (t.hasTag(TYPEVAR)) { + TypeVar v = (TypeVar) t.unannotatedType(); + return v.isCaptured() ? cvarLowerBound(v.getLowerBound()) : v; } - else return t; + else return t.unannotatedType(); } // @@ -628,7 +629,7 @@ * (ii) perform functional interface bridge calculation. */ public ClassSymbol makeFunctionalInterfaceClass(Env env, Name name, List targets, long cflags) { - if (targets.isEmpty() || !isFunctionalInterface(targets.head)) { + if (targets.isEmpty()) { return null; } Symbol descSym = findDescriptorSymbol(targets.head.tsym); @@ -1221,14 +1222,35 @@ TypeRelation isSameTypeLoose = new LooseSameTypeVisitor(); private class LooseSameTypeVisitor extends SameTypeVisitor { + + /** cache of the type-variable pairs being (recursively) tested. */ + private Set cache = new HashSet<>(); + @Override boolean sameTypeVars(TypeVar tv1, TypeVar tv2) { - return tv1.tsym == tv2.tsym && visit(tv1.getUpperBound(), tv2.getUpperBound()); + return tv1.tsym == tv2.tsym && checkSameBounds(tv1, tv2); } @Override protected boolean containsTypes(List ts1, List ts2) { return containsTypeEquivalent(ts1, ts2); } + + /** + * Since type-variable bounds can be recursive, we need to protect against + * infinite loops - where the same bounds are checked over and over recursively. + */ + private boolean checkSameBounds(TypeVar tv1, TypeVar tv2) { + TypePair p = new TypePair(tv1, tv2, true); + if (cache.add(p)) { + try { + return visit(tv1.getUpperBound(), tv2.getUpperBound()); + } finally { + cache.remove(p); + } + } else { + return false; + } + } }; /** @@ -1375,7 +1397,7 @@ // debugContainsType(t, s); return isSameWildcard(t, s) || isCaptureOf(s, t) - || ((t.isExtendsBound() || isSubtypeNoCapture(wildLowerBound(t), wildLowerBound(s))) && + || ((t.isExtendsBound() || isSubtypeNoCapture(wildLowerBound(t), cvarLowerBound(wildLowerBound(s)))) && // TODO: JDK-8039214, cvarUpperBound call here is incorrect (t.isSuperBound() || isSubtypeNoCapture(cvarUpperBound(wildUpperBound(s)), wildUpperBound(t)))); } @@ -2278,7 +2300,7 @@ public Type visitType(Type t, Void ignored) { // A note on wildcards: there is no good way to // determine a supertype for a super bounded wildcard. - return null; + return Type.noType; } @Override @@ -2445,7 +2467,7 @@ return false; return t.isRaw() || - supertype(t) != null && isDerivedRaw(supertype(t)) || + supertype(t) != Type.noType && isDerivedRaw(supertype(t)) || isDerivedRaw(interfaces(t)); } @@ -3376,9 +3398,16 @@ class TypePair { final Type t1; final Type t2; + boolean strict; + TypePair(Type t1, Type t2) { + this(t1, t2, false); + } + + TypePair(Type t1, Type t2, boolean strict) { this.t1 = t1; this.t2 = t2; + this.strict = strict; } @Override public int hashCode() { @@ -3389,8 +3418,8 @@ if (!(obj instanceof TypePair)) return false; TypePair typePair = (TypePair)obj; - return isSameType(t1, typePair.t1) - && isSameType(t2, typePair.t2); + return isSameType(t1, typePair.t1, strict) + && isSameType(t2, typePair.t2, strict); } } Set mergeCache = new HashSet(); @@ -4670,7 +4699,7 @@ assembleClassSig(rawOuter ? types.erasure(outer) : outer); - append('.'); + append(rawOuter ? '$' : '.'); Assert.check(c.flatname.startsWith(c.owner.enclClass().flatname)); append(rawOuter ? c.flatname.subName(c.owner.enclClass().flatname.getByteLength() + 1, c.flatname.getByteLength()) diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/comp/Attr.java --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Thu Jun 26 07:56:29 2014 -0700 @@ -94,6 +94,7 @@ final Annotate annotate; final TypeAnnotations typeAnnotations; final DeferredLintHandler deferredLintHandler; + final TypeEnvs typeEnvs; public static Attr instance(Context context) { Attr instance = context.get(attrKey); @@ -123,6 +124,7 @@ annotate = Annotate.instance(context); typeAnnotations = TypeAnnotations.instance(context); deferredLintHandler = DeferredLintHandler.instance(context); + typeEnvs = TypeEnvs.instance(context); Options options = Options.instance(context); @@ -138,6 +140,7 @@ allowTypeAnnos = source.allowTypeAnnotations(); allowLambda = source.allowLambda(); allowDefaultMethods = source.allowDefaultMethods(); + allowStaticInterfaceMethods = source.allowStaticInterfaceMethods(); sourceName = source.name; relax = (options.isSet("-retrofit") || options.isSet("-relax")); @@ -195,6 +198,10 @@ */ boolean allowDefaultMethods; + /** Switch: static interface methods enabled? + */ + boolean allowStaticInterfaceMethods; + /** Switch: allow references to surrounding object from anonymous * objects during constructor call? */ @@ -427,7 +434,7 @@ } public Type attribType(JCTree node, TypeSymbol sym) { - Env env = enter.typeEnvs.get(sym); + Env env = typeEnvs.get(sym); Env localEnv = env.dup(node, env.info.dup()); return attribTree(node, localEnv, unknownTypeInfo); } @@ -2056,7 +2063,7 @@ tree.constructor = constructor.baseSymbol(); final TypeSymbol csym = clazztype.tsym; - ResultInfo diamondResult = new ResultInfo(MTH, newMethodTemplate(resultInfo.pt, argtypes, typeargtypes), new Check.NestedCheckContext(resultInfo.checkContext) { + ResultInfo diamondResult = new ResultInfo(pkind, newMethodTemplate(resultInfo.pt, argtypes, typeargtypes), new Check.NestedCheckContext(resultInfo.checkContext) { @Override public void report(DiagnosticPosition _unused, JCDiagnostic details) { enclosingContext.report(tree.clazz, @@ -2961,10 +2968,19 @@ if (checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.CHECK && pt != Type.recoveryType) { //check that functional interface class is well-formed - ClassSymbol csym = types.makeFunctionalInterfaceClass(env, - names.empty, List.of(fExpr.targets.head), ABSTRACT); - if (csym != null) { - chk.checkImplementations(env.tree, csym, csym); + try { + /* Types.makeFunctionalInterfaceClass() may throw an exception + * when it's executed post-inference. See the listener code + * above. + */ + ClassSymbol csym = types.makeFunctionalInterfaceClass(env, + names.empty, List.of(fExpr.targets.head), ABSTRACT); + if (csym != null) { + chk.checkImplementations(env.tree, csym, csym); + } + } catch (Types.FunctionDescriptorLookupError ex) { + JCDiagnostic cause = ex.getDiagnostic(); + resultInfo.checkContext.report(env.tree, cause); } } } @@ -3323,6 +3339,10 @@ tree.pos(), site, sym.name, true); } } + if (!allowStaticInterfaceMethods && sitesym.isInterface() && + sym.isStatic() && sym.kind == MTH) { + log.error(tree.pos(), "static.intf.method.invoke.not.supported.in.source", sourceName); + } } else if (sym.kind != ERR && (sym.flags() & STATIC) != 0 && sym.name != names._class) { // If the qualified item is not a type and the selected item is static, report // a warning. Make allowance for the class of an array type e.g. Object[].class) @@ -4042,7 +4062,7 @@ // ... and attribute the bound class c.flags_field |= UNATTRIBUTED; Env cenv = enter.classEnv(cd, env); - enter.typeEnvs.put(c, cenv); + typeEnvs.put(c, cenv); attribClass(c); return owntype; } @@ -4192,9 +4212,9 @@ c.flags_field &= ~UNATTRIBUTED; // Get environment current at the point of class definition. - Env env = enter.typeEnvs.get(c); - - // The info.lint field in the envs stored in enter.typeEnvs is deliberately uninitialized, + Env env = typeEnvs.get(c); + + // The info.lint field in the envs stored in typeEnvs is deliberately uninitialized, // because the annotations were not available at the time the env was created. Therefore, // we look up the environment chain for the first enclosing environment for which the // lint value is set. Typically, this is the parent env, but might be further if there diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/comp/Check.java --- a/src/share/classes/com/sun/tools/javac/comp/Check.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java Thu Jun 26 07:56:29 2014 -0700 @@ -1038,7 +1038,9 @@ switch (sym.kind) { case VAR: - if (sym.owner.kind != TYP) + if (TreeInfo.isReceiverParam(tree)) + mask = ReceiverParamFlags; + else if (sym.owner.kind != TYP) mask = LocalVarFlags; else if ((sym.owner.flags_field & INTERFACE) != 0) mask = implicit = InterfaceVarFlags; @@ -1813,6 +1815,11 @@ Type t1, Type t2, Type site) { + if ((site.tsym.flags() & COMPOUND) != 0) { + // special case for intersections: need to eliminate wildcards in supertypes + t1 = types.capture(t1); + t2 = types.capture(t2); + } return firstIncompatibility(pos, t1, t2, site) == null; } @@ -2672,7 +2679,7 @@ checkClassBounds(pos, seensofar, it); } Type st = types.supertype(type); - if (st != null) checkClassBounds(pos, seensofar, st); + if (st != Type.noType) checkClassBounds(pos, seensofar, st); } /** Enter interface into into set. diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java --- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java Thu Jun 26 07:56:29 2014 -0700 @@ -77,6 +77,7 @@ final Types types; final Flow flow; final Names names; + final TypeEnvs typeEnvs; public static DeferredAttr instance(Context context) { DeferredAttr instance = context.get(deferredAttrKey); @@ -100,6 +101,7 @@ flow = Flow.instance(context); names = Names.instance(context); stuckTree = make.Ident(names.empty).setType(Type.stuckType); + typeEnvs = TypeEnvs.instance(context); emptyDeferredAttrContext = new DeferredAttrContext(AttrMode.CHECK, null, MethodResolutionPhase.BOX, infer.emptyContext, null, null) { @Override @@ -400,7 +402,7 @@ //it is possible that nested expressions inside argument expression //are left unchecked - in such cases there's nothing to clean up. if (csym == null) return; - enter.typeEnvs.remove(csym); + typeEnvs.remove(csym); chk.compiled.remove(csym.flatname); syms.classes.remove(csym.flatname); super.visitClassDef(tree); @@ -928,7 +930,7 @@ LambdaReturnScanner() { super(EnumSet.of(BLOCK, CASE, CATCH, DOLOOP, FOREACHLOOP, - FORLOOP, RETURN, SYNCHRONIZED, SWITCH, TRY, WHILELOOP)); + FORLOOP, IF, RETURN, SYNCHRONIZED, SWITCH, TRY, WHILELOOP)); } } @@ -1218,25 +1220,102 @@ } //slow path + Symbol sym = quicklyResolveMethod(env, tree); + + if (sym == null) { + result = ArgumentExpressionKind.POLY; + return; + } + + result = analyzeCandidateMethods(sym, ArgumentExpressionKind.PRIMITIVE, + argumentKindAnalyzer); + } + //where + private boolean isSimpleReceiver(JCTree rec) { + switch (rec.getTag()) { + case IDENT: + return true; + case SELECT: + return isSimpleReceiver(((JCFieldAccess)rec).selected); + case TYPEAPPLY: + case TYPEARRAY: + return true; + case ANNOTATED_TYPE: + return isSimpleReceiver(((JCAnnotatedType)rec).underlyingType); + case APPLY: + return true; + default: + return false; + } + } + private ArgumentExpressionKind reduce(ArgumentExpressionKind kind) { + return argumentKindAnalyzer.reduce(result, kind); + } + MethodAnalyzer argumentKindAnalyzer = + new MethodAnalyzer() { + @Override + public ArgumentExpressionKind process(MethodSymbol ms) { + return ArgumentExpressionKind.methodKind(ms, types); + } + @Override + public ArgumentExpressionKind reduce(ArgumentExpressionKind kind1, + ArgumentExpressionKind kind2) { + switch (kind1) { + case PRIMITIVE: return kind2; + case NO_POLY: return kind2.isPoly() ? kind2 : kind1; + case POLY: return kind1; + default: + Assert.error(); + return null; + } + } + @Override + public boolean shouldStop(ArgumentExpressionKind result) { + return result.isPoly(); + } + }; + + @Override + public void visitLiteral(JCLiteral tree) { + Type litType = attr.litType(tree.typetag); + result = ArgumentExpressionKind.standaloneKind(litType, types); + } + + @Override + void skip(JCTree tree) { + result = ArgumentExpressionKind.NO_POLY; + } + + private Symbol quicklyResolveMethod(Env env, final JCMethodInvocation tree) { final JCExpression rec = tree.meth.hasTag(SELECT) ? ((JCFieldAccess)tree.meth).selected : null; if (rec != null && !isSimpleReceiver(rec)) { - //give up if receiver is too complex (to cut down analysis time) - result = ArgumentExpressionKind.POLY; - return; + return null; } - Type site = rec != null ? - attribSpeculative(rec, env, attr.unknownTypeExprInfo).type : - env.enclClass.sym.type; + Type site; - while (site.hasTag(TYPEVAR)) { - site = site.getUpperBound(); + if (rec != null) { + if (rec.hasTag(APPLY)) { + Symbol recSym = quicklyResolveMethod(env, (JCMethodInvocation) rec); + if (recSym == null) + return null; + Symbol resolvedReturnType = + analyzeCandidateMethods(recSym, syms.errSymbol, returnSymbolAnalyzer); + if (resolvedReturnType == null) + return null; + site = resolvedReturnType.type; + } else { + site = attribSpeculative(rec, env, attr.unknownTypeExprInfo).type; + } + } else { + site = env.enclClass.sym.type; } List args = rs.dummyArgs(tree.args.length()); + Name name = TreeInfo.name(tree.meth); Resolve.LookupHelper lh = rs.new LookupHelper(name, site, args, List.nil(), MethodResolutionPhase.VARARITY) { @Override @@ -1251,61 +1330,60 @@ } }; - Symbol sym = rs.lookupMethod(env, tree, site.tsym, rs.arityMethodCheck, lh); + return rs.lookupMethod(env, tree, site.tsym, rs.arityMethodCheck, lh); + } + //where: + MethodAnalyzer returnSymbolAnalyzer = new MethodAnalyzer() { + @Override + public Symbol process(MethodSymbol ms) { + ArgumentExpressionKind kind = ArgumentExpressionKind.methodKind(ms, types); + return kind != ArgumentExpressionKind.POLY ? ms.getReturnType().tsym : null; + } + @Override + public Symbol reduce(Symbol s1, Symbol s2) { + return s1 == syms.errSymbol ? s2 : s1 == s2 ? s1 : null; + } + @Override + public boolean shouldStop(Symbol result) { + return result == null; + } + }; - if (sym.kind == Kinds.AMBIGUOUS) { - Resolve.AmbiguityError err = (Resolve.AmbiguityError)sym.baseSymbol(); - result = ArgumentExpressionKind.PRIMITIVE; - for (Symbol s : err.ambiguousSyms) { - if (result.isPoly()) break; - if (s.kind == Kinds.MTH) { - result = reduce(ArgumentExpressionKind.methodKind(s, types)); + /** + * Process the result of Resolve.lookupMethod. If sym is a method symbol, the result of + * MethodAnalyzer.process is returned. If sym is an ambiguous symbol, all the candidate + * methods are inspected one by one, using MethodAnalyzer.process. The outcomes are + * reduced using MethodAnalyzer.reduce (using defaultValue as the first value over which + * the reduction runs). MethodAnalyzer.shouldStop can be used to stop the inspection early. + */ + E analyzeCandidateMethods(Symbol sym, E defaultValue, MethodAnalyzer analyzer) { + switch (sym.kind) { + case Kinds.MTH: + return analyzer.process((MethodSymbol) sym); + case Kinds.AMBIGUOUS: + Resolve.AmbiguityError err = (Resolve.AmbiguityError)sym.baseSymbol(); + E res = defaultValue; + for (Symbol s : err.ambiguousSyms) { + if (s.kind == Kinds.MTH) { + res = analyzer.reduce(res, analyzer.process((MethodSymbol) s)); + if (analyzer.shouldStop(res)) + return res; + } } - } - } else { - result = (sym.kind == Kinds.MTH) ? - ArgumentExpressionKind.methodKind(sym, types) : - ArgumentExpressionKind.NO_POLY; + return res; + default: + return defaultValue; } } - //where - private boolean isSimpleReceiver(JCTree rec) { - switch (rec.getTag()) { - case IDENT: - return true; - case SELECT: - return isSimpleReceiver(((JCFieldAccess)rec).selected); - case TYPEAPPLY: - case TYPEARRAY: - return true; - case ANNOTATED_TYPE: - return isSimpleReceiver(((JCAnnotatedType)rec).underlyingType); - default: - return false; - } - } - private ArgumentExpressionKind reduce(ArgumentExpressionKind kind) { - switch (result) { - case PRIMITIVE: return kind; - case NO_POLY: return kind.isPoly() ? kind : result; - case POLY: return result; - default: - Assert.error(); - return null; - } - } + } - @Override - public void visitLiteral(JCLiteral tree) { - Type litType = attr.litType(tree.typetag); - result = ArgumentExpressionKind.standaloneKind(litType, types); - } + /** Analyzer for methods - used by analyzeCandidateMethods. */ + interface MethodAnalyzer { + E process(MethodSymbol ms); + E reduce(E e1, E e2); + boolean shouldStop(E result); + } - @Override - void skip(JCTree tree) { - result = ArgumentExpressionKind.NO_POLY; - } - } //where private EnumSet deferredCheckerTags = EnumSet.of(LAMBDA, REFERENCE, PARENS, TYPECAST, diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/comp/Enter.java --- a/src/share/classes/com/sun/tools/javac/comp/Enter.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Enter.java Thu Jun 26 07:56:29 2014 -0700 @@ -105,6 +105,7 @@ Names names; JavaFileManager fileManager; PkgInfo pkginfoOpt; + TypeEnvs typeEnvs; private final Todo todo; @@ -142,14 +143,9 @@ Options options = Options.instance(context); pkginfoOpt = PkgInfo.get(options); + typeEnvs = TypeEnvs.instance(context); } - /** A hashtable mapping classes and packages to the environments current - * at the points of their definitions. - */ - Map> typeEnvs = - new HashMap>(); - /** Accessor for typeEnvs */ public Env getEnv(TypeSymbol sym) { diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/comp/Flow.java --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java Thu Jun 26 07:56:29 2014 -0700 @@ -232,7 +232,8 @@ } } - public List analyzeLambdaThrownTypes(Env env, JCLambda that, TreeMaker make) { + public List analyzeLambdaThrownTypes(final Env env, + JCLambda that, TreeMaker make) { //we need to disable diagnostics temporarily; the problem is that if //a lambda expression contains e.g. an unreachable statement, an error //message will be reported and will cause compilation to skip the flow analyis @@ -240,7 +241,13 @@ //related errors, which will allow for more errors to be detected Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log); try { - new AssignAnalyzer(log, syms, lint, names, enforceThisDotInit).analyzeTree(env); + new AssignAnalyzer(log, syms, lint, names, enforceThisDotInit) { + @Override + protected boolean trackable(VarSymbol sym) { + return !env.info.scope.includes(sym) && + sym.owner.kind == MTH; + } + }.analyzeTree(env); LambdaFlowAnalyzer flowAnalyzer = new LambdaFlowAnalyzer(); flowAnalyzer.analyzeTree(env, that, make); return flowAnalyzer.inferredThrownTypes; diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/comp/Lower.java --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java Thu Jun 26 07:56:29 2014 -0700 @@ -82,6 +82,7 @@ private ConstFold cfolder; private Target target; private Source source; + private final TypeEnvs typeEnvs; private boolean allowEnums; private final Name dollarAssertionsDisabled; private final Name classDollar; @@ -103,6 +104,7 @@ cfolder = ConstFold.instance(context); target = Target.instance(context); source = Source.instance(context); + typeEnvs = TypeEnvs.instance(context); allowEnums = source.allowEnums(); dollarAssertionsDisabled = names. fromString(target.syntheticNameChar() + "assertionsDisabled"); @@ -2452,10 +2454,16 @@ } public void visitClassDef(JCClassDecl tree) { + Env prevEnv = attrEnv; ClassSymbol currentClassPrev = currentClass; MethodSymbol currentMethodSymPrev = currentMethodSym; + currentClass = tree.sym; currentMethodSym = null; + attrEnv = typeEnvs.remove(currentClass); + if (attrEnv == null) + attrEnv = prevEnv; + classdefs.put(currentClass, tree); proxies = proxies.dup(currentClass); @@ -2527,6 +2535,7 @@ // Append translated tree to `translated' queue. translated.append(tree); + attrEnv = prevEnv; currentClass = currentClassPrev; currentMethodSym = currentMethodSymPrev; diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/comp/MemberEnter.java --- a/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/MemberEnter.java Thu Jun 26 07:56:29 2014 -0700 @@ -86,6 +86,7 @@ private final Target target; private final DeferredLintHandler deferredLintHandler; private final Lint lint; + private final TypeEnvs typeEnvs; public static MemberEnter instance(Context context) { MemberEnter instance = context.get(memberEnterKey); @@ -113,6 +114,7 @@ target = Target.instance(context); deferredLintHandler = DeferredLintHandler.instance(context); lint = Lint.instance(context); + typeEnvs = TypeEnvs.instance(context); allowTypeAnnos = source.allowTypeAnnotations(); allowRepeatedAnnos = source.allowRepeatedAnnotations(); } @@ -652,22 +654,8 @@ attr.attribIdentAsEnumType(localEnv, (JCIdent)tree.vartype); } else { attr.attribType(tree.vartype, localEnv); - if (tree.nameexpr != null) { - attr.attribExpr(tree.nameexpr, localEnv); - MethodSymbol m = localEnv.enclMethod.sym; - if (m.isConstructor()) { - Type outertype = m.owner.owner.type; - if (outertype.hasTag(TypeTag.CLASS)) { - checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type"); - checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name"); - } else { - log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class"); - } - } else { - checkType(tree.vartype, m.owner.type, "incorrect.receiver.type"); - checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name"); - } - } + if (TreeInfo.isReceiverParam(tree)) + checkReceiver(tree, localEnv); } } finally { deferredLintHandler.setPos(prevLintPos); @@ -714,6 +702,26 @@ log.error(tree, diag, type, tree.type); } } + void checkReceiver(JCVariableDecl tree, Env localEnv) { + attr.attribExpr(tree.nameexpr, localEnv); + MethodSymbol m = localEnv.enclMethod.sym; + if (m.isConstructor()) { + Type outertype = m.owner.owner.type; + if (outertype.hasTag(TypeTag.METHOD)) { + // we have a local inner class + outertype = m.owner.owner.owner.type; + } + if (outertype.hasTag(TypeTag.CLASS)) { + checkType(tree.vartype, outertype, "incorrect.constructor.receiver.type"); + checkType(tree.nameexpr, outertype, "incorrect.constructor.receiver.name"); + } else { + log.error(tree, "receiver.parameter.not.applicable.constructor.toplevel.class"); + } + } else { + checkType(tree.vartype, m.owner.type, "incorrect.receiver.type"); + checkType(tree.nameexpr, m.owner.type, "incorrect.receiver.name"); + } + } public boolean needsLazyConstValue(JCTree tree) { InitTreeVisitor initTreeVisitor = new InitTreeVisitor(); @@ -1018,7 +1026,7 @@ ClassSymbol c = (ClassSymbol)sym; ClassType ct = (ClassType)c.type; - Env env = enter.typeEnvs.get(c); + Env env = typeEnvs.get(c); JCClassDecl tree = (JCClassDecl)env.tree; boolean wasFirst = isFirst; isFirst = false; diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/comp/TransTypes.java --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java Thu Jun 26 07:56:29 2014 -0700 @@ -967,10 +967,11 @@ translateClass((ClassSymbol)st.tsym); } - Env myEnv = enter.typeEnvs.remove(c); - if (myEnv == null) { + Env myEnv = enter.getEnv(c); + if (myEnv == null || (c.flags_field & TYPE_TRANSLATED) != 0) { return; } + c.flags_field |= TYPE_TRANSLATED; /* The two assertions below are set for early detection of any attempt * to translate a class that: diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/comp/TypeEnvs.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/com/sun/tools/javac/comp/TypeEnvs.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.tools.javac.comp; + +import java.util.Collection; +import java.util.HashMap; +import com.sun.tools.javac.code.Symbol.TypeSymbol; +import com.sun.tools.javac.util.Context; + +/** This class contains the type environments used by Enter, MemberEnter, + * Attr, DeferredAttr, and Lower. + * + *

This is NOT part of any supported API. + * If you write code that depends on this, you do so at your own risk. + * This code and its internal interfaces are subject to change or + * deletion without notice. + */ +class TypeEnvs { + private static final long serialVersionUID = 571524752489954631L; + + protected static final Context.Key typeEnvsKey = new Context.Key<>(); + public static TypeEnvs instance(Context context) { + TypeEnvs instance = context.get(typeEnvsKey); + if (instance == null) + instance = new TypeEnvs(context); + return instance; + } + + private HashMap> map; + protected TypeEnvs(Context context) { + map = new HashMap<>(); + context.put(typeEnvsKey, this); + } + + Env get(TypeSymbol sym) { return map.get(sym); } + Env put(TypeSymbol sym, Env env) { return map.put(sym, env); } + Env remove(TypeSymbol sym) { return map.remove(sym); } + Collection> values() { return map.values(); } + void clear() { map.clear(); } +} diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/file/Locations.java --- a/src/share/classes/com/sun/tools/javac/file/Locations.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/file/Locations.java Thu Jun 26 07:56:29 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -51,6 +51,7 @@ import com.sun.tools.javac.util.ListBuffer; import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.Options; +import com.sun.tools.javac.util.StringUtils; import javax.tools.JavaFileManager; import javax.tools.StandardJavaFileManager; @@ -717,7 +718,7 @@ /** Is this the name of an archive file? */ private boolean isArchive(File file) { - String n = file.getName().toLowerCase(); + String n = StringUtils.toLowerCase(file.getName()); return fsInfo.isFile(file) && (n.endsWith(".jar") || n.endsWith(".zip")); } diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/jvm/Code.java --- a/src/share/classes/com/sun/tools/javac/jvm/Code.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/jvm/Code.java Thu Jun 26 07:56:29 2014 -0700 @@ -1925,6 +1925,13 @@ return aliveRanges.isEmpty() ? null : aliveRanges.get(aliveRanges.size() - 1); } + void removeLastRange() { + Range lastRange = lastRange(); + if (lastRange != null) { + aliveRanges.remove(lastRange); + } + } + @Override public String toString() { if (aliveRanges == null) { @@ -1955,9 +1962,7 @@ } } } else { - if (!aliveRanges.isEmpty()) { - aliveRanges.remove(aliveRanges.size() - 1); - } + removeLastRange(); } } @@ -1965,16 +1970,14 @@ if (aliveRanges.isEmpty()) { return false; } - Range range = lastRange(); - return range.length == Character.MAX_VALUE; + return lastRange().length == Character.MAX_VALUE; } public boolean isLastRangeInitialized() { if (aliveRanges.isEmpty()) { return false; } - Range range = lastRange(); - return range.start_pc != Character.MAX_VALUE; + return lastRange().start_pc != Character.MAX_VALUE; } public Range getWidestRange() { @@ -2095,7 +2098,7 @@ v.closeRange(length); putVar(v); } else { - v.lastRange().start_pc = Character.MAX_VALUE; + v.removeLastRange(); } } } diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/jvm/Gen.java --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java Thu Jun 26 07:56:29 2014 -0700 @@ -1811,8 +1811,7 @@ genStat(tree.thenpart, env, CRT_STATEMENT | CRT_FLOW_TARGET); thenExit = code.branch(goto_); if (varDebugInfo && lvtRanges.containsKey(code.meth, tree.thenpart)) { - code.closeAliveRanges(tree.thenpart, - thenExit != null && tree.elsepart == null ? thenExit.pc : code.cp); + code.closeAliveRanges(tree.thenpart, code.cp); } } if (elseChain != null) { diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/main/Option.java --- a/src/share/classes/com/sun/tools/javac/main/Option.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/main/Option.java Thu Jun 26 07:56:29 2014 -0700 @@ -47,6 +47,7 @@ import com.sun.tools.javac.util.Log.PrefixKind; import com.sun.tools.javac.util.Log.WriterKind; import com.sun.tools.javac.util.Options; +import com.sun.tools.javac.util.StringUtils; import static com.sun.tools.javac.main.Option.ChoiceKind.*; import static com.sun.tools.javac.main.Option.OptionGroup.*; import static com.sun.tools.javac.main.Option.OptionKind.*; @@ -713,7 +714,7 @@ String v = options.get(XPKGINFO); return (v == null ? PkgInfo.LEGACY - : PkgInfo.valueOf(v.toUpperCase())); + : PkgInfo.valueOf(StringUtils.toUpperCase(v))); } } diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/parser/DocCommentParser.java --- a/src/share/classes/com/sun/tools/javac/parser/DocCommentParser.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/parser/DocCommentParser.java Thu Jun 26 07:56:29 2014 -0700 @@ -57,6 +57,7 @@ import com.sun.tools.javac.util.Names; import com.sun.tools.javac.util.Options; import com.sun.tools.javac.util.Position; +import com.sun.tools.javac.util.StringUtils; import static com.sun.tools.javac.util.LayoutCharacters.*; /** @@ -993,7 +994,7 @@ "h1", "h2", "h3", "h4", "h5", "h6", "p", "pre")); protected boolean isSentenceBreak(Name n) { - return htmlBlockTags.contains(n.toString().toLowerCase()); + return htmlBlockTags.contains(StringUtils.toLowerCase(n.toString())); } protected boolean isSentenceBreak(DCTree t) { diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/parser/JavacParser.java --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java Thu Jun 26 07:56:29 2014 -0700 @@ -4068,15 +4068,16 @@ */ protected static class SimpleEndPosTable extends AbstractEndPosTable { - private final Map endPosMap; + private final IntHashTable endPosMap; SimpleEndPosTable(JavacParser parser) { super(parser); - endPosMap = new HashMap(); + endPosMap = new IntHashTable(); } public void storeEnd(JCTree tree, int endpos) { - endPosMap.put(tree, errorEndPos > endpos ? errorEndPos : endpos); + endPosMap.putAtIndex(tree, errorEndPos > endpos ? errorEndPos : endpos, + endPosMap.lookup(tree)); } protected T to(T t) { @@ -4090,14 +4091,15 @@ } public int getEndPos(JCTree tree) { - Integer value = endPosMap.get(tree); - return (value == null) ? Position.NOPOS : value; + int value = endPosMap.getFromIndex(endPosMap.lookup(tree)); + // As long as Position.NOPOS==-1, this just returns value. + return (value == -1) ? Position.NOPOS : value; } public int replaceTree(JCTree oldTree, JCTree newTree) { - Integer pos = endPosMap.remove(oldTree); - if (pos != null) { - endPosMap.put(newTree, pos); + int pos = endPosMap.remove(oldTree); + if (pos != -1) { + storeEnd(newTree, pos); return pos; } return Position.NOPOS; diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java --- a/src/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/processing/PrintingProcessor.java Thu Jun 26 07:56:29 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,6 +36,7 @@ import java.io.PrintWriter; import java.io.Writer; import java.util.*; +import com.sun.tools.javac.util.StringUtils; /** * A processor which prints out elements. Used to implement the @@ -202,7 +203,7 @@ writer.print("@interface"); break; default: - writer.print(kind.toString().toLowerCase()); + writer.print(StringUtils.toLowerCase(kind.toString())); } writer.print(" "); writer.print(e.getSimpleName()); diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/resources/compiler.properties --- a/src/share/classes/com/sun/tools/javac/resources/compiler.properties Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/resources/compiler.properties Thu Jun 26 07:56:29 2014 -0700 @@ -2390,6 +2390,11 @@ static interface methods are not supported in -source {0}\n\ (use -source 8 or higher to enable static interface methods) +# 0: string +compiler.err.static.intf.method.invoke.not.supported.in.source=\ + static interface method invocations are not supported in -source {0}\n\ + (use -source 8 or higher to enable static interface method invocations) + ######################################## # Diagnostics for verbose resolution # used by Resolve (debug only) diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/tree/TreeInfo.java --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java Thu Jun 26 07:56:29 2014 -0700 @@ -135,6 +135,14 @@ } } + public static boolean isReceiverParam(JCTree tree) { + if (tree.hasTag(VARDEF)) { + return ((JCVariableDecl)tree).nameexpr != null; + } else { + return false; + } + } + /** Is there a constructor declaration in the given list of trees? */ public static boolean hasConstructors(List trees) { diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/util/IntHashTable.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/com/sun/tools/javac/util/IntHashTable.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.tools.javac.util; + +/** + * A hash table that maps Object to int. + * + * This is a custom hash table optimised for the Object -> int + * maps. This is done to avoid unnecessary object allocation in the image set. + * + * @author Charles Turner + * @author Per Bothner + */ +public class IntHashTable { + private static final int DEFAULT_INITIAL_SIZE = 64; + protected Object[] objs; // the domain set + protected int[] ints; // the image set + protected int mask; // used to clip int's into the domain + protected int num_bindings; // the number of mappings (including DELETED) + private final static Object DELETED = new Object(); + + /** + * Construct an Object -> int hash table. + * + * The default size of the hash table is 64 mappings. + */ + public IntHashTable() { + objs = new Object[DEFAULT_INITIAL_SIZE]; + ints = new int[DEFAULT_INITIAL_SIZE]; + mask = DEFAULT_INITIAL_SIZE - 1; + } + + /** + * Construct an Object -> int hash table with a specified amount of mappings. + * @param capacity The number of default mappings in this hash table. + */ + public IntHashTable(int capacity) { + int log2Size = 4; + while (capacity > (1 << log2Size)) { + log2Size++; + } + capacity = 1 << log2Size; + objs = new Object[capacity]; + ints = new int[capacity]; + mask = capacity - 1; + } + + /** + * Compute the hash code of a given object. + * + * @param key The object whose hash code is to be computed. + * @return zero if the object is null, otherwise the identityHashCode + */ + public int hash(Object key) { + return System.identityHashCode(key); + } + + /** + * Find either the index of a key's value, or the index of an available space. + * + * @param key The key to whose value you want to find. + * @param hash The hash code of this key. + * @return Either the index of the key's value, or an index pointing to + * unoccupied space. + */ + public int lookup(Object key, int hash) { + Object node; + int hash1 = hash ^ (hash >>> 15); + int hash2 = (hash ^ (hash << 6)) | 1; //ensure coprimeness + int deleted = -1; + for (int i = hash1 & mask;; i = (i + hash2) & mask) { + node = objs[i]; + if (node == key) + return i; + if (node == null) + return deleted >= 0 ? deleted : i; + if (node == DELETED && deleted < 0) + deleted = i; + } + } + + /** + * Lookup a given key's value in the hash table. + * + * @param key The key whose value you want to find. + * @return Either the index of the key's value, or an index pointing to + * unoccupied space. + */ + public int lookup(Object key) { + return lookup(key, hash(key)); + } + + /** + * Return the value stored at the specified index in the table. + * + * @param index The index to inspect, as returned from {@link #lookup} + * @return A non-negative integer if the index contains a non-null + * value, or -1 if it does. + */ + public int getFromIndex(int index) { + Object node = objs[index]; + return node == null || node == DELETED ? -1 : ints[index]; + } + + /** + * Associates the specified key with the specified value in this map. + * + * @param key key with which the specified value is to be associated. + * @param value value to be associated with the specified key. + * @param index the index at which to place this binding, as returned + * from {@link #lookup}. + * @return previous value associated with specified key, or -1 if there was + * no mapping for key. + */ + public int putAtIndex(Object key, int value, int index) { + Object old = objs[index]; + if (old == null || old == DELETED) { + objs[index] = key; + ints[index] = value; + if (old != DELETED) + num_bindings++; + if (3 * num_bindings >= 2 * objs.length) + rehash(); + return -1; + } else { // update existing mapping + int oldValue = ints[index]; + ints[index] = value; + return oldValue; + } + } + + public int remove(Object key) { + int index = lookup(key); + Object old = objs[index]; + if (old == null || old == DELETED) + return -1; + objs[index] = DELETED; + return ints[index]; + } + + /** + * Expand the hash table when it exceeds the load factor. + * + * Rehash the existing objects. + */ + protected void rehash() { + Object[] oldObjsTable = objs; + int[] oldIntsTable = ints; + int oldCapacity = oldObjsTable.length; + int newCapacity = oldCapacity << 1; + Object[] newObjTable = new Object[newCapacity]; + int[] newIntTable = new int[newCapacity]; + int newMask = newCapacity - 1; + objs = newObjTable; + ints = newIntTable; + mask = newMask; + num_bindings = 0; // this is recomputed below + Object key; + for (int i = oldIntsTable.length; --i >= 0;) { + key = oldObjsTable[i]; + if (key != null && key != DELETED) + putAtIndex(key, oldIntsTable[i], lookup(key, hash(key))); + } + } + + /** + * Removes all mappings from this map. + */ + public void clear() { + for (int i = objs.length; --i >= 0;) { + objs[i] = null; + } + num_bindings = 0; + } +} diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java --- a/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javac/util/JCDiagnostic.java Thu Jun 26 07:56:29 2014 -0700 @@ -355,13 +355,41 @@ private final DiagnosticType type; private final DiagnosticSource source; private final DiagnosticPosition position; - private final int line; - private final int column; private final String key; protected final Object[] args; private final Set flags; private final LintCategory lintCategory; + /** source line position (set lazily) */ + private SourcePosition sourcePosition; + + /** + * This class is used to defer the line/column position fetch logic after diagnostic construction. + */ + class SourcePosition { + + private final int line; + private final int column; + + SourcePosition() { + int n = (position == null ? Position.NOPOS : position.getPreferredPosition()); + if (n == Position.NOPOS || source == null) + line = column = -1; + else { + line = source.getLineNumber(n); + column = source.getColumnNumber(n, true); + } + } + + public int getLineNumber() { + return line; + } + + public int getColumnNumber() { + return column; + } + } + /** * Create a diagnostic object. * @param formatter the formatter to use for the diagnostic @@ -391,14 +419,6 @@ this.position = pos; this.key = key; this.args = args; - - int n = (pos == null ? Position.NOPOS : pos.getPreferredPosition()); - if (n == Position.NOPOS || source == null) - line = column = -1; - else { - line = source.getLineNumber(n); - column = source.getColumnNumber(n, true); - } } /** @@ -495,7 +515,10 @@ * @return the line number within the source referred to by this diagnostic */ public long getLineNumber() { - return line; + if (sourcePosition == null) { + sourcePosition = new SourcePosition(); + } + return sourcePosition.getLineNumber(); } /** @@ -503,7 +526,10 @@ * @return the column number within the line of source referred to by this diagnostic */ public long getColumnNumber() { - return column; + if (sourcePosition == null) { + sourcePosition = new SourcePosition(); + } + return sourcePosition.getColumnNumber(); } /** diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javac/util/StringUtils.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/share/classes/com/sun/tools/javac/util/StringUtils.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.tools.javac.util; + +import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** A collection of utilities for String manipulation. + * + *

This is NOT part of any supported API. + * If you write code that depends on this, you do so at your own risk. + * This code and its internal interfaces are subject to change or + * deletion without notice. + */ +public class StringUtils { + + /**Converts the given String to lower case using the {@link Locale#US US Locale}. The result + * is independent of the default Locale in the current JVM instance. + */ + public static String toLowerCase(String source) { + return source.toLowerCase(Locale.US); + } + + /**Converts the given String to upper case using the {@link Locale#US US Locale}. The result + * is independent of the default Locale in the current JVM instance. + */ + public static String toUpperCase(String source) { + return source.toUpperCase(Locale.US); + } + + /**Case insensitive version of {@link String#indexOf(java.lang.String)}. Equivalent to + * {@code text.indexOf(str)}, except the matching is case insensitive. + */ + public static int indexOfIgnoreCase(String text, String str) { + return indexOfIgnoreCase(text, str, 0); + } + + /**Case insensitive version of {@link String#indexOf(java.lang.String, int)}. Equivalent to + * {@code text.indexOf(str, startIndex)}, except the matching is case insensitive. + */ + public static int indexOfIgnoreCase(String text, String str, int startIndex) { + Matcher m = Pattern.compile(Pattern.quote(str), Pattern.CASE_INSENSITIVE).matcher(text); + return m.find(startIndex) ? m.start() : -1; + } + +} diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javap/AttributeWriter.java --- a/src/share/classes/com/sun/tools/javap/AttributeWriter.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javap/AttributeWriter.java Thu Jun 26 07:56:29 2014 -0700 @@ -62,6 +62,7 @@ import com.sun.tools.classfile.Synthetic_attribute; import static com.sun.tools.classfile.AccessFlags.*; +import com.sun.tools.javac.util.StringUtils; /* * A writer for writing Attributes as text. @@ -690,14 +691,14 @@ } static String toHex(int i) { - return Integer.toString(i, 16).toUpperCase(); + return StringUtils.toUpperCase(Integer.toString(i, 16)); } static String toHex(int i, int w) { - String s = Integer.toHexString(i).toUpperCase(); + String s = StringUtils.toUpperCase(Integer.toHexString(i)); while (s.length() < w) s = "0" + s; - return s.toUpperCase(); + return StringUtils.toUpperCase(s); } private AnnotationWriter annotationWriter; diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/javap/TypeAnnotationWriter.java --- a/src/share/classes/com/sun/tools/javap/TypeAnnotationWriter.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/javap/TypeAnnotationWriter.java Thu Jun 26 07:56:29 2014 -0700 @@ -37,6 +37,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.sun.tools.javac.util.StringUtils; /** * Annotate instructions with details about type annotations. @@ -115,7 +116,7 @@ print("@"); annotationWriter.write(n.anno, false, true); print(", "); - println(n.kind.toString().toLowerCase()); + println(StringUtils.toLowerCase(n.kind.toString())); } } } diff -r c8b8cabfc922 -r c14269602ffd src/share/classes/com/sun/tools/sjavac/server/CompilerThread.java --- a/src/share/classes/com/sun/tools/sjavac/server/CompilerThread.java Wed Jun 18 12:56:12 2014 -0700 +++ b/src/share/classes/com/sun/tools/sjavac/server/CompilerThread.java Thu Jun 26 07:56:29 2014 -0700 @@ -49,6 +49,7 @@ import com.sun.tools.javac.util.Context; import com.sun.tools.javac.util.Log; import com.sun.tools.javac.util.BaseFileManager; +import com.sun.tools.javac.util.StringUtils; import com.sun.tools.sjavac.comp.Dependencies; import com.sun.tools.sjavac.comp.JavaCompilerWithDeps; import com.sun.tools.sjavac.comp.SmartFileManager; @@ -256,7 +257,7 @@ // Load visible sources Set visibleSources = new HashSet(); boolean fix_drive_letter_case = - System.getProperty("os.name").toLowerCase().startsWith("windows"); + StringUtils.toLowerCase(System.getProperty("os.name")).startsWith("windows"); for (;;) { String l = in.readLine(); if (l == null) diff -r c8b8cabfc922 -r c14269602ffd test/com/sun/javadoc/testRelativeLinks/TestRelativeLinks.java --- a/test/com/sun/javadoc/testRelativeLinks/TestRelativeLinks.java Wed Jun 18 12:56:12 2014 -0700 +++ b/test/com/sun/javadoc/testRelativeLinks/TestRelativeLinks.java Thu Jun 26 07:56:29 2014 -0700 @@ -23,7 +23,7 @@ /* * @test - * @bug 4460354 8014636 + * @bug 4460354 8014636 8043186 * @summary Test to make sure that relative paths are redirected in the * output so that they are not broken. * @author jamieh diff -r c8b8cabfc922 -r c14269602ffd test/com/sun/javadoc/testRelativeLinks/pkg/C.java --- a/test/com/sun/javadoc/testRelativeLinks/pkg/C.java Wed Jun 18 12:56:12 2014 -0700 +++ b/test/com/sun/javadoc/testRelativeLinks/pkg/C.java Thu Jun 26 07:56:29 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,7 +30,7 @@ public class C { /** - * Here is a relative link in a field: + * Here is a relative link in a field:\u0130 * relative field link. */ public C field = null; diff -r c8b8cabfc922 -r c14269602ffd test/com/sun/javadoc/testTopOption/TestTopOption.java --- a/test/com/sun/javadoc/testTopOption/TestTopOption.java Wed Jun 18 12:56:12 2014 -0700 +++ b/test/com/sun/javadoc/testTopOption/TestTopOption.java Thu Jun 26 07:56:29 2014 -0700 @@ -23,7 +23,7 @@ /* * @test - * @bug 6227616 + * @bug 6227616 8043186 * @summary Test the new -top option. * @author jamieh * @library ../lib/ @@ -39,7 +39,7 @@ //Javadoc arguments. private static final String[] ARGS = new String[] { - "-overview", "SRC_DIR + FS + overview.html", "-use", "-top", "TOP TEXT", "-d", BUG_ID, "-sourcepath", + "-overview", SRC_DIR + FS + "overview.html", "-use", "-top", "\u0130{@docroot}TOP TEXT", "-d", BUG_ID, "-sourcepath", SRC_DIR, "pkg" }; diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/NoStringToLower.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/NoStringToLower.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8029800 + * @summary String.toLowerCase()/toUpperCase is generally dangerous, check it is not used in langtools + */ + +import java.io.*; +import java.util.*; +import javax.tools.*; +import com.sun.tools.classfile.*; +import com.sun.tools.classfile.ConstantPool.CONSTANT_Methodref_info; + +public class NoStringToLower { + public static void main(String... args) throws Exception { + NoStringToLower c = new NoStringToLower(); + if (c.run(args)) + return; + + if (is_jtreg()) + throw new Exception(c.errors + " errors occurred"); + else + System.exit(1); + } + + static boolean is_jtreg() { + return (System.getProperty("test.src") != null); + } + + /** + * Main entry point. + */ + boolean run(String... args) throws Exception { + JavaCompiler c = ToolProvider.getSystemJavaCompiler(); + JavaFileManager fm = c.getStandardFileManager(null, null, null); + JavaFileManager.Location javacLoc = findJavacLocation(fm); + String[] pkgs = { + "javax.annotation.processing", + "javax.lang.model", + "javax.tools", + "com.sun.source", + "com.sun.tools.classfile", + "com.sun.tools.doclet", + "com.sun.tools.doclint", + "com.sun.tools.javac", + "com.sun.tools.javadoc", + "com.sun.tools.javah", + "com.sun.tools.javap", + "com.sun.tools.jdeps", + "com.sun.tools.sjavac" + }; + for (String pkg: pkgs) { + for (JavaFileObject fo: fm.list(javacLoc, + pkg, EnumSet.of(JavaFileObject.Kind.CLASS), true)) { + scan(fo); + } + } + + return (errors == 0); + } + + // depending on how the test is run, javac may be on bootclasspath or classpath + JavaFileManager.Location findJavacLocation(JavaFileManager fm) { + JavaFileManager.Location[] locns = + { StandardLocation.PLATFORM_CLASS_PATH, StandardLocation.CLASS_PATH }; + try { + for (JavaFileManager.Location l: locns) { + JavaFileObject fo = fm.getJavaFileForInput(l, + "com.sun.tools.javac.Main", JavaFileObject.Kind.CLASS); + if (fo != null) + return l; + } + } catch (IOException e) { + throw new Error(e); + } + throw new IllegalStateException("Cannot find javac"); + } + + /** + * Verify there are no references to String.toLowerCase() in a class file. + */ + void scan(JavaFileObject fo) throws IOException { + InputStream in = fo.openInputStream(); + try { + ClassFile cf = ClassFile.read(in); + for (ConstantPool.CPInfo cpinfo: cf.constant_pool.entries()) { + if (cpinfo.getTag() == ConstantPool.CONSTANT_Methodref) { + CONSTANT_Methodref_info ref = (CONSTANT_Methodref_info) cpinfo; + String methodDesc = ref.getClassInfo().getName() + "." + ref.getNameAndTypeInfo().getName() + ":" + ref.getNameAndTypeInfo().getType(); + + if ("java/lang/String.toLowerCase:()Ljava/lang/String;".equals(methodDesc)) { + error("found reference to String.toLowerCase() in: " + fo.getName()); + } + if ("java/lang/String.toUpperCase:()Ljava/lang/String;".equals(methodDesc)) { + error("found reference to String.toLowerCase() in: " + fo.getName()); + } + } + } + } catch (ConstantPoolException ignore) { + } finally { + in.close(); + } + } + + /** + * Report an error. + */ + void error(String msg) { + System.err.println("Error: " + msg); + errors++; + } + + int errors; +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/T8038975/AccessTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/T8038975/AccessTest.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8038975 + * @summary Access control in enhanced for + * @compile AccessTest.java + */ + +import a.*; +public class AccessTest { + private static class Impl extends B { + public void method(Inner inner) { + for (A a : inner) + System.out.println(a); + } + } +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/T8038975/a/A.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/T8038975/a/A.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package a; +public class A { } diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/T8038975/a/B.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/T8038975/a/B.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package a; +public class B { + protected abstract class Inner implements Iterable { } +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/annotations/FinalReceiverTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/annotations/FinalReceiverTest.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,14 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8027886 + * @summary Receiver parameters must not be final + * @compile/fail/ref=FinalReceiverTest.out -XDrawDiagnostics FinalReceiverTest.java + */ + +class FinalReceiverTest { + void m() { + class Inner { + Inner(final FinalReceiverTest FinalReceiverTest.this) {} + } + } +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/annotations/FinalReceiverTest.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/annotations/FinalReceiverTest.out Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,2 @@ +FinalReceiverTest.java:11:43: compiler.err.mod.not.allowed.here: final +1 error diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/annotations/LocalInnerReceiverTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/annotations/LocalInnerReceiverTest.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8029042 + * @summary Receiver parameter not supported on local class constructor + * @compile LocalInnerReceiverTest.java + */ + +class LocalInnerReceiverTest { + void m() { + class Inner { + Inner(LocalInnerReceiverTest LocalInnerReceiverTest.this) {} + } + } +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/annotations/typeAnnotations/newlocations/Receivers.java --- a/test/tools/javac/annotations/typeAnnotations/newlocations/Receivers.java Wed Jun 18 12:56:12 2014 -0700 +++ b/test/tools/javac/annotations/typeAnnotations/newlocations/Receivers.java Thu Jun 26 07:56:29 2014 -0700 @@ -54,14 +54,6 @@ void accept(@B("m") WithValue this, T r) throws Exception { } } -class WithFinal { - void plain(final @B("m") WithFinal this) { } - void generic(final @B("m") WithFinal this) { } - void withException(final @B("m") WithFinal this) throws Exception { } - String nonVoid(final @B("m") WithFinal this) { return null; } - void accept(final @B("m") WithFinal this, T r) throws Exception { } -} - class WithBody { Object f; diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/defaultMethods/static/StaticInvoke.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/defaultMethods/static/StaticInvoke.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,15 @@ +/* @test /nodynamiccopyright/ + * @bug 8037385 + * @summary Must not allow static interface method invocation in legacy code + * @compile -source 8 -Xlint:-options StaticInvoke.java + * @compile/fail/ref=StaticInvoke7.out -source 7 -Xlint:-options -XDrawDiagnostics StaticInvoke.java + * @compile/fail/ref=StaticInvoke6.out -source 6 -Xlint:-options -XDrawDiagnostics StaticInvoke.java + */ +import java.util.stream.Stream; + +class StaticInvoke { + void test() { + Stream.empty(); + java.util.stream.Stream.empty(); + } +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/defaultMethods/static/StaticInvoke6.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/defaultMethods/static/StaticInvoke6.out Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,3 @@ +StaticInvoke.java:12:15: compiler.err.static.intf.method.invoke.not.supported.in.source: 1.6 +StaticInvoke.java:13:32: compiler.err.static.intf.method.invoke.not.supported.in.source: 1.6 +2 errors diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/defaultMethods/static/StaticInvoke7.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/defaultMethods/static/StaticInvoke7.out Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,3 @@ +StaticInvoke.java:12:15: compiler.err.static.intf.method.invoke.not.supported.in.source: 1.7 +StaticInvoke.java:13:32: compiler.err.static.intf.method.invoke.not.supported.in.source: 1.7 +2 errors diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/diags/examples/StaticIntfMethodInvokeNotSupported.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/diags/examples/StaticIntfMethodInvokeNotSupported.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// key: compiler.err.static.intf.method.invoke.not.supported.in.source +// options: -source 7 -Xlint:-options +import java.util.stream.Stream; + +class StaticIntfMethodInvokeNotSupported { + void test() { + Stream.empty(); + } +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/flow/LVTHarness.java --- a/test/tools/javac/flow/LVTHarness.java Wed Jun 18 12:56:12 2014 -0700 +++ b/test/tools/javac/flow/LVTHarness.java Thu Jun 26 07:56:29 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,8 +23,8 @@ /* * @test - * @bug 7047734 8027660 - * @summary The LVT is not generated correctly during some try/catch scenarios; + * @bug 7047734 8027660 8037937 + * @summary The LVT is not generated correctly during some try/catch scenarios * javac crash while creating LVT entry for a local variable defined in * an inner block * @library /tools/javac/lib @@ -120,7 +120,7 @@ for (Map.Entry entry : aliveRangeMap.entrySet()) { if (!seenAliveRanges.contains(entry.getKey())) { error("Redundant @AliveRanges annotation on method " + - entry.getKey().elem); + entry.getKey().elem + " with key " + entry.getKey()); } } } @@ -134,7 +134,7 @@ for (Method method : classFile.methods) { for (ElementKey elementKey: aliveRangeMap.keySet()) { String methodDesc = method.getName(constantPool) + - method.descriptor.getParameterTypes(constantPool); + method.descriptor.getParameterTypes(constantPool).replace(" ", ""); if (methodDesc.equals(elementKey.elem.toString())) { checkMethod(constantPool, method, aliveRangeMap.get(elementKey)); seenAliveRanges.add(elementKey); diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/flow/T8042741/A.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/flow/T8042741/A.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +// str must be at absolute position greater than that of lambda +// expression in PositionTest.java +// padding..........................................................padding +// padding..........................................................padding +// padding..........................................................padding +// padding..........................................................padding +// padding..........................................................padding + +public class A { + public final String str; + { + str = ""; + } +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/flow/T8042741/PositionTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/flow/T8042741/PositionTest.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* @test + * @bug 8042741 + * @summary Java 8 compiler throws NullPointerException depending location in source file + * @compile A.java PositionTest.java + */ + +public class PositionTest extends A { + void test(SAM r) throws E { + test(() -> { System.err.println(str); }); + } + interface SAM { + public void run() throws E; + } + void f() { + try { + test(() -> { + test(() -> { + try { + test(() -> { System.err.println(str); }); + System.err.println(str); + } catch (Exception e) {} + System.err.println(str); + }); + System.err.println(str); + }); + } catch (Exception e) { } + } + void g() throws Exception { + test(() -> { + try { + try { + test(() -> { System.err.println(str); }); + } catch (Exception e) {} + System.err.println(str); + } catch (Exception e) {} + System.err.println(str); + }); + } +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/flow/tests/TestCaseIfElse.java --- a/test/tools/javac/flow/tests/TestCaseIfElse.java Wed Jun 18 12:56:12 2014 -0700 +++ b/test/tools/javac/flow/tests/TestCaseIfElse.java Thu Jun 26 07:56:29 2014 -0700 @@ -33,7 +33,7 @@ @AliveRange(varName="o", bytecodeStart=10, bytecodeLength=8) @AliveRange(varName="o", bytecodeStart=21, bytecodeLength=9) - void m2(String[] args) { + void m2() { Object o; int i = 5; if (i != 5) { @@ -45,4 +45,19 @@ } o = "finish"; } + + @AliveRange(varName="o", bytecodeStart=11, bytecodeLength=3) + @AliveRange(varName="o", bytecodeStart=17, bytecodeLength=2) + Object m3(boolean cond1, boolean cond2) { + Object o; + if (cond1) { + if (cond2) { + o = "then"; + } else { + o = "else"; + return null; + } + } + return null; + } } diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/generics/diamond/T8041713/DiamondPlusUnexistingMethodRefCrashTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/diamond/T8041713/DiamondPlusUnexistingMethodRefCrashTest.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,11 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8041713 + * @summary Type inference of non-existent method references crashes the compiler + * @compile/fail/ref=DiamondPlusUnexistingMethodRefCrashTest.out -XDrawDiagnostics DiamondPlusUnexistingMethodRefCrashTest.java + */ + +public class DiamondPlusUnexistingMethodRefCrashTest { + DiamondPlusUnexistingMethodRefCrashTest m = + new DiamondPlusUnexistingMethodRefCrashTest<>(DiamondPlusUnexistingMethodRefCrashTest::doNotExists); +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/generics/diamond/T8041713/DiamondPlusUnexistingMethodRefCrashTest.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/diamond/T8041713/DiamondPlusUnexistingMethodRefCrashTest.out Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,2 @@ +DiamondPlusUnexistingMethodRefCrashTest.java:10:55: compiler.err.invalid.mref: kindname.method, (compiler.misc.cant.resolve.location.args: kindname.method, doNotExists, , , (compiler.misc.location: kindname.class, DiamondPlusUnexistingMethodRefCrashTest, null)) +1 error diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/generics/inference/7086586/T7086586.out --- a/test/tools/javac/generics/inference/7086586/T7086586.out Wed Jun 18 12:56:12 2014 -0700 +++ b/test/tools/javac/generics/inference/7086586/T7086586.out Thu Jun 26 07:56:29 2014 -0700 @@ -1,5 +1,5 @@ -T7086586.java:14:28: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.captureof: 1, ?, java.lang.String) -T7086586.java:15:28: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.captureof: 1, ?, java.lang.Number) -T7086586.java:16:31: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.type.captureof: 1, ?, java.lang.Exception) -T7086586.java:17:13: compiler.err.cant.resolve.location.args: kindname.method, nonExistentMethod, , , (compiler.misc.location: kindname.interface, java.util.List, null) +T7086586.java:14:20: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List, java.util.List, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List, java.util.List)) +T7086586.java:15:20: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List, java.util.List, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List, java.util.List)) +T7086586.java:16:23: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List, java.util.List, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List, java.util.List)) +T7086586.java:17:9: compiler.err.cant.apply.symbol: kindname.method, m, java.util.List, java.util.List, kindname.class, T7086586, (compiler.misc.infer.no.conforming.assignment.exists: T, (compiler.misc.inconvertible.types: java.util.List, java.util.List)) 4 errors diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/generics/inference/7086586/T7086586b.java --- a/test/tools/javac/generics/inference/7086586/T7086586b.java Wed Jun 18 12:56:12 2014 -0700 +++ b/test/tools/javac/generics/inference/7086586/T7086586b.java Thu Jun 26 07:56:29 2014 -0700 @@ -23,10 +23,9 @@ /* * @test - * @bug 7086586 8033718 + * @bug 7086586 * - * @summary Inference producing null type argument; inference ignores capture - * variable as upper bound + * @summary Inference producing null type argument */ import java.util.List; @@ -41,8 +40,8 @@ assertionCount++; } - void m(List dummy) { assertTrue(true); } - void m(Object dummy) { assertTrue(false); } + void m(List dummy) { assertTrue(false); } + void m(Object dummy) { assertTrue(true); } void test(List l) { m(l); diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/generics/inference/8043725/T8043725.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/inference/8043725/T8043725.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8043725 + * @summary javac fails with StackOverflowException + * @compile T8043725.java + */ +class T8043725 { + > T m(T v) { + //this will generate two upper bounds, T and Comparable respectively + //causing infinite recursion in lub (because of JLS 18.3.1). + return m(v); + } +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/generics/inference/NestedWildcards.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/inference/NestedWildcards.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8039214 + * @summary Nested generic methods that work on wildcard-parameterized types + * @compile NestedWildcards.java + */ + +public class NestedWildcards { + + public static void test(Box b) { + foo(bar(b)); + } + private static Box foo(Box ts) { + return null; + } + public static Box bar(Box language) { + return null; + } + + interface Box {} +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/generics/wildcards/7034495/T7034495.out --- a/test/tools/javac/generics/wildcards/7034495/T7034495.out Wed Jun 18 12:56:12 2014 -0700 +++ b/test/tools/javac/generics/wildcards/7034495/T7034495.out Thu Jun 26 07:56:29 2014 -0700 @@ -1,2 +1,2 @@ -T7034495.java:40:17: compiler.err.types.incompatible.diff.ret: T7034495.B, T7034495.A, foo() +T7034495.java:40:17: compiler.err.types.incompatible.diff.ret: T7034495.B, T7034495.A, foo() 1 error diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/generics/wildcards/T8015101.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/wildcards/T8015101.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8015101 + * @summary Mishandling of wildcards in intersection member method check + * @compile T8015101.java + */ +class T8015101 { + + public static class Bug & Runnable> { + } + + interface Parent { + public C get(); + } + + interface Child extends Parent { + @Override + public S get(); + } + + } diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/generics/wildcards/T8034147.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/generics/wildcards/T8034147.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8034147 + * @summary javac crashes with a NullPointerException during bounds checking + * @compile T8034147.java + */ + +class T8034147 { + static class One> {} + static class Two> implements Three {} + interface Three {} +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/lambda/T8031967.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/T8031967.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8031967 + * @summary Ensure javac can handle very deeply nested chain of method invocations occurring as + * a parameter to other method invocations. + * @run main T8031967 + */ + +import java.io.IOException; +import java.net.URI; +import java.util.Arrays; +import java.util.List; + +import javax.tools.DiagnosticListener; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.ToolProvider; + +import com.sun.source.util.JavacTask; + +public class T8031967 { + + public static void main(String... args) throws IOException { + new T8031967().run(); + } + + final int depth = 50; + + private void run() throws IOException { + runTestCase(true); + runTestCase(false); + } + + private void runTestCase(boolean withErrors) throws IOException { + StringBuilder code = new StringBuilder(); + + code.append("public class Test {\n" + + " private void test() {\n" + + " GroupLayout l = new GroupLayout();\n" + + " l.setHorizontalGroup(\n"); + + gen(code, depth); + code.append(" );\n" + + " }\n"); + if (!withErrors) { + code.append(" class GroupLayout {\n" + + " ParallelGroup createParallelGroup() {return null;}\n" + + " ParallelGroup createParallelGroup(int i) {return null;}\n" + + " ParallelGroup createParallelGroup(int i, int j) {return null;}\n" + + " void setHorizontalGroup(Group g) { }\n" + + " }\n" + + " \n" + + " class Group {\n" + + " Group addGroup(Group g) { return this; }\n" + + " Group addGroup(int i, Group g) { return this; }\n" + + " Group addGap(int i) { return this; }\n" + + " Group addGap(long l) { return this; }\n" + + " Group addGap(int i, int j) { return this; }\n" + + " Group addComponent(Object c) { return this; }\n" + + " Group addComponent(int i, Object c) { return this; }\n" + + " }\n" + + " class ParallelGroup extends Group {\n" + + " Group addGroup(Group g) { return this; }\n" + + " Group addGroup(int i, Group g) { return this; }\n" + + " Group addGap(int i) { return this; }\n" + + " Group addGap(int i, int j) { return this; }\n" + + " Group addComponent(Object c) { return this; }\n" + + " Group addComponent(int i, Object c) { return this; }\n" + + " }\n"); + } + + code.append("}\n"); + + JavaSource source = new JavaSource(code.toString()); + List sourceList = Arrays.asList(source); + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + DiagnosticListener noErrors = (diagnostic) -> { + throw new IllegalStateException("Should not produce errors: " + diagnostic); + }; + JavacTask task = (JavacTask) compiler.getTask(null, null, withErrors ? null : noErrors, + null, null, sourceList); + + task.analyze(); + } + + private void gen(StringBuilder code, int depth) { + code.append("l.createParallelGroup()\n"); + if (depth > 0) { + code.append(".addGroup(\n"); + gen(code, depth - 1); + code.append(")"); + } + + code.append(".addGap(1)\n" + + ".addComponent(new Object())\n" + + ".addGap(1)\n" + + ".addComponent(new Object())"); + } + + class JavaSource extends SimpleJavaFileObject { + + final String code; + public JavaSource(String code) { + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); + this.code = code; + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return code; + } + } +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/lambda/T8038182/CrashFunctionDescriptorExceptionTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/T8038182/CrashFunctionDescriptorExceptionTest.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,24 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8038182 + * @summary javac crash with FunctionDescriptorLookupError for invalid functional interface + * @compile/fail/ref=CrashFunctionDescriptorExceptionTest.out -XDrawDiagnostics CrashFunctionDescriptorExceptionTest.java + */ + +class CrashFunctionDescriptorExceptionTest { + + @SuppressWarnings("unchecked") + void m () { + bar((B b) -> {}); + } + + > void bar(I i) {} + + class A {} + + class B extends A {} + + interface I> { + void foo(E e); + } +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/lambda/T8038182/CrashFunctionDescriptorExceptionTest.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/T8038182/CrashFunctionDescriptorExceptionTest.out Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,2 @@ +CrashFunctionDescriptorExceptionTest.java:12:13: compiler.err.prob.found.req: (compiler.misc.no.suitable.functional.intf.inst: CrashFunctionDescriptorExceptionTest.I) +1 error diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/lambda/T8042759/ImplicitLambdaConsideredForApplicabilityTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/T8042759/ImplicitLambdaConsideredForApplicabilityTest.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,33 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8042759 + * @summary Lambda returning implicitly-typed lambdas considered pertinent to applicability + * @compile/fail/ref=ImplicitLambdaConsideredForApplicabilityTest.out -XDrawDiagnostics ImplicitLambdaConsideredForApplicabilityTest.java + */ + +abstract class ImplicitLambdaConsideredForApplicabilityTest { + interface A { + B m(int a, int b); + } + + interface C { + String m(int a, int b); + } + + interface B { + int m(int c); + } + + abstract void foo(A a); + + abstract void foo(C c); + + void bar() { + foo((int a, int b) -> { + if(a < b) + return c -> 0; + else + return c -> 0; + }); + } +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/lambda/T8042759/ImplicitLambdaConsideredForApplicabilityTest.out --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/lambda/T8042759/ImplicitLambdaConsideredForApplicabilityTest.out Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,2 @@ +ImplicitLambdaConsideredForApplicabilityTest.java:26:9: compiler.err.ref.ambiguous: foo, kindname.method, foo(ImplicitLambdaConsideredForApplicabilityTest.A), ImplicitLambdaConsideredForApplicabilityTest, kindname.method, foo(ImplicitLambdaConsideredForApplicabilityTest.C), ImplicitLambdaConsideredForApplicabilityTest +1 error diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/processing/model/element/TestTypeParameterAnnotations.java --- a/test/tools/javac/processing/model/element/TestTypeParameterAnnotations.java Wed Jun 18 12:56:12 2014 -0700 +++ b/test/tools/javac/processing/model/element/TestTypeParameterAnnotations.java Thu Jun 26 07:56:29 2014 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /* * @test - * @bug 8011027 + * @bug 8011027 8046916 * @library /tools/javac/lib * @build JavacTestingAbstractProcessor TestTypeParameterAnnotations * @compile -processor TestTypeParameterAnnotations -proc:only TestTypeParameterAnnotations.java @@ -33,10 +33,16 @@ import java.lang.annotation.*; import javax.annotation.processing.*; import javax.lang.model.element.*; -import javax.lang.model.util.*; import javax.tools.*; -public class TestTypeParameterAnnotations<@Foo @Bar @Baz T> extends JavacTestingAbstractProcessor { +@ExpectedTypeParameterAnnotations(typeParameterName="T1", + annotations={"Foo1", "Bar1", "Baz1"}) +@ExpectedTypeParameterAnnotations(typeParameterName="T2", annotations={}) +@ExpectedTypeParameterAnnotations(typeParameterName="T3", + annotations={"Foo2", "Bar2", "Baz2"}) +@ExpectedTypeParameterAnnotations(typeParameterName="T4", annotations={}) +public class TestTypeParameterAnnotations<@Foo1 @Bar1 @Baz1 T1, T2, @Foo2 @Bar2 @Baz2 T3, T4> extends + JavacTestingAbstractProcessor { int round = 0; public boolean process(Set annotations, RoundEnvironment roundEnv) { @@ -74,82 +80,69 @@ int check(Element e, List typarams) { if (typarams.isEmpty()) return 0; - if (typarams.size() != 1) - return 0; - for (TypeParameterElement tpe: typarams) { - boolean b1 = checkAnnotationMirrors(tpe, tpe.getAnnotationMirrors()); - boolean b2 = checkAnnotationMirrors(tpe, elements.getAllAnnotationMirrors(tpe)); - boolean b3 = checkGetAnnotation(tpe); - boolean b4 = checkGetAnnotations(tpe); - return b1 && b2 && b3 && b4 ? 1 : 0; + for (TypeParameterElement tpe : typarams) { + ExpectedTypeParameterAnnotations expected = null; + for (ExpectedTypeParameterAnnotations a : e.getAnnotationsByType(ExpectedTypeParameterAnnotations.class)) { + if (tpe.getSimpleName().contentEquals(a.typeParameterName())) { + expected = a; + break; + } + } + if (expected == null) { + throw new IllegalStateException("Does not have expected values annotation."); + } + checkAnnotationMirrors(tpe, tpe.getAnnotationMirrors(), expected); + checkAnnotationMirrors(tpe, elements.getAllAnnotationMirrors(tpe), expected); + checkGetAnnotation(tpe, expected); + checkGetAnnotations(tpe, expected); } - return 0; + + return typarams.size(); } - boolean checkAnnotationMirrors(TypeParameterElement tpe, List l) { - if (l.size() != 3) { - error("To few annotations, got " + l.size() + - ", should be 3", tpe); - return false; + void checkAnnotationMirrors(TypeParameterElement tpe, List l, ExpectedTypeParameterAnnotations expected) { + String[] expectedAnnotations = expected.annotations(); + + if (l.size() != expectedAnnotations.length) { + error("Incorrect number of annotations, got " + l.size() + + ", should be " + expectedAnnotations.length, tpe); + return ; } - AnnotationMirror m = l.get(0); - if (!m.getAnnotationType().asElement().equals(elements.getTypeElement("Foo"))) { - error("Wrong type of annotation, was expecting @Foo", m.getAnnotationType().asElement()); - return false; + for (int i = 0; i < expectedAnnotations.length; i++) { + AnnotationMirror m = l.get(i); + if (!m.getAnnotationType().asElement().equals(elements.getTypeElement(expectedAnnotations[i]))) { + error("Wrong type of annotation, was expecting @Foo", m.getAnnotationType().asElement()); + return ; + } } - m = l.get(1); - if (!m.getAnnotationType().asElement().equals(elements.getTypeElement("Bar"))) { - error("Wrong type of annotation, was expecting @Bar", m.getAnnotationType().asElement()); - return false; - } - m = l.get(2); - if (!m.getAnnotationType().asElement().equals(elements.getTypeElement("Baz"))) { - error("Wrong type of annotation, was expecting @Baz", m.getAnnotationType().asElement()); - return false; - } - return true; } - boolean checkGetAnnotation(TypeParameterElement tpe) { - Foo f = tpe.getAnnotation(Foo.class); - if (f == null) - error("Expecting @Foo to be present in getAnnotation()", tpe); + void checkGetAnnotation(TypeParameterElement tpe, ExpectedTypeParameterAnnotations expected) { + List expectedAnnotations = Arrays.asList(expected.annotations()); - Bar b = tpe.getAnnotation(Bar.class); - if (b == null) - error("Expecting @Bar to be present in getAnnotation()", tpe); + for (Class c : ALL_ANNOTATIONS) { + Object a = tpe.getAnnotation(c); - Baz z = tpe.getAnnotation(Baz.class); - if (z == null) - error("Expecting @Baz to be present in getAnnotation()", tpe); - - return f != null && - b != null && - z != null; + if (a != null ^ expectedAnnotations.indexOf(c.getName()) != (-1)) { + error("Unexpected behavior for " + c.getName(), tpe); + return ; + } + } } - boolean checkGetAnnotations(TypeParameterElement tpe) { - Foo[] f = tpe.getAnnotationsByType(Foo.class); - if (f.length != 1) { - error("Expecting 1 @Foo to be present in getAnnotationsByType()", tpe); - return false; + void checkGetAnnotations(TypeParameterElement tpe, ExpectedTypeParameterAnnotations expected) { + List expectedAnnotations = Arrays.asList(expected.annotations()); + + for (Class c : ALL_ANNOTATIONS) { + Object[] a = tpe.getAnnotationsByType(c); + + if (a.length > 0 ^ expectedAnnotations.indexOf(c.getName()) != (-1)) { + error("Unexpected behavior for " + c.getName(), tpe); + return ; + } } - - Bar[] b = tpe.getAnnotationsByType(Bar.class); - if (b.length != 1) { - error("Expecting 1 @Bar to be present in getAnnotationsByType()", tpe); - return false; - } - - Baz[] z = tpe.getAnnotationsByType(Baz.class); - if (z.length != 1) { - error("Expecting 1 @Baz to be present in getAnnotationsByType()", tpe); - return false; - } - - return true; } void note(String msg) { @@ -168,23 +161,71 @@ messager.printMessage(Diagnostic.Kind.ERROR, msg); } + Class[] ALL_ANNOTATIONS = new Class[] { + Foo1.class, Bar1.class, Baz1.class, + Foo2.class, Bar2.class, Baz2.class, + }; + // additional generic elements to test - <@Foo @Bar @Baz X> X m(X x) { return x; } + @ExpectedTypeParameterAnnotations(typeParameterName="W", + annotations={"Foo1", "Bar1", "Baz1"}) + @ExpectedTypeParameterAnnotations(typeParameterName="X", annotations={}) + @ExpectedTypeParameterAnnotations(typeParameterName="Y", + annotations={"Foo2", "Bar2", "Baz2"}) + @ExpectedTypeParameterAnnotations(typeParameterName="Z", annotations={}) + <@Foo1 @Bar1 @Baz1 W, X, @Foo2 @Bar2 @Baz2 Y, Z> X m(X x) { return x; } - interface Intf<@Foo @Bar @Baz X> { X m() ; } + @ExpectedTypeParameterAnnotations(typeParameterName="W", + annotations={"Foo1", "Bar1", "Baz1"}) + @ExpectedTypeParameterAnnotations(typeParameterName="X", annotations={}) + @ExpectedTypeParameterAnnotations(typeParameterName="Y", + annotations={"Foo2", "Bar2", "Baz2"}) + @ExpectedTypeParameterAnnotations(typeParameterName="Z", annotations={}) + interface Intf<@Foo1 @Bar1 @Baz1 W, X, @Foo2 @Bar2 @Baz2 Y, Z> { X m() ; } - class Class<@Foo @Bar @Baz X> { - <@Foo @Bar @Baz Y> Class() { } + @ExpectedTypeParameterAnnotations(typeParameterName="W", + annotations={"Foo1", "Bar1", "Baz1"}) + @ExpectedTypeParameterAnnotations(typeParameterName="X", annotations={}) + @ExpectedTypeParameterAnnotations(typeParameterName="Y", + annotations={"Foo2", "Bar2", "Baz2"}) + @ExpectedTypeParameterAnnotations(typeParameterName="Z", annotations={}) + class Clazz<@Foo1 @Bar1 @Baz1 W, X, @Foo2 @Bar2 @Baz2 Y, Z> { + @ExpectedTypeParameterAnnotations(typeParameterName="W", + annotations={"Foo1", "Bar1", "Baz1"}) + @ExpectedTypeParameterAnnotations(typeParameterName="X", annotations={}) + @ExpectedTypeParameterAnnotations(typeParameterName="Y", + annotations={"Foo2", "Bar2", "Baz2"}) + @ExpectedTypeParameterAnnotations(typeParameterName="Z", annotations={}) + <@Foo1 @Bar1 @Baz1 W, X, @Foo2 @Bar2 @Baz2 Y, Z> Clazz() { } } - final int expect = 5; // top level class, plus preceding examples + final int expect = 5 * 4; // top level class, plus preceding examples, 4 type variables each } @Target(ElementType.TYPE_PARAMETER) -@interface Foo {} +@interface Foo1 {} @Target(ElementType.TYPE_PARAMETER) -@interface Bar {} +@interface Bar1 {} @Target(ElementType.TYPE_PARAMETER) -@interface Baz {} +@interface Baz1 {} + +@Target(ElementType.TYPE_PARAMETER) +@interface Foo2 {} + +@Target(ElementType.TYPE_PARAMETER) +@interface Bar2 {} + +@Target(ElementType.TYPE_PARAMETER) +@interface Baz2 {} + +@Repeatable(ExpectedTypeParameterAnnotationsCollection.class) +@interface ExpectedTypeParameterAnnotations { + public String typeParameterName(); + public String[] annotations(); +} + +@interface ExpectedTypeParameterAnnotationsCollection { + public ExpectedTypeParameterAnnotations[] value(); +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/types/BadSigTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/types/BadSigTest.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8037934 + * @summary Javac generates invalid signatures for local types + * @run main BadSigTest + */ + +public class BadSigTest { + void m(){ + class Local1{} + class Local2 extends Local1{} + Local2.class.getTypeParameters(); + } + public static void main(String[] args) { + new BadSigTest().m(); + } +} diff -r c8b8cabfc922 -r c14269602ffd test/tools/javac/util/StringUtilsTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/tools/javac/util/StringUtilsTest.java Thu Jun 26 07:56:29 2014 -0700 @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * @test + * @bug 8029800 8043186 + * @summary Unit test StringUtils + * @run main StringUtilsTest + */ + +import java.util.Locale; +import java.util.Objects; +import com.sun.tools.javac.util.StringUtils; + +public class StringUtilsTest { + public static void main(String... args) throws Exception { + new StringUtilsTest().run(); + } + + void run() throws Exception { + Locale.setDefault(new Locale("tr", "TR")); + + //verify the properties of the default locale: + assertEquals("\u0131", "I".toLowerCase()); + assertEquals("\u0130", "i".toUpperCase()); + + //verify the StringUtils.toLowerCase/toUpperCase do what they should: + assertEquals("i", StringUtils.toLowerCase("I")); + assertEquals("I", StringUtils.toUpperCase("i")); + + //verify StringUtils.caseInsensitiveIndexOf works: + assertEquals(2, StringUtils.indexOfIgnoreCase(" lookFor", "lookfor")); + assertEquals(11, StringUtils.indexOfIgnoreCase(" lookFor LOOKfor", "lookfor", 11)); + assertEquals(2, StringUtils.indexOfIgnoreCase("\u0130\u0130lookFor", "lookfor")); + } + + void assertEquals(String expected, String actual) { + if (!Objects.equals(expected, actual)) { + throw new IllegalStateException("expected=" + expected + "; actual=" + actual); + } + } + + void assertEquals(int expected, int actual) { + if (expected != actual) { + throw new IllegalStateException("expected=" + expected + "; actual=" + actual); + } + } +}