diff options
author | Alexey Ushakov <alexey.ushakov@jetbrains.com> | 2016-02-15 15:22:22 +0300 |
---|---|---|
committer | Alexey Ushakov <alexey.ushakov@jetbrains.com> | 2016-02-15 15:22:22 +0300 |
commit | 1cf8e687c4c5dc4f1ea30170c5b00fb47d46cf51 (patch) | |
tree | 560858df8840cb6b9150a1aa180d4cc698a25682 | |
parent | 4d41f4353881d713b5bfc4ab8213bb66cb5a7c2c (diff) | |
parent | ee1f343487d24f15c827831f5d95df301abbe9dd (diff) | |
download | jdk8u_langtools-jetbrains-master-mirror-osx.tar.gz |
Merged changes from defaultjetbrains-master-mirror-osx
--HG--
branch : 8u40-verified-fixes
115 files changed, 3298 insertions, 1406 deletions
@@ -334,6 +334,8 @@ a340d68b020585cad7aa6e38d1aafb19ad0e4e07 jdk8u25-b14 53ca196be1ae098466976c017b166d4ce180c36f jdk8u25-b17 a4f0c6dd8f97d4dd89baf09463c748abea9b3ed7 jdk8u25-b18 c4de614efd7affc001715aa5a7040620924ac44a jdk8u25-b31 +a2a922ccc00f29af625cbecde8e77643c60f147c jdk8u25-b32 +b72a49d88cc3f5394b69b861455552476341558d jdk8u25-b33 c4bd223559aad3d152968a09d56241175d82c561 jdk8u31-b00 6b5e2c190f3023162a33b798e57a0d78e027c843 jdk8u31-b01 8b4ea00b438d7f99ecd6a8345cb018d8a0379620 jdk8u31-b02 @@ -348,6 +350,10 @@ fe1980c653be1fa9fb50353c5a5305855dcd7bd4 jdk8u31-b06 e72be544fa9e247fba3c6bb61e291d80e127a461 jdk8u31-b11 c956b12b30ee21a4fc5df1871fa3b01e84310ebe jdk8u31-b12 7a34ec7bb1c831e82ac88da578a028572b676260 jdk8u31-b13 +b813a76f10911ac8db2c775e52b29f36ab0005f4 jdk8u31-b31 +8dc0c7e42d90c9f323582b742a7f228bad57b124 jdk8u31-b32 +f75e26a5c3acc1ca9f5035dbfc4a40710d354dff jdk8u31-b33 +cbbf2cd7ed1c24856cf8fa570e70cfc793c8bd7b jdk8u31-b34 d231957fe3103e790465fcf058fb8cb33bbc4c4e jdk8u40-b00 bf89a471779d13a9407f7d1c86f7716258bc4aa6 jdk8u40-b01 0b6cc4ea670f5d17b56c088f202869bdbb80a5ce jdk8u40-b02 @@ -376,3 +382,154 @@ c5d4ffa220f3824c2ea5d39dc99d41a9df9e5ae5 jdk8u40-b24 991141080b2078e67179ff307a5051e59431762c jdk8u40-b25 2904142783dd0a9e12195a84c7dcdb3d8278b1b1 jdk8u40-b26 83eca922346e27ec42645e9630c04fbaec5eaf0f jdk8u40-b27 +d727ca30ce3c1b97ed9acd7380f8e4cf41813ffa jdk8u40-b31 +cc9fc1abb5aeffe2b6123c392a5c602a0ba75368 jdk8u40-b32 +dbae37f50c43453f7d6f22d96adc8b5b6cd1e90d jdk8u45-b00 +244e6dc772877dfae6286530f58e11a210a48a3c jdk8u45-b01 +401ec76887623a29d3f868f9f9b18b42838d2e92 jdk8u45-b02 +79d31ae9990e28b99dd64beda6dd247993138431 jdk8u45-b03 +47292f3c0da7dd197a28765004b588bc3141d189 jdk8u45-b04 +77d7dd7f35d63f9fe60ed0b7ef32e4e9a8b46c0b jdk8u45-b05 +22cc48973eae62c63e68c4c4e3f22ff2d89012a8 jdk8u45-b06 +460238ab73ce27112b3d0d7236366960f9898259 jdk8u45-b07 +6dd7fd9f027bf037517feae2a571848aa8fbc20f jdk8u45-b08 +db16aa5c73c99d0050246660ebebb6166002ff57 jdk8u45-b09 +572895f19937b7aadc8c27c5e83887bf40f5bcff jdk8u45-b10 +0547ef2be3b303923b30ce78e1ab832725483f4e jdk8u45-b11 +4f89bbda7b4532b9f6eeee8c41b7a3b38570ae93 jdk8u45-b12 +5ce022bca792453a7efedaed419a9d763d7a9fc3 jdk8u45-b13 +847af465a5425e2caa1f1d7a09efec3b3f31b323 jdk8u45-b14 +ebe1e9d17713e45d157b48b9a31c5c2d077c7970 jdk8u45-b15 +10fae8059bb210df1624b827a3895ccc455e3c64 jdk8u45-b31 +e0b8d79bef0c01d77453579b1d36e926892c774b jdk8u45-b32 +215ac00f188ef920a2f0f25257c96550f410bc5e jdk8u45-b33 +67733b5f2dee681e9590f1224df97132a37c2314 jdk8u45-b34 +a7b242cd24d1dae36d79dec6746896de4414823b jdk8u45-b35 +06aa26ac40d82df216f28ead7b2ae6d59b66f461 jdk8u45-b36 +e233228c112c1e796747d303324284c86b3ef8e2 jdk8u45-b37 +ac1c3ae884633c2ec3881816977023fc44919c66 jdk8u51-b00 +565167bf31eab083c306dfe11c947e59f4f4ee72 jdk8u51-b01 +2078bad2444c509a63a539f3bbe1db0f36513c9e jdk8u51-b02 +30124dd95dc07edf3340c98d5af2a5a254b233b5 jdk8u51-b03 +9cb46d0c0d5932f1e52f1f06f015a9a5c1190bc2 jdk8u51-b04 +412ac274e12075e1a774f9b971ce019bcc2e1435 jdk8u51-b05 +7c65f509ca37c7b45c9762841cc280f572686c70 jdk8u51-b06 +b40a953cbc4dbcd87e56b9f9e006ab048d0deaa1 jdk8u51-b07 +858a7fc598d0baa0949a525fadfe912efd15b459 jdk8u51-b08 +90def0a14f4ad8c99fcda34f2745b6158823e21c jdk8u51-b09 +417f734de62d74c69e3a8465340bfb3aca60151a jdk8u51-b10 +8ac1243890d4f427a32320b81ae1be38f81f0c62 jdk8u51-b11 +f65c2fc549b5e9184da67e3a4f81260c27a88010 jdk8u51-b12 +3836d67a94a92befedd97064358270c6f0760e5c jdk8u51-b13 +f3a44c7deac2b23a53f0fd35b22a5d9181291616 jdk8u51-b14 +f77e8d012e8d6ee3432515ad68dd4f630dd08d56 jdk8u51-b15 +e27a094cb423a3bf32906969e9e454e061ce94d4 jdk8u51-b16 +57ea4856a08f0bc87f2fe56d57b3cf1497c0cb51 jdk8u51-b31 +153378991303acf7906684380a025347a95bc95e jdk8u51-b32 +e7810a2613c9b9b407125cbd17add7bfeebfdb03 jdk8u51-b33 +0c514d1fd006fc79d35b670de10c370c8d559db7 jdk8u60-b00 +0ba07c272e33c93377a5d7ed98b9de873cc91980 jdk8u60-b01 +387cf62ce7895dd5e067aaa51faa93d5c078583e jdk8u60-b02 +e59ced856c92d542b6ea11a3a76e2f0a1ffae17a jdk8u60-b03 +27bb4c63fd70483bb63a6d830c595e691bf28a34 jdk8u60-b04 +fc98314cff57ce33bfe3093441804ee0a3446622 jdk8u60-b05 +44d168f9ad16609062e359ee70c6699ec4525b45 jdk8u60-b06 +39b47ffeb7780407561c0b189c3b3ab497868518 jdk8u60-b07 +e5b93c508212e0db2301cc25f5ada882367d1d9b jdk8u60-b08 +76adee5ad278e33675fdd236179fa83f20de5cc3 jdk8u60-b09 +ba758e1ffa6960266e5c619b7771ca779ee5d148 jdk8u60-b10 +ac218cf56d8ba365ba341132933629c10dbfcc06 jdk8u60-b11 +84eb517777335f079ba16c1fa49e7c36f0c444aa jdk8u60-b12 +9df2a728410bb8603d0cc39bdebed8fa93430cb2 jdk8u60-b13 +a136ed2f3041e48f340d891208cc8ac0171a7816 jdk8u60-b14 +248db113703a917fd38b637d384848a5e458ebcc jdk8u60-b15 +ecb7e46b820f293bb644f92bc1af3ede53bceced jdk8u60-b16 +87dcdc1fd75bf827c8a4596b183de7ea73cb75e1 jdk8u60-b17 +e7e42c79861ea1ab7495de5f238c01f98035a8a8 jdk8u60-b18 +0366d7f1faa12ed35694571c151524e0847f05ff jdk8u60-b19 +976523f1d5626bdb6dd47883e2734614b64a5e61 jdk8u60-b20 +97328f3e2aa2c713931edf471270a1208980b963 jdk8u60-b21 +d1febf79ce5ea41fb4b818ffd3589cf923e6de5f jdk8u60-b22 +7f88b5dc78cebc2c5ebb716938fd9a7632b052b2 jdk8u60-b23 +2af11e10da7dc24610551bbeed02c4ca3f4ae654 jdk8u60-b24 +8d152d1e45944616309886e730ffcbfb5c078d22 jdk8u60-b25 +3876ab6f471b85a02bb2cdaca00652f169f9e27a jdk8u60-b26 +e8e293d0db49b717f8cfc2c8fa5926bcec0f2941 jdk8u60-b27 +11907015714ab0bb44e27f0bb32365dc1669ac51 jdk8u60-b31 +f928484c17d6d27cc3b866ea6fe878058b518372 jdk8u60-b32 +779397f90251ea813cb44621dc27f780e5c20449 jdk8u52-b06 +e0ce6be9142ed1e2f0ce3ee13090ec01c6c44721 jdk8u52-b07 +779397f90251ea813cb44621dc27f780e5c20449 jdk8u65-b00 +c4dcc4e75218f222b80b21d2044baeb98f1f7143 jdk8u65-b01 +57a11f869f0a469798d571197403947bdd8f0525 jdk8u65-b02 +0e03089b5bb37450c7bcab8fc9cb0912e24fe681 jdk8u65-b03 +b90367f392f5d7af47c26bae5493adc73a865c70 jdk8u65-b04 +b2e8d2c5636f5f98a10b9e800ea10e0fe4c265c3 jdk8u65-b05 +ae5e31450299f6c265df24ed155acd650fb3bffd jdk8u65-b06 +c80e74eb5aaa6abe74c7cf110a41290317bc4efb jdk8u65-b07 +5e00d983801dd8764c7cdccdede6d026f6033b66 jdk8u65-b08 +9a8c4add20b277917466d48398071e0965f3deee jdk8u65-b09 +f3f51e2bce4b243ab7abb9e83dfb20cc706939e8 jdk8u65-b10 +f3f51e2bce4b243ab7abb9e83dfb20cc706939e8 jdk8u65-b10 +0000000000000000000000000000000000000000 jdk8u65-b10 +0000000000000000000000000000000000000000 jdk8u65-b10 +f72616a2c088fb2918d730b4eeea6c86f84d1f04 jdk8u65-b10 +2628c6cd89512e40a97baf79465c68147ed750d4 jdk8u65-b11 +54e958a3719e6af61f16e1fa3bcca9422738e4dd jdk8u65-b12 +153d0309e6986149e763597edd20250485160734 jdk8u65-b13 +ec4fa681ae411edc666a60ca5470a56c5cf0fa81 jdk8u65-b14 +02e92f7edc325dc1d17141477ee851a1cc7e71d8 jdk8u65-b15 +20703c32d5ae5d53ecb40bcef79ae933558411aa jdk8u65-b16 +d038f63e516730c240b5ee0559fc7b09c22393c4 jdk8u65-b17 +d1febf79ce5ea41fb4b818ffd3589cf923e6de5f jdk8u66-b00 +4c13b9cd06222be73b9c44607ae929b4818aed17 jdk8u66-b01 +ec4e102b4bd02b08336e172047e70971a3ed7489 jdk8u66-b02 +a765210439a2544a4570deda6d9400363cd18b48 jdk8u66-b07 +8d4dc964a44ba0d55dccbcf7ac840f70bc523e20 jdk8u66-b08 +93a0c0eb33d47c5a6f096dcf531ee062480e1cd7 jdk8u66-b09 +09600814af4e1dbf9de8e5bcec0316ec0bb92c20 jdk8u66-b10 +b71e6a08899271f3f6c02af2abc3c72b2eaad797 jdk8u66-b11 +7ea15c71137ffc344fa4ef3eefb69da94713e841 jdk8u66-b12 +55656a3a71be6674c215b670354ee6e2a7f1c839 jdk8u66-b13 +70489ab07527a3ef65e2a30f23b164220466775a jdk8u66-b14 +8063e4ac4caabe1756f8393859ab56da3bb29122 jdk8u66-b15 +01e7f91d993b341986f574d0eb3fbfe3d7cae68e jdk8u66-b16 +ad3f528335b4c609eee7227d150c9a0a39b1dd73 jdk8u66-b17 +ee701de614ad0c5f4bf3a553942909a54084c458 jdk8u66-b18 +f55af75598d85f45f779f3e632152a067fb7efbc jdk8u66-b31 +aaad025819b721f7f291048a07cd1c144319b68d jdk8u71-b00 +fb2756fb330047dbbff0fa89b79e1d8d96146868 jdk8u71-b01 +21306b94f23ef63cc3ac48a509d491187dadb0f6 jdk8u71-b02 +43002f1aebfdaa64ad497f86c5f9a2f9b450b464 jdk8u71-b03 +531efb9ef9808eef700a0b4d9c3996090469ad6c jdk8u71-b04 +89deefc7b6bac551bb16fbb8740775cfd5f73998 jdk8u71-b05 +bc15decea6ad7b8b34b217af102f175a9a0d52c3 jdk8u71-b06 +6462f92dadf2e5b7ac6fc35f7b38a5018108fd4d jdk8u71-b07 +ef48693aa6ab6356a46830f3f127d41394b79224 jdk8u71-b08 +8089203f9ae281143388d3d6bbe448ef94c32433 jdk8u71-b09 +f01e8d723f60fb5cae3e64db771590d2219fa1b9 jdk8u71-b10 +69f2b3ae357a2a85c3f6e9c74e13e42eb6acd899 jdk8u71-b11 +12889f37d0573ddbcf0738843f013ac89b3f0cb3 jdk8u71-b12 +ceba7d950f1d4055628dbddbcb5c39b9888b7333 jdk8u71-b13 +87d69c4a77b4ca9bc3a8304fc6591ca10c80bfe5 jdk8u71-b14 +f693ae53d58c81d6f319b402dfd3ed8bf14ed7bc jdk8u71-b15 +1c93d260bf996e56d1e1f6d187aceadaa9a38d0c jdk8u72-b00 +aec633bcb3af5382013c6c25b435564aba5bc3d4 jdk8u72-b01 +dfb368f2498e5bfaac7cc7730b5e822999736cd7 jdk8u72-b02 +975709317923c28f0dfcf99d8456048f920d087e jdk8u72-b03 +106fb99e28d20623748c2c3a2120be37fcfac78f jdk8u72-b04 +5bb4ad0363a74265a931b24d0bb0f51b23f09060 jdk8u72-b05 +2e722fd7496556350510c5d3fc02c77377fd8bff jdk8u72-b06 +34d01f3892f5d7408926d5b29da0bcfdc8238f5b jdk8u72-b07 +98179963e9332fd10e8c369e5e50dfe5df280a18 jdk8u72-b08 +a9ec52fb3bc762ccca9baeda84333fdf8465f707 jdk8u72-b09 +96744607e4b9fb85c985e70ba07a803e8792c576 jdk8u72-b10 +6840ff8b3db5e47576893fb0fa940202a50f2e12 jdk8u72-b11 +5218bea65fe64b31cf201f3f6dd0310b74acec1e jdk8u72-b12 +5b67278c6616dca433488697eb6f2f81fcbbf22d jdk8u72-b13 +0ee6d8ae247d449950c18623513ccae4349e70d6 jdk8u72-b14 +48d0c20256a37ad20d075091285ea23788186f9a jdk8u72-b15 +10ffafaf53404de7fd23784aa3ff6016d107b9c8 jdk8u76-b00 +0caab0d65a04d8cce71976a6bdc1ca0841bcbcf0 jdk8u76-b01 +78f0aa6199150e10f387989b9bd5997f72cdc4e1 jdk8u76-b02 +8969d6096fe123922bb3ac0c8f6f7b18c1c7668e jdk8u76-b03 diff --git a/THIRD_PARTY_README b/THIRD_PARTY_README index c34ce6b3..2b20da2c 100644 --- a/THIRD_PARTY_README +++ b/THIRD_PARTY_README @@ -1140,37 +1140,6 @@ included with JRE 8, JDK 8, and OpenJDK 8. -------------------------------------------------------------------------------- -%% This notice is provided with respect to JSON, which may be included -with JRE 8 & JDK 8. - ---- begin of LICENSE --- - -Copyright (c) 2002 JSON.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - ---- end of LICENSE --- - -------------------------------------------------------------------------------- - %% This notice is provided with respect to Kerberos functionality, which which may be included with JRE 8, JDK 8, and OpenJDK 8. @@ -1250,7 +1219,7 @@ included with JDK 8 and OpenJDK 8 source distributions. ------------------------------------------------------------------------------- -%% This notice is provided with respect to libpng 1.5.4, which may be +%% This notice is provided with respect to libpng 1.6.16, which may be included with JRE 8, JDK 8, and OpenJDK 8. --- begin of LICENSE --- @@ -1266,8 +1235,8 @@ this sentence. This code is released under the libpng license. -libpng versions 1.2.6, August 15, 2004, through 1.5.4, July 7, 2011, are -Copyright (c) 2004, 2006-2011 Glenn Randers-Pehrson, and are +libpng versions 1.2.6, August 15, 2004, through 1.6.16, December 22, 2014, are +Copyright (c) 2004, 2006-2014 Glenn Randers-Pehrson, and are distributed according to the same disclaimer and license as libpng-1.2.5 with the following individual added to the list of Contributing Authors @@ -1364,13 +1333,13 @@ certification mark of the Open Source Initiative. Glenn Randers-Pehrson glennrp at users.sourceforge.net -July 7, 2011 +December 22, 2014 --- end of LICENSE --- ------------------------------------------------------------------------------- -%% This notice is provided with respect to libungif 4.1.3, which may be +%% This notice is provided with respect to GIFLIB 5.1.1 & libungif 4.1.3, which may be included with JRE 8, JDK 8, and OpenJDK 8. --- begin of LICENSE --- @@ -1399,13 +1368,13 @@ THE SOFTWARE. ------------------------------------------------------------------------------- -%% This notice is provided with respect to Little CMS 2.5, which may be +%% This notice is provided with respect to Little CMS 2.7, which may be included with JRE 8, JDK 8, and OpenJDK 8. --- begin of LICENSE --- Little CMS -Copyright (c) 1998-2011 Marti Maria Saguer +Copyright (c) 1998-2015 Marti Maria Saguer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/src/share/classes/com/sun/tools/doclets/formats/html/SubWriterHolderWriter.java b/src/share/classes/com/sun/tools/doclets/formats/html/SubWriterHolderWriter.java index f634638b..dbd857dd 100644 --- a/src/share/classes/com/sun/tools/doclets/formats/html/SubWriterHolderWriter.java +++ b/src/share/classes/com/sun/tools/doclets/formats/html/SubWriterHolderWriter.java @@ -113,7 +113,7 @@ public abstract class SubWriterHolderWriter extends HtmlDocletWriter { Content captionSpan; Content span; if (type.isDefaultTab()) { - captionSpan = HtmlTree.SPAN(new StringContent(type.text())); + captionSpan = HtmlTree.SPAN(configuration.getResource(type.resourceKey())); span = HtmlTree.SPAN(type.tabId(), HtmlStyle.activeTableTab, captionSpan); } else { @@ -136,7 +136,7 @@ public abstract class SubWriterHolderWriter extends HtmlDocletWriter { */ public Content getMethodTypeLinks(MethodTypes methodType) { String jsShow = "javascript:show(" + methodType.value() +");"; - HtmlTree link = HtmlTree.A(jsShow, new StringContent(methodType.text())); + HtmlTree link = HtmlTree.A(jsShow, configuration.getResource(methodType.resourceKey())); return link; } diff --git a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java index f74c0849..ae748c3b 100644 --- a/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java +++ b/src/share/classes/com/sun/tools/doclets/formats/html/markup/HtmlWriter.java @@ -471,10 +471,10 @@ public class HtmlWriter { for (Map.Entry<String,Integer> entry : typeMap.entrySet()) { vars.append(sep); sep = ","; - vars.append("\""); - vars.append(entry.getKey()); - vars.append("\":"); - vars.append(entry.getValue()); + vars.append("\"") + .append(entry.getKey()) + .append("\":") + .append(entry.getValue()); } vars.append("};").append(DocletConstants.NL); sep = ""; @@ -482,11 +482,19 @@ public class HtmlWriter { for (MethodTypes entry : methodTypes) { vars.append(sep); sep = ","; - vars.append(entry.value()).append(":"); - vars.append("[").append("\"").append(entry.tabId()); - vars.append("\"").append(sep).append("\"").append(entry.text()).append("\"]"); + vars.append(entry.value()) + .append(":") + .append("[") + .append("\"") + .append(entry.tabId()) + .append("\"") + .append(sep) + .append("\"") + .append(configuration.getText(entry.resourceKey())) + .append("\"]"); } - vars.append("};").append(DocletConstants.NL); + vars.append("};") + .append(DocletConstants.NL); addStyles(HtmlStyle.altColor, vars); addStyles(HtmlStyle.rowColor, vars); addStyles(HtmlStyle.tableTab, vars); diff --git a/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard_ja.properties b/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard_ja.properties index bd7ea237..273fa87c 100644 --- a/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard_ja.properties +++ b/src/share/classes/com/sun/tools/doclets/formats/html/resources/standard_ja.properties @@ -190,4 +190,4 @@ doclet.usage=\u6A19\u6E96\u306Edoclet\u306B\u3088\u308A\u63D0\u4F9B\u3055\u308C\ # L10N: do not localize these words: all none accessibility html missing reference syntax -doclet.X.usage=\u6A19\u6E96\u306Edoclet\u306B\u3088\u308A\u63D0\u4F9B\u3055\u308C\u308B\u3082\u306E:\n -Xdocrootparent <url> doc\u30B3\u30E1\u30F3\u30C8\u5185\u306E/..\u304C\u5F8C\u306B\u7D9A\u304F@docRoot\u306E\u3059\u3079\u3066\u3092\n <url>\u3067\u7F6E\u63DB\u3057\u307E\u3059\n -Xdoclint javadoc\u30B3\u30E1\u30F3\u30C8\u5185\u306E\u554F\u984C\u306B\u5BFE\u3059\u308B\u63A8\u5968\u3055\u308C\u308B\u30C1\u30A7\u30C3\u30AF\u3092\u6709\u52B9\u306B\u3057\u307E\u3059\n -Xdoclint:(all|none|[-]<group>) \n javadoc\u30B3\u30E1\u30F3\u30C8\u5185\u306E\u554F\u984C\u306B\u5BFE\u3059\u308B\u7279\u5B9A\u306E\u30C1\u30A7\u30C3\u30AF\u3092\u6709\u52B9\u307E\u305F\u306F\u7121\u52B9\u306B\u3057\u307E\u3059\u3002\n \u3053\u3053\u3067\u3001<group>\u306Fhtml\u3001missing\u3001reference\u307E\u305F\u306Fsyntax\u306E\u3044\u305A\u308C\u304B\u3067\u3059\u3002\n +doclet.X.usage=\u6A19\u6E96\u306Edoclet\u306B\u3088\u308A\u63D0\u4F9B\u3055\u308C\u308B\u3082\u306E:\n -Xdocrootparent <url> doc\u30B3\u30E1\u30F3\u30C8\u5185\u306E/..\u304C\u5F8C\u306B\u7D9A\u304F@docRoot\u306E\u3059\u3079\u3066\u3092\n <url>\u3067\u7F6E\u63DB\u3057\u307E\u3059\n -Xdoclint javadoc\u30B3\u30E1\u30F3\u30C8\u5185\u306E\u554F\u984C\u306B\u5BFE\u3059\u308B\u63A8\u5968\u3055\u308C\u308B\u30C1\u30A7\u30C3\u30AF\u3092\u6709\u52B9\u306B\u3057\u307E\u3059\n -Xdoclint:(all|none|[-]<group>) \n javadoc\u30B3\u30E1\u30F3\u30C8\u5185\u306E\u554F\u984C\u306B\u5BFE\u3059\u308B\u7279\u5B9A\u306E\u30C1\u30A7\u30C3\u30AF\u3092\u6709\u52B9\u307E\u305F\u306F\u7121\u52B9\u306B\u3057\u307E\u3059\u3002\n \u3053\u3053\u3067\u3001<group>\u306Faccessibility\u3001html\u3001missing\u3001reference\u307E\u305F\u306Fsyntax\u306E\u3044\u305A\u308C\u304B\u3067\u3059\u3002\n diff --git a/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/doclets.properties b/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/doclets.properties index cf21120f..597dd35e 100644 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/doclets.properties +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/doclets.properties @@ -150,6 +150,13 @@ doclet.constructors=constructors doclet.Constructors=Constructors doclet.methods=methods doclet.Methods=Methods +doclet.All_Methods=All Methods +doclet.Static_Methods=Static Methods +doclet.Instance_Methods=Instance Methods +doclet.Abstract_Methods=Abstract Methods +doclet.Concrete_Methods=Concrete Methods +doclet.Default_Methods=Default Methods +doclet.Deprecated_Methods=Deprecated Methods doclet.annotation_type_optional_members=optional elements doclet.Annotation_Type_Optional_Members=Optional Elements doclet.annotation_type_required_members=required elements diff --git a/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/doclets_ja.properties b/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/doclets_ja.properties index 8b724b4f..8051a49b 100644 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/doclets_ja.properties +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/doclets_ja.properties @@ -148,6 +148,13 @@ doclet.constructors=\u30B3\u30F3\u30B9\u30C8\u30E9\u30AF\u30BF doclet.Constructors=\u30B3\u30F3\u30B9\u30C8\u30E9\u30AF\u30BF doclet.methods=\u30E1\u30BD\u30C3\u30C9 doclet.Methods=\u30E1\u30BD\u30C3\u30C9 +doclet.All_Methods=\u3059\u3079\u3066\u306E\u30E1\u30BD\u30C3\u30C9 +doclet.Static_Methods=static\u30E1\u30BD\u30C3\u30C9 +doclet.Instance_Methods=\u30A4\u30F3\u30B9\u30BF\u30F3\u30B9\u30FB\u30E1\u30BD\u30C3\u30C9 +doclet.Abstract_Methods=abstract\u30E1\u30BD\u30C3\u30C9 +doclet.Concrete_Methods=concrete\u30E1\u30BD\u30C3\u30C9 +doclet.Default_Methods=\u30C7\u30D5\u30A9\u30EB\u30C8\u30FB\u30E1\u30BD\u30C3\u30C9 +doclet.Deprecated_Methods=\u63A8\u5968\u3055\u308C\u3066\u3044\u306A\u3044\u30E1\u30BD\u30C3\u30C9 doclet.annotation_type_optional_members=\u4EFB\u610F\u8981\u7D20 doclet.Annotation_Type_Optional_Members=\u4EFB\u610F\u8981\u7D20 doclet.annotation_type_required_members=\u5FC5\u9808\u8981\u7D20 diff --git a/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/doclets_zh_CN.properties b/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/doclets_zh_CN.properties index 28e4f54f..d67b2483 100644 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/doclets_zh_CN.properties +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/doclets_zh_CN.properties @@ -148,6 +148,13 @@ doclet.constructors=\u6784\u9020\u5668 doclet.Constructors=\u6784\u9020\u5668 doclet.methods=\u65B9\u6CD5 doclet.Methods=\u65B9\u6CD5 +doclet.All_Methods=\u6240\u6709\u65B9\u6CD5 +doclet.Static_Methods=\u9759\u6001\u65B9\u6CD5 +doclet.Instance_Methods=\u5B9E\u4F8B\u65B9\u6CD5 +doclet.Abstract_Methods=\u62BD\u8C61\u65B9\u6CD5 +doclet.Concrete_Methods=\u5177\u4F53\u65B9\u6CD5 +doclet.Default_Methods=\u9ED8\u8BA4\u65B9\u6CD5 +doclet.Deprecated_Methods=\u5DF2\u8FC7\u65F6\u7684\u65B9\u6CD5 doclet.annotation_type_optional_members=\u53EF\u9009\u5143\u7D20 doclet.Annotation_Type_Optional_Members=\u53EF\u9009\u5143\u7D20 doclet.annotation_type_required_members=\u5FC5\u9700\u7684\u5143\u7D20 diff --git a/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/stylesheet.css b/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/stylesheet.css index cebb4fd8..98055b22 100644 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/stylesheet.css +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/resources/stylesheet.css @@ -463,7 +463,6 @@ Table styles .useSummary td, .constantsSummary td, .deprecatedSummary td { text-align:left; padding:0px 0px 12px 10px; - width:100%; } th.colOne, th.colFirst, th.colLast, .useSummary th, .constantsSummary th, td.colOne, td.colFirst, td.colLast, .useSummary td, .constantsSummary td{ @@ -488,6 +487,7 @@ td.colOne, th.colOne { font-size:13px; } .overviewSummary td.colFirst, .overviewSummary th.colFirst, +.useSummary td.colFirst, .useSummary th.colFirst, .overviewSummary td.colOne, .overviewSummary th.colOne, .memberSummary td.colFirst, .memberSummary th.colFirst, .memberSummary td.colOne, .memberSummary th.colOne, diff --git a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/MethodTypes.java b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/MethodTypes.java index 7b31ad81..24254350 100644 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/MethodTypes.java +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/MethodTypes.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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,22 +31,22 @@ package com.sun.tools.doclets.internal.toolkit.util; * @author Bhavesh Patel */ public enum MethodTypes { - ALL(0xffff, "All Methods", "t0", true), - STATIC(0x1, "Static Methods", "t1", false), - INSTANCE(0x2, "Instance Methods", "t2", false), - ABSTRACT(0x4, "Abstract Methods", "t3", false), - CONCRETE(0x8, "Concrete Methods", "t4", false), - DEFAULT(0x10, "Default Methods", "t5", false), - DEPRECATED(0x20, "Deprecated Methods", "t6", false); + ALL(0xffff, "doclet.All_Methods", "t0", true), + STATIC(0x1, "doclet.Static_Methods", "t1", false), + INSTANCE(0x2, "doclet.Instance_Methods", "t2", false), + ABSTRACT(0x4, "doclet.Abstract_Methods", "t3", false), + CONCRETE(0x8, "doclet.Concrete_Methods", "t4", false), + DEFAULT(0x10, "doclet.Default_Methods", "t5", false), + DEPRECATED(0x20, "doclet.Deprecated_Methods", "t6", false); private final int value; - private final String text; + private final String resourceKey; private final String tabId; private final boolean isDefaultTab; - MethodTypes(int v, String t, String id, boolean dt) { + MethodTypes(int v, String k, String id, boolean dt) { this.value = v; - this.text = t; + this.resourceKey = k; this.tabId = id; this.isDefaultTab = dt; } @@ -55,8 +55,8 @@ public enum MethodTypes { return value; } - public String text() { - return text; + public String resourceKey() { + return resourceKey; } public String tabId() { diff --git a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java index 72cc196d..bc38491b 100644 --- a/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java +++ b/src/share/classes/com/sun/tools/doclets/internal/toolkit/util/VisibleMemberMap.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2016, 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 @@ -250,7 +250,7 @@ public class VisibleMemberMap { for (int i = 0; i < list.size(); i++) { Object key = getMemberKey(list.get(i)); Map<ProgramElementDoc, String> memberLevelMap = memberNameMap.get(key); - if (level.equals(memberLevelMap.get(list.get(i)))) + if (memberLevelMap != null && level.equals(memberLevelMap.get(list.get(i)))) memberLevelMap.remove(list.get(i)); } } diff --git a/src/share/classes/com/sun/tools/javac/code/Scope.java b/src/share/classes/com/sun/tools/javac/code/Scope.java index dee7c42f..b4899b2a 100644 --- a/src/share/classes/com/sun/tools/javac/code/Scope.java +++ b/src/share/classes/com/sun/tools/javac/code/Scope.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -241,12 +241,16 @@ public class Scope { listeners = listeners.prepend(sl); } - /** Remove symbol from this scope. Used when an inner class - * attribute tells us that the class isn't a package member. + /** Remove symbol from this scope. */ - public void remove(Symbol sym) { + public void remove(final Symbol sym) { Assert.check(shared == 0); - Entry e = lookup(sym.name); + Entry e = lookup(sym.name, new Filter<Symbol>() { + @Override + public boolean accepts(Symbol candidate) { + return candidate == sym; + } + }); if (e.scope == null) return; // remove e from table and shadowed list; diff --git a/src/share/classes/com/sun/tools/javac/code/Symbol.java b/src/share/classes/com/sun/tools/javac/code/Symbol.java index 9efd9f7b..f84ff831 100644 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java @@ -1153,6 +1153,16 @@ public abstract class Symbol extends AnnoConstruct implements Element { public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { return v.visitClassSymbol(this, p); } + + public void markAbstractIfNeeded(Types types) { + if (types.enter.getEnv(this) != null && + (flags() & ENUM) != 0 && types.supertype(type).tsym == types.syms.enumSym && + (flags() & (FINAL | ABSTRACT)) == 0) { + if (types.firstUnimplementedAbstract(this) != null) + // add the ABSTRACT flag to an enum + flags_field |= ABSTRACT; + } + } } diff --git a/src/share/classes/com/sun/tools/javac/code/Type.java b/src/share/classes/com/sun/tools/javac/code/Type.java index 017b85d2..2544199e 100644 --- a/src/share/classes/com/sun/tools/javac/code/Type.java +++ b/src/share/classes/com/sun/tools/javac/code/Type.java @@ -421,6 +421,14 @@ public abstract class Type extends AnnoConstruct implements TypeMirror { && (tsym.flags() & COMPOUND) != 0; } + public boolean isIntersection() { + return false; + } + + public boolean isUnion() { + return false; + } + public boolean isInterface() { return (tsym.flags() & INTERFACE) != 0; } @@ -970,6 +978,11 @@ public abstract class Type extends AnnoConstruct implements TypeMirror { } @Override + public boolean isUnion() { + return true; + } + + @Override public TypeKind getKind() { return TypeKind.UNION; } @@ -1003,6 +1016,11 @@ public abstract class Type extends AnnoConstruct implements TypeMirror { return interfaces_field.prepend(supertype_field); } + @Override + public boolean isIntersection() { + return true; + } + public List<Type> getExplicitComponents() { return allInterfaces ? interfaces_field : diff --git a/src/share/classes/com/sun/tools/javac/code/Types.java b/src/share/classes/com/sun/tools/javac/code/Types.java index a9354648..d7110fbd 100644 --- a/src/share/classes/com/sun/tools/javac/code/Types.java +++ b/src/share/classes/com/sun/tools/javac/code/Types.java @@ -47,6 +47,7 @@ import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.util.*; import static com.sun.tools.javac.code.BoundKind.*; import static com.sun.tools.javac.code.Flags.*; +import static com.sun.tools.javac.code.Kinds.MTH; import static com.sun.tools.javac.code.Scope.*; import static com.sun.tools.javac.code.Symbol.*; import static com.sun.tools.javac.code.Type.*; @@ -85,6 +86,7 @@ public class Types { final boolean allowBoxing; final boolean allowCovariantReturns; final boolean allowObjectToPrimitiveCast; + final boolean allowDefaultMethods; final ClassReader reader; final Check chk; final Enter enter; @@ -111,6 +113,7 @@ public class Types { allowBoxing = source.allowBoxing(); allowCovariantReturns = source.allowCovariantReturns(); allowObjectToPrimitiveCast = source.allowObjectToPrimitiveCast(); + allowDefaultMethods = source.allowDefaultMethods(); reader = ClassReader.instance(context); chk = Check.instance(context); enter = Enter.instance(context); @@ -1536,8 +1539,8 @@ public class Types { } } - if (t.isCompound() || s.isCompound()) { - return !t.isCompound() ? + if (t.isIntersection() || s.isIntersection()) { + return !t.isIntersection() ? visitIntersectionType((IntersectionClassType)s.unannotatedType(), t, true) : visitIntersectionType((IntersectionClassType)t.unannotatedType(), s, false); } @@ -2252,19 +2255,28 @@ public class Types { } // </editor-fold> - // <editor-fold defaultstate="collapsed" desc="makeCompoundType"> + // <editor-fold defaultstate="collapsed" desc="makeIntersectionType"> /** - * Make a compound type from non-empty list of types. The list should be - * ordered according to {@link Symbol#precedes(TypeSymbol,Types)}. + * Make an intersection type from non-empty list of types. The list should be ordered according to + * {@link TypeSymbol#precedes(TypeSymbol, Types)}. Note that this might cause a symbol completion. + * Hence, this version of makeIntersectionType may not be called during a classfile read. * - * @param bounds the types from which the compound type is formed - * @param supertype is objectType if all bounds are interfaces, - * null otherwise. + * @param bounds the types from which the intersection type is formed */ - public Type makeCompoundType(List<Type> bounds) { - return makeCompoundType(bounds, bounds.head.tsym.isInterface()); + public IntersectionClassType makeIntersectionType(List<Type> bounds) { + return makeIntersectionType(bounds, bounds.head.tsym.isInterface()); } - public Type makeCompoundType(List<Type> bounds, boolean allInterfaces) { + + /** + * Make an intersection type from non-empty list of types. The list should be ordered according to + * {@link TypeSymbol#precedes(TypeSymbol, Types)}. This does not cause symbol completion as + * an extra parameter indicates as to whether all bounds are interfaces - in which case the + * supertype is implicitly assumed to be 'Object'. + * + * @param bounds the types from which the intersection type is formed + * @param allInterfaces are all bounds interface types? + */ + public IntersectionClassType makeIntersectionType(List<Type> bounds, boolean allInterfaces) { Assert.check(bounds.nonEmpty()); Type firstExplicitBound = bounds.head; if (allInterfaces) { @@ -2277,23 +2289,24 @@ public class Types { : names.empty, null, syms.noSymbol); - bc.type = new IntersectionClassType(bounds, bc, allInterfaces); + IntersectionClassType intersectionType = new IntersectionClassType(bounds, bc, allInterfaces); + bc.type = intersectionType; bc.erasure_field = (bounds.head.hasTag(TYPEVAR)) ? syms.objectType : // error condition, recover erasure(firstExplicitBound); bc.members_field = new Scope(bc); - return bc.type; + return intersectionType; } /** - * A convenience wrapper for {@link #makeCompoundType(List)}; the + * A convenience wrapper for {@link #makeIntersectionType(List)}; the * arguments are converted to a list and passed to the other * method. Note that this might cause a symbol completion. - * Hence, this version of makeCompoundType may not be called + * Hence, this version of makeIntersectionType may not be called * during a classfile read. */ - public Type makeCompoundType(Type bound1, Type bound2) { - return makeCompoundType(List.of(bound1, bound2)); + public Type makeIntersectionType(Type bound1, Type bound2) { + return makeIntersectionType(List.of(bound1, bound2)); } // </editor-fold> @@ -2433,7 +2446,7 @@ public class Types { private final UnaryVisitor<List<Type>> directSupertypes = new UnaryVisitor<List<Type>>() { public List<Type> visitType(final Type type, final Void ignored) { - if (!type.isCompound()) { + if (!type.isIntersection()) { final Type sup = supertype(type); return (sup == Type.noType || sup == type || sup == null) ? interfaces(type) @@ -2487,30 +2500,32 @@ public class Types { // <editor-fold defaultstate="collapsed" desc="setBounds"> /** - * Set the bounds field of the given type variable to reflect a - * (possibly multiple) list of bounds. - * @param t a type variable - * @param bounds the bounds, must be nonempty - * @param supertype is objectType if all bounds are interfaces, - * null otherwise. + * Same as {@link Types#setBounds(TypeVar, List, boolean)}, except that third parameter is computed directly, + * as follows: if all all bounds are interface types, the computed supertype is Object,otherwise + * the supertype is simply left null (in this case, the supertype is assumed to be the head of + * the bound list passed as second argument). Note that this check might cause a symbol completion. + * Hence, this version of setBounds may not be called during a classfile read. + * + * @param t a type variable + * @param bounds the bounds, must be nonempty */ public void setBounds(TypeVar t, List<Type> bounds) { setBounds(t, bounds, bounds.head.tsym.isInterface()); } /** - * Same as {@link #setBounds(Type.TypeVar,List,Type)}, except that - * third parameter is computed directly, as follows: if all - * all bounds are interface types, the computed supertype is Object, - * otherwise the supertype is simply left null (in this case, the supertype - * is assumed to be the head of the bound list passed as second argument). - * Note that this check might cause a symbol completion. Hence, this version of - * setBounds may not be called during a classfile read. + * Set the bounds field of the given type variable to reflect a (possibly multiple) list of bounds. + * This does not cause symbol completion as an extra parameter indicates as to whether all bounds + * are interfaces - in which case the supertype is implicitly assumed to be 'Object'. + * + * @param t a type variable + * @param bounds the bounds, must be nonempty + * @param allInterfaces are all bounds interface types? */ public void setBounds(TypeVar t, List<Type> bounds, boolean allInterfaces) { t.bound = bounds.tail.isEmpty() ? bounds.head : - makeCompoundType(bounds, allInterfaces); + makeIntersectionType(bounds, allInterfaces); t.rank_field = -1; } // </editor-fold> @@ -2691,78 +2706,155 @@ public class Types { // </editor-fold> // <editor-fold defaultstate="collapsed" desc="compute transitive closure of all members in given site"> - class MembersClosureCache extends SimpleVisitor<CompoundScope, Boolean> { + class MembersClosureCache extends SimpleVisitor<Scope.CompoundScope, Void> { - private WeakHashMap<TypeSymbol, Entry> _map = - new WeakHashMap<TypeSymbol, Entry>(); + private Map<TypeSymbol, CompoundScope> _map = new HashMap<>(); - class Entry { - final boolean skipInterfaces; - final CompoundScope compoundScope; + Set<TypeSymbol> seenTypes = new HashSet<>(); + + class MembersScope extends CompoundScope { + + CompoundScope scope; + + public MembersScope(CompoundScope scope) { + super(scope.owner); + this.scope = scope; + } + + Filter<Symbol> combine(final Filter<Symbol> sf) { + return new Filter<Symbol>() { + @Override + public boolean accepts(Symbol s) { + return !s.owner.isInterface() && (sf == null || sf.accepts(s)); + } + }; + } + + @Override + public Iterable<Symbol> getElements(Filter<Symbol> sf) { + return scope.getElements(combine(sf)); + } - public Entry(boolean skipInterfaces, CompoundScope compoundScope) { - this.skipInterfaces = skipInterfaces; - this.compoundScope = compoundScope; + @Override + public Iterable<Symbol> getElementsByName(Name name, Filter<Symbol> sf) { + return scope.getElementsByName(name, combine(sf)); } - boolean matches(boolean skipInterfaces) { - return this.skipInterfaces == skipInterfaces; + @Override + public int getMark() { + return scope.getMark(); } } - List<TypeSymbol> seenTypes = List.nil(); + CompoundScope nilScope; /** members closure visitor methods **/ - public CompoundScope visitType(Type t, Boolean skipInterface) { - return null; + public CompoundScope visitType(Type t, Void _unused) { + if (nilScope == null) { + nilScope = new CompoundScope(syms.noSymbol); + } + return nilScope; } @Override - public CompoundScope visitClassType(ClassType t, Boolean skipInterface) { - if (seenTypes.contains(t.tsym)) { + public CompoundScope visitClassType(ClassType t, Void _unused) { + if (!seenTypes.add(t.tsym)) { //this is possible when an interface is implemented in multiple - //superclasses, or when a classs hierarchy is circular - in such + //superclasses, or when a class hierarchy is circular - in such //cases we don't need to recurse (empty scope is returned) return new CompoundScope(t.tsym); } try { - seenTypes = seenTypes.prepend(t.tsym); + seenTypes.add(t.tsym); ClassSymbol csym = (ClassSymbol)t.tsym; - Entry e = _map.get(csym); - if (e == null || !e.matches(skipInterface)) { - CompoundScope membersClosure = new CompoundScope(csym); - if (!skipInterface) { - for (Type i : interfaces(t)) { - membersClosure.addSubScope(visit(i, skipInterface)); - } + CompoundScope membersClosure = _map.get(csym); + if (membersClosure == null) { + membersClosure = new CompoundScope(csym); + for (Type i : interfaces(t)) { + membersClosure.addSubScope(visit(i, null)); } - membersClosure.addSubScope(visit(supertype(t), skipInterface)); + membersClosure.addSubScope(visit(supertype(t), null)); membersClosure.addSubScope(csym.members()); - e = new Entry(skipInterface, membersClosure); - _map.put(csym, e); + _map.put(csym, membersClosure); } - return e.compoundScope; + return membersClosure; } finally { - seenTypes = seenTypes.tail; + seenTypes.remove(t.tsym); } } @Override - public CompoundScope visitTypeVar(TypeVar t, Boolean skipInterface) { - return visit(t.getUpperBound(), skipInterface); + public CompoundScope visitTypeVar(TypeVar t, Void _unused) { + return visit(t.getUpperBound(), null); } } private MembersClosureCache membersCache = new MembersClosureCache(); public CompoundScope membersClosure(Type site, boolean skipInterface) { - return membersCache.visit(site, skipInterface); + CompoundScope cs = membersCache.visit(site, null); + if (cs == null) + Assert.error("type " + site); + return skipInterface ? membersCache.new MembersScope(cs) : cs; } // </editor-fold> + /** Return first abstract member of class `sym'. + */ + public MethodSymbol firstUnimplementedAbstract(ClassSymbol sym) { + try { + return firstUnimplementedAbstractImpl(sym, sym); + } catch (CompletionFailure ex) { + chk.completionError(enter.getEnv(sym).tree.pos(), ex); + return null; + } + } + //where: + private MethodSymbol firstUnimplementedAbstractImpl(ClassSymbol impl, ClassSymbol c) { + MethodSymbol undef = null; + // Do not bother to search in classes that are not abstract, + // since they cannot have abstract members. + if (c == impl || (c.flags() & (ABSTRACT | INTERFACE)) != 0) { + Scope s = c.members(); + for (Scope.Entry e = s.elems; + undef == null && e != null; + e = e.sibling) { + if (e.sym.kind == MTH && + (e.sym.flags() & (ABSTRACT|IPROXY|DEFAULT)) == ABSTRACT) { + MethodSymbol absmeth = (MethodSymbol)e.sym; + MethodSymbol implmeth = absmeth.implementation(impl, this, true); + if (implmeth == null || implmeth == absmeth) { + //look for default implementations + if (allowDefaultMethods) { + MethodSymbol prov = interfaceCandidates(impl.type, absmeth).head; + if (prov != null && prov.overrides(absmeth, impl, this, true)) { + implmeth = prov; + } + } + } + if (implmeth == null || implmeth == absmeth) { + undef = absmeth; + } + } + } + if (undef == null) { + Type st = supertype(c.type); + if (st.hasTag(CLASS)) + undef = firstUnimplementedAbstractImpl(impl, (ClassSymbol)st.tsym); + } + for (List<Type> l = interfaces(c.type); + undef == null && l.nonEmpty(); + l = l.tail) { + undef = firstUnimplementedAbstractImpl(impl, (ClassSymbol)l.head.tsym); + } + } + return undef; + } + + //where public List<MethodSymbol> interfaceCandidates(Type site, MethodSymbol ms) { Filter<Symbol> filter = new MethodFilter(ms, site); @@ -2983,7 +3075,7 @@ public class Types { if (st == supertype(t) && is == interfaces(t)) return t; else - return makeCompoundType(is.prepend(st)); + return makeIntersectionType(is.prepend(st)); } } @@ -3486,7 +3578,7 @@ public class Types { else if (compound.tail.isEmpty()) return compound.head; else - return makeCompoundType(compound); + return makeIntersectionType(compound); } /** @@ -3664,8 +3756,8 @@ public class Types { synchronized (this) { if (arraySuperType == null) { // JLS 10.8: all arrays implement Cloneable and Serializable. - arraySuperType = makeCompoundType(List.of(syms.serializableType, - syms.cloneableType), true); + arraySuperType = makeIntersectionType(List.of(syms.serializableType, + syms.cloneableType), true); } } } @@ -3731,7 +3823,7 @@ public class Types { return glbFlattened(union(bounds, lowers), errT); } } - return makeCompoundType(bounds); + return makeIntersectionType(bounds); } // </editor-fold> diff --git a/src/share/classes/com/sun/tools/javac/comp/Attr.java b/src/share/classes/com/sun/tools/javac/comp/Attr.java index f5d52595..a88b6a0f 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java @@ -156,6 +156,8 @@ public class Attr extends JCTree.Visitor { unknownTypeInfo = new ResultInfo(TYP, Type.noType); unknownTypeExprInfo = new ResultInfo(Kinds.TYP | Kinds.VAL, Type.noType); recoveryInfo = new RecoveryInfo(deferredAttr.emptyDeferredAttrContext); + + noCheckTree = make.at(-1).Skip(); } /** Switch: relax some constraints for retrofit mode. @@ -253,31 +255,34 @@ public class Attr extends JCTree.Visitor { Type check(final JCTree tree, final Type found, final int ownkind, final ResultInfo resultInfo) { InferenceContext inferenceContext = resultInfo.checkContext.inferenceContext(); Type owntype; - if (!found.hasTag(ERROR) && !resultInfo.pt.hasTag(METHOD) && !resultInfo.pt.hasTag(FORALL)) { - if ((ownkind & ~resultInfo.pkind) != 0) { - log.error(tree.pos(), "unexpected.type", + boolean shouldCheck = !found.hasTag(ERROR) && + !resultInfo.pt.hasTag(METHOD) && + !resultInfo.pt.hasTag(FORALL); + if (shouldCheck && (ownkind & ~resultInfo.pkind) != 0) { + log.error(tree.pos(), "unexpected.type", kindNames(resultInfo.pkind), kindName(ownkind)); - owntype = types.createErrorType(found); - } else if (allowPoly && inferenceContext.free(found)) { - //delay the check if there are inference variables in the found type - //this means we are dealing with a partially inferred poly expression - owntype = resultInfo.pt; - inferenceContext.addFreeTypeListener(List.of(found, resultInfo.pt), new FreeTypeListener() { + owntype = types.createErrorType(found); + } else if (allowPoly && inferenceContext.free(found)) { + //delay the check if there are inference variables in the found type + //this means we are dealing with a partially inferred poly expression + owntype = shouldCheck ? resultInfo.pt : found; + inferenceContext.addFreeTypeListener(List.of(found, resultInfo.pt), new FreeTypeListener() { @Override public void typesInferred(InferenceContext inferenceContext) { ResultInfo pendingResult = resultInfo.dup(inferenceContext.asInstType(resultInfo.pt)); check(tree, inferenceContext.asInstType(found), ownkind, pendingResult); } - }); - } else { - owntype = resultInfo.check(tree, found); - } + }); } else { - owntype = found; + owntype = shouldCheck ? + resultInfo.check(tree, found) : + found; + } + if (tree != noCheckTree) { + tree.type = owntype; } - tree.type = owntype; return owntype; } @@ -550,6 +555,10 @@ public class Attr extends JCTree.Visitor { */ Type result; + /** Synthetic tree to be used during 'fake' checks. + */ + JCTree noCheckTree; + /** Visitor method: attribute a tree, catching any completion failure * exceptions. Return the tree's type. * @@ -653,8 +662,8 @@ public class Attr extends JCTree.Visitor { /** Attribute the arguments in a method call, returning the method kind. */ - int attribArgs(List<JCExpression> trees, Env<AttrContext> env, ListBuffer<Type> argtypes) { - int kind = VAL; + int attribArgs(int initialKind, List<JCExpression> trees, Env<AttrContext> env, ListBuffer<Type> argtypes) { + int kind = initialKind; for (JCExpression arg : trees) { Type argtype; if (allowPoly && deferredAttr.isDeferred(env, arg)) { @@ -825,9 +834,18 @@ public class Attr extends JCTree.Visitor { } public void visitClassDef(JCClassDecl tree) { - // Local classes have not been entered yet, so we need to do it now: - if ((env.info.scope.owner.kind & (VAR | MTH)) != 0) + // Local and anonymous classes have not been entered yet, so we need to + // do it now. + if ((env.info.scope.owner.kind & (VAR | MTH)) != 0) { enter.classEnter(tree, env); + } else { + // If this class declaration is part of a class level annotation, + // as in @MyAnno(new Object() {}) class MyClass {}, enter it in + // order to simplify later steps and allow for sensible error + // messages. + if (env.tree.hasTag(NEWCLASS) && TreeInfo.isInAnnotation(env, tree)) + enter.classEnter(tree, env); + } ClassSymbol c = tree.sym; if (c == null) { @@ -1721,7 +1739,7 @@ public class Attr extends JCTree.Visitor { localEnv.info.isSelfCall = true; // Attribute arguments, yielding list of argument types. - attribArgs(tree.args, localEnv, argtypesBuf); + int kind = attribArgs(MTH, tree.args, localEnv, argtypesBuf); argtypes = argtypesBuf.toList(); typeargtypes = attribTypes(tree.typeargs, localEnv); @@ -1786,7 +1804,7 @@ public class Attr extends JCTree.Visitor { // ...and check that it is legal in the current context. // (this will also set the tree's type) Type mpt = newMethodTemplate(resultInfo.pt, argtypes, typeargtypes); - checkId(tree.meth, site, sym, localEnv, new ResultInfo(MTH, mpt)); + checkId(tree.meth, site, sym, localEnv, new ResultInfo(kind, mpt)); } // Otherwise, `site' is an error type and we do nothing } @@ -1794,7 +1812,7 @@ public class Attr extends JCTree.Visitor { } else { // Otherwise, we are seeing a regular method call. // Attribute the arguments, yielding list of argument types, ... - int kind = attribArgs(tree.args, localEnv, argtypesBuf); + int kind = attribArgs(VAL, tree.args, localEnv, argtypesBuf); argtypes = argtypesBuf.toList(); typeargtypes = attribAnyTypes(tree.typeargs, localEnv); @@ -1976,7 +1994,7 @@ public class Attr extends JCTree.Visitor { // Attribute constructor arguments. ListBuffer<Type> argtypesBuf = new ListBuffer<>(); - int pkind = attribArgs(tree.args, localEnv, argtypesBuf); + int pkind = attribArgs(VAL, tree.args, localEnv, argtypesBuf); List<Type> argtypes = argtypesBuf.toList(); List<Type> typeargtypes = attribTypes(tree.typeargs, localEnv); @@ -2034,7 +2052,7 @@ public class Attr extends JCTree.Visitor { } }); Type constructorType = tree.constructorType = types.createErrorType(clazztype); - constructorType = checkId(tree, site, + constructorType = checkId(noCheckTree, site, constructor, diamondEnv, diamondResult); @@ -2060,7 +2078,7 @@ public class Attr extends JCTree.Visitor { tree.constructor = rs.resolveConstructor( tree.pos(), rsEnv, clazztype, argtypes, typeargtypes); if (cdef == null) { //do not check twice! - tree.constructorType = checkId(tree, + tree.constructorType = checkId(noCheckTree, clazztype, tree.constructor, rsEnv, @@ -2141,7 +2159,7 @@ public class Attr extends JCTree.Visitor { tree.pos(), localEnv, clazztype, argtypes, typeargtypes); Assert.check(sym.kind < AMBIGUOUS); tree.constructor = sym; - tree.constructorType = checkId(tree, + tree.constructorType = checkId(noCheckTree, clazztype, tree.constructor, localEnv, @@ -2152,6 +2170,17 @@ public class Attr extends JCTree.Visitor { owntype = clazztype; } result = check(tree, owntype, VAL, resultInfo); + InferenceContext inferenceContext = resultInfo.checkContext.inferenceContext(); + if (tree.constructorType != null && inferenceContext.free(tree.constructorType)) { + //we need to wait for inference to finish and then replace inference vars in the constructor type + inferenceContext.addFreeTypeListener(List.of(tree.constructorType), + new FreeTypeListener() { + @Override + public void typesInferred(InferenceContext instantiatedContext) { + tree.constructorType = instantiatedContext.asInstType(tree.constructorType); + } + }); + } chk.validate(tree.typeargs, localEnv); } //where @@ -2379,6 +2408,7 @@ public class Attr extends JCTree.Visitor { preFlow(that); flow.analyzeLambda(env, that, make, isSpeculativeRound); + that.type = currentTarget; //avoids recovery at this stage checkLambdaCompatible(that, lambdaType, resultInfo.checkContext); if (!isSpeculativeRound) { @@ -2425,7 +2455,7 @@ public class Attr extends JCTree.Visitor { @Override public Type visitClassType(ClassType t, DiagnosticPosition pos) { - return t.isCompound() ? + return t.isIntersection() ? visitIntersectionClassType((IntersectionClassType)t, pos) : t; } @@ -2456,8 +2486,7 @@ public class Attr extends JCTree.Visitor { } supertypes.append(i.tsym.type); } - IntersectionClassType notionalIntf = - (IntersectionClassType)types.makeCompoundType(supertypes.toList()); + IntersectionClassType notionalIntf = types.makeIntersectionType(supertypes.toList()); notionalIntf.allparams_field = targs.toList(); notionalIntf.tsym.flags_field |= INTERFACE; return notionalIntf.tsym; @@ -2818,7 +2847,7 @@ public class Attr extends JCTree.Visitor { that.kind.isUnbound() ? argtypes.tail : argtypes, typeargtypes), new FunctionalReturnContext(resultInfo.checkContext)); - Type refType = checkId(that, lookupHelper.site, refSym, localEnv, checkInfo); + Type refType = checkId(noCheckTree, lookupHelper.site, refSym, localEnv, checkInfo); if (that.kind.isUnbound() && resultInfo.checkContext.inferenceContext().free(argtypes.head)) { @@ -2840,6 +2869,8 @@ public class Attr extends JCTree.Visitor { //is a no-op (as this has been taken care during method applicability) boolean isSpeculativeRound = resultInfo.checkContext.deferredAttrContext().mode == DeferredAttr.AttrMode.SPECULATIVE; + + that.type = currentTarget; //avoids recovery at this stage checkReferenceCompatible(that, desc, refType, resultInfo.checkContext, isSpeculativeRound); if (!isSpeculativeRound) { checkAccessibleTypes(that, localEnv, resultInfo.checkContext.inferenceContext(), desc, currentTarget); @@ -3960,7 +3991,7 @@ public class Attr extends JCTree.Visitor { all_multicatchTypes.append(ctype); } } - Type t = check(tree, types.lub(multicatchTypes.toList()), TYP, resultInfo); + Type t = check(noCheckTree, types.lub(multicatchTypes.toList()), TYP, resultInfo); if (t.hasTag(CLASS)) { List<Type> alternatives = ((all_multicatchTypes == null) ? multicatchTypes : all_multicatchTypes).toList(); @@ -4023,7 +4054,7 @@ public class Attr extends JCTree.Visitor { } else if (bounds.length() == 1) { return bounds.head.type; } else { - Type owntype = types.makeCompoundType(TreeInfo.types(bounds)); + Type owntype = types.makeIntersectionType(TreeInfo.types(bounds)); // ... the variable's bound is a class type flagged COMPOUND // (see comment for TypeVar.bound). // In this case, generate a class tree that represents the @@ -4269,6 +4300,8 @@ public class Attr extends JCTree.Visitor { chk.validate(tree.implementing, env); } + c.markAbstractIfNeeded(types); + // If this is a non-abstract class, check that it has no abstract // methods or unimplemented methods of an implemented interface. if ((c.flags() & (ABSTRACT | INTERFACE)) == 0) { diff --git a/src/share/classes/com/sun/tools/javac/comp/AttrContext.java b/src/share/classes/com/sun/tools/javac/comp/AttrContext.java index e9e6224d..0f7cd603 100644 --- a/src/share/classes/com/sun/tools/javac/comp/AttrContext.java +++ b/src/share/classes/com/sun/tools/javac/comp/AttrContext.java @@ -25,6 +25,7 @@ package com.sun.tools.javac.comp; +import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.util.*; import com.sun.tools.javac.code.*; @@ -80,6 +81,13 @@ public class AttrContext { */ Type defaultSuperCallSite = null; + /** Tree that when non null, is to be preferentially used in diagnostics. + * Usually Env<AttrContext>.tree is the tree to be referred to in messages, + * but this may not be true during the window a method is looked up in enclosing + * contexts (JDK-8145466) + */ + JCTree preferredTreeForDiagnostics; + /** Duplicate this context, replacing scope field and copying all others. */ AttrContext dup(Scope scope) { @@ -94,6 +102,7 @@ public class AttrContext { info.returnResult = returnResult; info.defaultSuperCallSite = defaultSuperCallSite; info.isSerializable = isSerializable; + info.preferredTreeForDiagnostics = preferredTreeForDiagnostics; return info; } diff --git a/src/share/classes/com/sun/tools/javac/comp/Check.java b/src/share/classes/com/sun/tools/javac/comp/Check.java index 141b5573..d5e9c47a 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Check.java +++ b/src/share/classes/com/sun/tools/javac/comp/Check.java @@ -1813,7 +1813,7 @@ public class Check { Type t1, Type t2) { return checkCompatibleAbstracts(pos, t1, t2, - types.makeCompoundType(t1, t2)); + types.makeIntersectionType(t1, t2)); } public boolean checkCompatibleAbstracts(DiagnosticPosition pos, @@ -2049,70 +2049,15 @@ public class Check { * @param c The class. */ void checkAllDefined(DiagnosticPosition pos, ClassSymbol c) { - try { - MethodSymbol undef = firstUndef(c, c); - if (undef != null) { - if ((c.flags() & ENUM) != 0 && - types.supertype(c.type).tsym == syms.enumSym && - (c.flags() & FINAL) == 0) { - // add the ABSTRACT flag to an enum - c.flags_field |= ABSTRACT; - } else { - MethodSymbol undef1 = - new MethodSymbol(undef.flags(), undef.name, - types.memberType(c.type, undef), undef.owner); - log.error(pos, "does.not.override.abstract", - c, undef1, undef1.location()); - } - } - } catch (CompletionFailure ex) { - completionError(pos, ex); + MethodSymbol undef = types.firstUnimplementedAbstract(c); + if (undef != null) { + MethodSymbol undef1 = + new MethodSymbol(undef.flags(), undef.name, + types.memberType(c.type, undef), undef.owner); + log.error(pos, "does.not.override.abstract", + c, undef1, undef1.location()); } } -//where - /** Return first abstract member of class `c' that is not defined - * in `impl', null if there is none. - */ - private MethodSymbol firstUndef(ClassSymbol impl, ClassSymbol c) { - MethodSymbol undef = null; - // Do not bother to search in classes that are not abstract, - // since they cannot have abstract members. - if (c == impl || (c.flags() & (ABSTRACT | INTERFACE)) != 0) { - Scope s = c.members(); - for (Scope.Entry e = s.elems; - undef == null && e != null; - e = e.sibling) { - if (e.sym.kind == MTH && - (e.sym.flags() & (ABSTRACT|IPROXY|DEFAULT)) == ABSTRACT) { - MethodSymbol absmeth = (MethodSymbol)e.sym; - MethodSymbol implmeth = absmeth.implementation(impl, types, true); - if (implmeth == null || implmeth == absmeth) { - //look for default implementations - if (allowDefaultMethods) { - MethodSymbol prov = types.interfaceCandidates(impl.type, absmeth).head; - if (prov != null && prov.overrides(absmeth, impl, types, true)) { - implmeth = prov; - } - } - } - if (implmeth == null || implmeth == absmeth) { - undef = absmeth; - } - } - } - if (undef == null) { - Type st = types.supertype(c.type); - if (st.hasTag(CLASS)) - undef = firstUndef(impl, (ClassSymbol)st.tsym); - } - for (List<Type> l = types.interfaces(c.type); - undef == null && l.nonEmpty(); - l = l.tail) { - undef = firstUndef(impl, (ClassSymbol)l.head.tsym); - } - } - return undef; - } void checkNonCyclicDecl(JCClassDecl tree) { CycleChecker cc = new CycleChecker(); diff --git a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java index a8946e4e..c67715e4 100644 --- a/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java +++ b/src/share/classes/com/sun/tools/javac/comp/DeferredAttr.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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 @@ -224,7 +224,8 @@ public class DeferredAttr extends JCTree.Visitor { DeferredStuckPolicy deferredStuckPolicy; if (resultInfo.pt.hasTag(NONE) || resultInfo.pt.isErroneous()) { deferredStuckPolicy = dummyStuckPolicy; - } else if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.SPECULATIVE) { + } else if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.SPECULATIVE || + resultInfo.checkContext.deferredAttrContext().insideOverloadPhase()) { deferredStuckPolicy = new OverloadStuckPolicy(resultInfo, this); } else { deferredStuckPolicy = new CheckStuckPolicy(resultInfo, this); @@ -1255,6 +1256,9 @@ public class DeferredAttr extends JCTree.Visitor { return isSimpleReceiver(((JCAnnotatedType)rec).underlyingType); case APPLY: return true; + case NEWCLASS: + JCNewClass nc = (JCNewClass) rec; + return nc.encl == null && nc.def == null && !TreeInfo.isDiamond(nc); default: return false; } @@ -1309,17 +1313,24 @@ public class DeferredAttr extends JCTree.Visitor { Type site; 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; + switch (rec.getTag()) { + case 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; + break; + case NEWCLASS: + JCNewClass nc = (JCNewClass) rec; + site = attribSpeculative(nc.clazz, env, attr.unknownTypeExprInfo).type; + break; + default: + site = attribSpeculative(rec, env, attr.unknownTypeExprInfo).type; + break; } } else { site = env.enclClass.sym.type; diff --git a/src/share/classes/com/sun/tools/javac/comp/Flow.java b/src/share/classes/com/sun/tools/javac/comp/Flow.java index 0406d0be..6fdfada5 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Flow.java +++ b/src/share/classes/com/sun/tools/javac/comp/Flow.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -353,17 +353,17 @@ public class Flow { this.tree = tree; } - void resolveJump(JCTree tree) { + void resolveJump() { //do nothing } } - abstract void markDead(JCTree tree); + abstract void markDead(); /** Record an outward transfer of control. */ - void recordExit(JCTree tree, P pe) { + void recordExit(P pe) { pendingExits.append(pe); - markDead(tree); + markDead(); } /** Resolve all jumps of this statement. */ @@ -377,7 +377,7 @@ public class Flow { P exit = exits.head; if (exit.tree.hasTag(jk.treeTag) && jk.getTarget(exit.tree) == tree) { - exit.resolveJump(tree); + exit.resolveJump(); resolved = true; } else { pendingExits.append(exit); @@ -420,7 +420,7 @@ public class Flow { private boolean alive; @Override - void markDead(JCTree tree) { + void markDead() { alive = false; } @@ -464,7 +464,7 @@ public class Flow { ListBuffer<PendingExit> pendingExitsPrev = pendingExits; Lint lintPrev = lint; - pendingExits = new ListBuffer<PendingExit>(); + pendingExits = new ListBuffer<>(); lint = lint.augment(tree.sym); try { @@ -513,7 +513,7 @@ public class Flow { log.error(TreeInfo.diagEndPos(tree.body), "missing.ret.stmt"); List<PendingExit> exits = pendingExits.toList(); - pendingExits = new ListBuffer<PendingExit>(); + pendingExits = new ListBuffer<>(); while (exits.nonEmpty()) { PendingExit exit = exits.head; exits = exits.tail; @@ -542,7 +542,7 @@ public class Flow { public void visitDoLoop(JCDoWhileLoop tree) { ListBuffer<PendingExit> prevPendingExits = pendingExits; - pendingExits = new ListBuffer<PendingExit>(); + pendingExits = new ListBuffer<>(); scanStat(tree.body); alive |= resolveContinues(tree); scan(tree.cond); @@ -552,7 +552,7 @@ public class Flow { public void visitWhileLoop(JCWhileLoop tree) { ListBuffer<PendingExit> prevPendingExits = pendingExits; - pendingExits = new ListBuffer<PendingExit>(); + pendingExits = new ListBuffer<>(); scan(tree.cond); alive = !tree.cond.type.isFalse(); scanStat(tree.body); @@ -564,7 +564,7 @@ public class Flow { public void visitForLoop(JCForLoop tree) { ListBuffer<PendingExit> prevPendingExits = pendingExits; scanStats(tree.init); - pendingExits = new ListBuffer<PendingExit>(); + pendingExits = new ListBuffer<>(); if (tree.cond != null) { scan(tree.cond); alive = !tree.cond.type.isFalse(); @@ -582,7 +582,7 @@ public class Flow { visitVarDef(tree.var); ListBuffer<PendingExit> prevPendingExits = pendingExits; scan(tree.expr); - pendingExits = new ListBuffer<PendingExit>(); + pendingExits = new ListBuffer<>(); scanStat(tree.body); alive |= resolveContinues(tree); resolveBreaks(tree, prevPendingExits); @@ -591,14 +591,14 @@ public class Flow { public void visitLabelled(JCLabeledStatement tree) { ListBuffer<PendingExit> prevPendingExits = pendingExits; - pendingExits = new ListBuffer<PendingExit>(); + pendingExits = new ListBuffer<>(); scanStat(tree.body); alive |= resolveBreaks(tree, prevPendingExits); } public void visitSwitch(JCSwitch tree) { ListBuffer<PendingExit> prevPendingExits = pendingExits; - pendingExits = new ListBuffer<PendingExit>(); + pendingExits = new ListBuffer<>(); scan(tree.selector); boolean hasDefault = false; for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) { @@ -625,7 +625,7 @@ public class Flow { public void visitTry(JCTry tree) { ListBuffer<PendingExit> prevPendingExits = pendingExits; - pendingExits = new ListBuffer<PendingExit>(); + pendingExits = new ListBuffer<>(); for (JCTree resource : tree.resources) { if (resource instanceof JCVariableDecl) { JCVariableDecl vdecl = (JCVariableDecl) resource; @@ -688,21 +688,21 @@ public class Flow { } public void visitBreak(JCBreak tree) { - recordExit(tree, new PendingExit(tree)); + recordExit(new PendingExit(tree)); } public void visitContinue(JCContinue tree) { - recordExit(tree, new PendingExit(tree)); + recordExit(new PendingExit(tree)); } public void visitReturn(JCReturn tree) { scan(tree.expr); - recordExit(tree, new PendingExit(tree)); + recordExit(new PendingExit(tree)); } public void visitThrow(JCThrow tree) { scan(tree.expr); - markDead(tree); + markDead(); } public void visitApply(JCMethodInvocation tree) { @@ -756,7 +756,7 @@ public class Flow { try { attrEnv = env; Flow.this.make = make; - pendingExits = new ListBuffer<PendingExit>(); + pendingExits = new ListBuffer<>(); alive = true; scan(tree); } finally { @@ -803,7 +803,7 @@ public class Flow { } @Override - void markDead(JCTree tree) { + void markDead() { //do nothing } @@ -1201,16 +1201,16 @@ public class Flow { } public void visitBreak(JCBreak tree) { - recordExit(tree, new FlowPendingExit(tree, null)); + recordExit(new FlowPendingExit(tree, null)); } public void visitContinue(JCContinue tree) { - recordExit(tree, new FlowPendingExit(tree, null)); + recordExit(new FlowPendingExit(tree, null)); } public void visitReturn(JCReturn tree) { scan(tree.expr); - recordExit(tree, new FlowPendingExit(tree, null)); + recordExit(new FlowPendingExit(tree, null)); } public void visitThrow(JCThrow tree) { @@ -1228,7 +1228,7 @@ public class Flow { else { markThrown(tree, tree.expr.type); } - markDead(tree); + markDead(); } public void visitApply(JCMethodInvocation tree) { @@ -1379,12 +1379,10 @@ public class Flow { * effectively-final local variables/parameters. */ - public abstract class AbstractAssignAnalyzer<P extends AbstractAssignAnalyzer<P>.AbstractAssignPendingExit> - extends BaseAnalyzer<P> { - + public class AssignAnalyzer extends BaseAnalyzer<AssignAnalyzer.AssignPendingExit> { /** The set of definitely assigned variables. */ - protected Bits inits; + final Bits inits; /** The set of definitely unassigned variables. */ @@ -1432,20 +1430,20 @@ public class Flow { */ Scope unrefdResources; - /** Set when processing a loop body the second time for DU analysis. */ + /** Modified when processing a loop body the second time for DU analysis. */ FlowKind flowKind = FlowKind.NORMAL; - /** The starting position of the analysed tree */ + /** The starting position of the analyzed tree */ int startPos; - public class AbstractAssignPendingExit extends BaseAnalyzer.PendingExit { + public class AssignPendingExit extends BaseAnalyzer.PendingExit { final Bits inits; final Bits uninits; final Bits exit_inits = new Bits(true); final Bits exit_uninits = new Bits(true); - public AbstractAssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) { + public AssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) { super(tree); this.inits = inits; this.uninits = uninits; @@ -1454,13 +1452,13 @@ public class Flow { } @Override - public void resolveJump(JCTree tree) { + void resolveJump() { inits.andSet(exit_inits); uninits.andSet(exit_uninits); } } - public AbstractAssignAnalyzer() { + public AssignAnalyzer() { this.inits = new Bits(); uninits = new Bits(); uninitsTry = new Bits(); @@ -1473,7 +1471,7 @@ public class Flow { private boolean isInitialConstructor = false; @Override - protected void markDead(JCTree tree) { + void markDead() { if (!isInitialConstructor) { inits.inclRange(returnadr, nextadr); } else { @@ -1520,35 +1518,41 @@ public class Flow { } sym.adr = nextadr; vardecls[nextadr] = varDecl; - exclVarFromInits(varDecl, nextadr); + inits.excl(nextadr); uninits.incl(nextadr); nextadr++; } - protected void exclVarFromInits(JCTree tree, int adr) { - inits.excl(adr); - } - - protected void assignToInits(JCTree tree, Bits bits) { - inits.assign(bits); - } - - protected void andSetInits(JCTree tree, Bits bits) { - inits.andSet(bits); - } - - protected void orSetInits(JCTree tree, Bits bits) { - inits.orSet(bits); - } - /** Record an initialization of a trackable variable. */ void letInit(DiagnosticPosition pos, VarSymbol sym) { if (sym.adr >= firstadr && trackable(sym)) { - if (uninits.isMember(sym.adr)) { - uninit(sym); + if ((sym.flags() & EFFECTIVELY_FINAL) != 0) { + if (!uninits.isMember(sym.adr)) { + //assignment targeting an effectively final variable + //makes the variable lose its status of effectively final + //if the variable is _not_ definitively unassigned + sym.flags_field &= ~EFFECTIVELY_FINAL; + } else { + uninit(sym); + } + } else if ((sym.flags() & FINAL) != 0) { + if ((sym.flags() & PARAMETER) != 0) { + if ((sym.flags() & UNION) != 0) { //multi-catch parameter + log.error(pos, "multicatch.parameter.may.not.be.assigned", sym); + } else { + log.error(pos, "final.parameter.may.not.be.assigned", + sym); + } + } else if (!uninits.isMember(sym.adr)) { + log.error(pos, flowKind.errKey, sym); + } else { + uninit(sym); + } } inits.incl(sym.adr); + } else if ((sym.flags() & FINAL) != 0) { + log.error(pos, "var.might.already.be.assigned", sym); } } //where @@ -1583,7 +1587,14 @@ public class Flow { checkInit(pos, sym, "var.might.not.have.been.initialized"); } - void checkInit(DiagnosticPosition pos, VarSymbol sym, String errkey) {} + void checkInit(DiagnosticPosition pos, VarSymbol sym, String errkey) { + if ((sym.adr >= firstadr || sym.owner.kind != TYP) && + trackable(sym) && + !inits.isMember(sym.adr)) { + log.error(pos, errkey, sym); + inits.incl(sym.adr); + } + } /** Utility method to reset several Bits instances. */ @@ -1607,7 +1618,7 @@ public class Flow { /** Merge (intersect) inits/uninits from WhenTrue/WhenFalse sets. */ - protected void merge(JCTree tree) { + protected void merge() { inits.assign(initsWhenFalse.andSet(initsWhenTrue)); uninits.assign(uninitsWhenFalse.andSet(uninitsWhenTrue)); } @@ -1623,7 +1634,7 @@ public class Flow { if (tree != null) { scan(tree); if (inits.isReset()) { - merge(tree); + merge(); } } } @@ -1641,7 +1652,7 @@ public class Flow { */ void scanCond(JCTree tree) { if (tree.type.isFalse()) { - if (inits.isReset()) merge(tree); + if (inits.isReset()) merge(); initsWhenTrue.assign(inits); initsWhenTrue.inclRange(firstadr, nextadr); uninitsWhenTrue.assign(uninits); @@ -1649,7 +1660,7 @@ public class Flow { initsWhenFalse.assign(inits); uninitsWhenFalse.assign(uninits); } else if (tree.type.isTrue()) { - if (inits.isReset()) merge(tree); + if (inits.isReset()) merge(); initsWhenFalse.assign(inits); initsWhenFalse.inclRange(firstadr, nextadr); uninitsWhenFalse.assign(uninits); @@ -1668,173 +1679,202 @@ public class Flow { /* ------------ Visitor methods for various sorts of trees -------------*/ - @Override public void visitClassDef(JCClassDecl tree) { if (tree.sym == null) { return; } - JCClassDecl classDefPrev = classDef; - int firstadrPrev = firstadr; - int nextadrPrev = nextadr; - ListBuffer<P> pendingExitsPrev = pendingExits; - - pendingExits = new ListBuffer<P>(); - if (tree.name != names.empty) { - firstadr = nextadr; - } - classDef = tree; + Lint lintPrev = lint; + lint = lint.augment(tree.sym); try { - // define all the static fields - for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { - if (l.head.hasTag(VARDEF)) { - JCVariableDecl def = (JCVariableDecl)l.head; - if ((def.mods.flags & STATIC) != 0) { - VarSymbol sym = def.sym; - if (trackable(sym)) { - newVar(def); + if (tree.sym == null) { + return; + } + + JCClassDecl classDefPrev = classDef; + int firstadrPrev = firstadr; + int nextadrPrev = nextadr; + ListBuffer<AssignPendingExit> pendingExitsPrev = pendingExits; + + pendingExits = new ListBuffer<>(); + if (tree.name != names.empty) { + firstadr = nextadr; + } + classDef = tree; + try { + // define all the static fields + for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { + if (l.head.hasTag(VARDEF)) { + JCVariableDecl def = (JCVariableDecl)l.head; + if ((def.mods.flags & STATIC) != 0) { + VarSymbol sym = def.sym; + if (trackable(sym)) { + newVar(def); + } } } } - } - // process all the static initializers - for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { - if (!l.head.hasTag(METHODDEF) && - (TreeInfo.flags(l.head) & STATIC) != 0) { - scan(l.head); + // process all the static initializers + for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { + if (!l.head.hasTag(METHODDEF) && + (TreeInfo.flags(l.head) & STATIC) != 0) { + scan(l.head); + } } - } - // define all the instance fields - for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { - if (l.head.hasTag(VARDEF)) { - JCVariableDecl def = (JCVariableDecl)l.head; - if ((def.mods.flags & STATIC) == 0) { - VarSymbol sym = def.sym; - if (trackable(sym)) { - newVar(def); + // define all the instance fields + for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { + if (l.head.hasTag(VARDEF)) { + JCVariableDecl def = (JCVariableDecl)l.head; + if ((def.mods.flags & STATIC) == 0) { + VarSymbol sym = def.sym; + if (trackable(sym)) { + newVar(def); + } } } } - } - - // process all the instance initializers - for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { - if (!l.head.hasTag(METHODDEF) && - (TreeInfo.flags(l.head) & STATIC) == 0) { - scan(l.head); + // process all the instance initializers + for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { + if (!l.head.hasTag(METHODDEF) && + (TreeInfo.flags(l.head) & STATIC) == 0) { + scan(l.head); + } } - } - // process all the methods - for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { - if (l.head.hasTag(METHODDEF)) { - scan(l.head); + // process all the methods + for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) { + if (l.head.hasTag(METHODDEF)) { + scan(l.head); + } } + } finally { + pendingExits = pendingExitsPrev; + nextadr = nextadrPrev; + firstadr = firstadrPrev; + classDef = classDefPrev; } } finally { - pendingExits = pendingExitsPrev; - nextadr = nextadrPrev; - firstadr = firstadrPrev; - classDef = classDefPrev; + lint = lintPrev; } } - @Override public void visitMethodDef(JCMethodDecl tree) { if (tree.body == null) { return; } - /* Ignore synthetic methods, except for translated lambda methods. + + /* MemberEnter can generate synthetic methods ignore them */ - if ((tree.sym.flags() & (SYNTHETIC | LAMBDA_METHOD)) == SYNTHETIC) { + if ((tree.sym.flags() & SYNTHETIC) != 0) { return; } - final Bits initsPrev = new Bits(inits); - final Bits uninitsPrev = new Bits(uninits); - int nextadrPrev = nextadr; - int firstadrPrev = firstadr; - int returnadrPrev = returnadr; - - Assert.check(pendingExits.isEmpty()); - boolean lastInitialConstructor = isInitialConstructor; + Lint lintPrev = lint; + lint = lint.augment(tree.sym); try { - isInitialConstructor = TreeInfo.isInitialConstructor(tree); - - if (!isInitialConstructor) { - firstadr = nextadr; + if (tree.body == null) { + return; } - for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { - JCVariableDecl def = l.head; - scan(def); - Assert.check((def.sym.flags() & PARAMETER) != 0, "Method parameter without PARAMETER flag"); - /* If we are executing the code from Gen, then there can be - * synthetic or mandated variables, ignore them. - */ - initParam(def); + /* Ignore synthetic methods, except for translated lambda methods. + */ + if ((tree.sym.flags() & (SYNTHETIC | LAMBDA_METHOD)) == SYNTHETIC) { + return; } - // else we are in an instance initializer block; - // leave caught unchanged. - scan(tree.body); - if (isInitialConstructor) { - boolean isSynthesized = (tree.sym.flags() & - GENERATEDCONSTR) != 0; - for (int i = firstadr; i < nextadr; i++) { - JCVariableDecl vardecl = vardecls[i]; - VarSymbol var = vardecl.sym; - if (var.owner == classDef.sym) { - // choose the diagnostic position based on whether - // the ctor is default(synthesized) or not - if (isSynthesized) { - checkInit(TreeInfo.diagnosticPositionFor(var, vardecl), - var, "var.not.initialized.in.default.constructor"); - } else { - checkInit(TreeInfo.diagEndPos(tree.body), var); - } - } + final Bits initsPrev = new Bits(inits); + final Bits uninitsPrev = new Bits(uninits); + int nextadrPrev = nextadr; + int firstadrPrev = firstadr; + int returnadrPrev = returnadr; + + Assert.check(pendingExits.isEmpty()); + boolean lastInitialConstructor = isInitialConstructor; + try { + isInitialConstructor = TreeInfo.isInitialConstructor(tree); + + if (!isInitialConstructor) { + firstadr = nextadr; } - } - List<P> exits = pendingExits.toList(); - pendingExits = new ListBuffer<>(); - while (exits.nonEmpty()) { - P exit = exits.head; - exits = exits.tail; - Assert.check(exit.tree.hasTag(RETURN), exit.tree); + for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { + JCVariableDecl def = l.head; + scan(def); + Assert.check((def.sym.flags() & PARAMETER) != 0, "Method parameter without PARAMETER flag"); + /* If we are executing the code from Gen, then there can be + * synthetic or mandated variables, ignore them. + */ + initParam(def); + } + // else we are in an instance initializer block; + // leave caught unchanged. + scan(tree.body); + if (isInitialConstructor) { - assignToInits(exit.tree, exit.exit_inits); + boolean isSynthesized = (tree.sym.flags() & + GENERATEDCONSTR) != 0; for (int i = firstadr; i < nextadr; i++) { - checkInit(exit.tree.pos(), vardecls[i].sym); + JCVariableDecl vardecl = vardecls[i]; + VarSymbol var = vardecl.sym; + if (var.owner == classDef.sym) { + // choose the diagnostic position based on whether + // the ctor is default(synthesized) or not + if (isSynthesized) { + checkInit(TreeInfo.diagnosticPositionFor(var, vardecl), + var, "var.not.initialized.in.default.constructor"); + } else { + checkInit(TreeInfo.diagEndPos(tree.body), var); + } + } + } + } + List<AssignPendingExit> exits = pendingExits.toList(); + pendingExits = new ListBuffer<>(); + while (exits.nonEmpty()) { + AssignPendingExit exit = exits.head; + exits = exits.tail; + Assert.check(exit.tree.hasTag(RETURN), exit.tree); + if (isInitialConstructor) { + inits.assign(exit.exit_inits); + for (int i = firstadr; i < nextadr; i++) { + checkInit(exit.tree.pos(), vardecls[i].sym); + } } } + } finally { + inits.assign(initsPrev); + uninits.assign(uninitsPrev); + nextadr = nextadrPrev; + firstadr = firstadrPrev; + returnadr = returnadrPrev; + isInitialConstructor = lastInitialConstructor; } } finally { - assignToInits(tree, initsPrev); - uninits.assign(uninitsPrev); - nextadr = nextadrPrev; - firstadr = firstadrPrev; - returnadr = returnadrPrev; - isInitialConstructor = lastInitialConstructor; + lint = lintPrev; } } protected void initParam(JCVariableDecl def) { inits.incl(def.sym.adr); uninits.excl(def.sym.adr); - } + } public void visitVarDef(JCVariableDecl tree) { - boolean track = trackable(tree.sym); - if (track && tree.sym.owner.kind == MTH) { - newVar(tree); - } - if (tree.init != null) { - scanExpr(tree.init); - if (track) { - letInit(tree.pos(), tree.sym); + Lint lintPrev = lint; + lint = lint.augment(tree.sym); + try{ + boolean track = trackable(tree.sym); + if (track && tree.sym.owner.kind == MTH) { + newVar(tree); + } + if (tree.init != null) { + scanExpr(tree.init); + if (track) { + letInit(tree.pos(), tree.sym); + } } + } finally { + lint = lintPrev; } } @@ -1844,18 +1884,14 @@ public class Flow { nextadr = nextadrPrev; } - int getLogNumberOfErrors() { - return 0; - } - public void visitDoLoop(JCDoWhileLoop tree) { - ListBuffer<P> prevPendingExits = pendingExits; + ListBuffer<AssignPendingExit> prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; final Bits initsSkip = new Bits(true); final Bits uninitsSkip = new Bits(true); - pendingExits = new ListBuffer<P>(); - int prevErrors = getLogNumberOfErrors(); + pendingExits = new ListBuffer<>(); + int prevErrors = log.nerrors; do { final Bits uninitsEntry = new Bits(uninits); uninitsEntry.excludeFrom(nextadr); @@ -1866,28 +1902,28 @@ public class Flow { initsSkip.assign(initsWhenFalse); uninitsSkip.assign(uninitsWhenFalse); } - if (getLogNumberOfErrors() != prevErrors || + if (log.nerrors != prevErrors || flowKind.isFinal() || new Bits(uninitsEntry).diffSet(uninitsWhenTrue).nextBit(firstadr)==-1) break; - assignToInits(tree.cond, initsWhenTrue); + inits.assign(initsWhenTrue); uninits.assign(uninitsEntry.andSet(uninitsWhenTrue)); flowKind = FlowKind.SPECULATIVE_LOOP; } while (true); flowKind = prevFlowKind; - assignToInits(tree, initsSkip); + inits.assign(initsSkip); uninits.assign(uninitsSkip); resolveBreaks(tree, prevPendingExits); } public void visitWhileLoop(JCWhileLoop tree) { - ListBuffer<P> prevPendingExits = pendingExits; + ListBuffer<AssignPendingExit> prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; final Bits initsSkip = new Bits(true); final Bits uninitsSkip = new Bits(true); pendingExits = new ListBuffer<>(); - int prevErrors = getLogNumberOfErrors(); + int prevErrors = log.nerrors; final Bits uninitsEntry = new Bits(uninits); uninitsEntry.excludeFrom(nextadr); do { @@ -1896,11 +1932,11 @@ public class Flow { initsSkip.assign(initsWhenFalse) ; uninitsSkip.assign(uninitsWhenFalse); } - assignToInits(tree, initsWhenTrue); + inits.assign(initsWhenTrue); uninits.assign(uninitsWhenTrue); scan(tree.body); resolveContinues(tree); - if (getLogNumberOfErrors() != prevErrors || + if (log.nerrors != prevErrors || flowKind.isFinal() || new Bits(uninitsEntry).diffSet(uninits).nextBit(firstadr) == -1) { break; @@ -1911,21 +1947,21 @@ public class Flow { flowKind = prevFlowKind; //a variable is DA/DU after the while statement, if it's DA/DU assuming the //branch is not taken AND if it's DA/DU before any break statement - assignToInits(tree.body, initsSkip); + inits.assign(initsSkip); uninits.assign(uninitsSkip); resolveBreaks(tree, prevPendingExits); } public void visitForLoop(JCForLoop tree) { - ListBuffer<P> prevPendingExits = pendingExits; + ListBuffer<AssignPendingExit> prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; int nextadrPrev = nextadr; scan(tree.init); final Bits initsSkip = new Bits(true); final Bits uninitsSkip = new Bits(true); - pendingExits = new ListBuffer<P>(); - int prevErrors = getLogNumberOfErrors(); + pendingExits = new ListBuffer<>(); + int prevErrors = log.nerrors; do { final Bits uninitsEntry = new Bits(uninits); uninitsEntry.excludeFrom(nextadr); @@ -1935,7 +1971,7 @@ public class Flow { initsSkip.assign(initsWhenFalse); uninitsSkip.assign(uninitsWhenFalse); } - assignToInits(tree.body, initsWhenTrue); + inits.assign(initsWhenTrue); uninits.assign(uninitsWhenTrue); } else if (!flowKind.isFinal()) { initsSkip.assign(inits); @@ -1946,7 +1982,7 @@ public class Flow { scan(tree.body); resolveContinues(tree); scan(tree.step); - if (getLogNumberOfErrors() != prevErrors || + if (log.nerrors != prevErrors || flowKind.isFinal() || new Bits(uninitsEntry).diffSet(uninits).nextBit(firstadr) == -1) break; @@ -1956,7 +1992,7 @@ public class Flow { flowKind = prevFlowKind; //a variable is DA/DU after a for loop, if it's DA/DU assuming the //branch is not taken AND if it's DA/DU before any break statement - assignToInits(tree.body, initsSkip); + inits.assign(initsSkip); uninits.assign(uninitsSkip); resolveBreaks(tree, prevPendingExits); nextadr = nextadrPrev; @@ -1965,7 +2001,7 @@ public class Flow { public void visitForeachLoop(JCEnhancedForLoop tree) { visitVarDef(tree.var); - ListBuffer<P> prevPendingExits = pendingExits; + ListBuffer<AssignPendingExit> prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; int nextadrPrev = nextadr; @@ -1974,14 +2010,14 @@ public class Flow { final Bits uninitsStart = new Bits(uninits); letInit(tree.pos(), tree.var.sym); - pendingExits = new ListBuffer<P>(); - int prevErrors = getLogNumberOfErrors(); + pendingExits = new ListBuffer<>(); + int prevErrors = log.nerrors; do { final Bits uninitsEntry = new Bits(uninits); uninitsEntry.excludeFrom(nextadr); scan(tree.body); resolveContinues(tree); - if (getLogNumberOfErrors() != prevErrors || + if (log.nerrors != prevErrors || flowKind.isFinal() || new Bits(uninitsEntry).diffSet(uninits).nextBit(firstadr) == -1) break; @@ -1989,21 +2025,21 @@ public class Flow { flowKind = FlowKind.SPECULATIVE_LOOP; } while (true); flowKind = prevFlowKind; - assignToInits(tree.body, initsStart); + inits.assign(initsStart); uninits.assign(uninitsStart.andSet(uninits)); resolveBreaks(tree, prevPendingExits); nextadr = nextadrPrev; } public void visitLabelled(JCLabeledStatement tree) { - ListBuffer<P> prevPendingExits = pendingExits; - pendingExits = new ListBuffer<P>(); + ListBuffer<AssignPendingExit> prevPendingExits = pendingExits; + pendingExits = new ListBuffer<>(); scan(tree.body); resolveBreaks(tree, prevPendingExits); } public void visitSwitch(JCSwitch tree) { - ListBuffer<P> prevPendingExits = pendingExits; + ListBuffer<AssignPendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); int nextadrPrev = nextadr; scanExpr(tree.selector); @@ -2011,7 +2047,7 @@ public class Flow { final Bits uninitsSwitch = new Bits(uninits); boolean hasDefault = false; for (List<JCCase> l = tree.cases; l.nonEmpty(); l = l.tail) { - assignToInits(l.head, initsSwitch); + inits.assign(initsSwitch); uninits.assign(uninits.andSet(uninitsSwitch)); JCCase c = l.head; if (c.pat == null) { @@ -2020,19 +2056,19 @@ public class Flow { scanExpr(c.pat); } if (hasDefault) { - assignToInits(null, initsSwitch); + inits.assign(initsSwitch); uninits.assign(uninits.andSet(uninitsSwitch)); } scan(c.stats); addVars(c.stats, initsSwitch, uninitsSwitch); if (!hasDefault) { - assignToInits(l.head.stats.last(), initsSwitch); + inits.assign(initsSwitch); uninits.assign(uninits.andSet(uninitsSwitch)); } // Warn about fall-through if lint switch fallthrough enabled. } if (!hasDefault) { - andSetInits(null, initsSwitch); + inits.andSet(initsSwitch); } resolveBreaks(tree, prevPendingExits); nextadr = nextadrPrev; @@ -2051,16 +2087,10 @@ public class Flow { } } - boolean isEnabled(Lint.LintCategory lc) { - return false; - } - - void reportWarning(Lint.LintCategory lc, DiagnosticPosition pos, String key, Object ... args) {} - public void visitTry(JCTry tree) { ListBuffer<JCVariableDecl> resourceVarDecls = new ListBuffer<>(); final Bits uninitsTryPrev = new Bits(uninitsTry); - ListBuffer<P> prevPendingExits = pendingExits; + ListBuffer<AssignPendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); final Bits initsTry = new Bits(inits); uninitsTry.assign(uninits); @@ -2083,10 +2113,10 @@ public class Flow { int nextadrCatch = nextadr; if (!resourceVarDecls.isEmpty() && - isEnabled(Lint.LintCategory.TRY)) { + lint.isEnabled(Lint.LintCategory.TRY)) { for (JCVariableDecl resVar : resourceVarDecls) { if (unrefdResources.includes(resVar.sym)) { - reportWarning(Lint.LintCategory.TRY, resVar.pos(), + log.warning(Lint.LintCategory.TRY, resVar.pos(), "try.resource.not.referenced", resVar.sym); unrefdResources.remove(resVar.sym); } @@ -2102,7 +2132,7 @@ public class Flow { for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) { JCVariableDecl param = l.head.param; - assignToInits(tree.body, initsCatchPrev); + inits.assign(initsCatchPrev); uninits.assign(uninitsCatchPrev); scan(param); /* If this is a TWR and we are executing the code from Gen, @@ -2115,9 +2145,9 @@ public class Flow { nextadr = nextadrCatch; } if (tree.finalizer != null) { - assignToInits(tree.finalizer, initsTry); + inits.assign(initsTry); uninits.assign(uninitsTry); - ListBuffer<P> exits = pendingExits; + ListBuffer<AssignPendingExit> exits = pendingExits; pendingExits = prevPendingExits; scan(tree.finalizer); if (!tree.finallyCanCompleteNormally) { @@ -2127,19 +2157,19 @@ public class Flow { // FIX: this doesn't preserve source order of exits in catch // versus finally! while (exits.nonEmpty()) { - P exit = exits.next(); + AssignPendingExit exit = exits.next(); if (exit.exit_inits != null) { exit.exit_inits.orSet(inits); exit.exit_uninits.andSet(uninits); } pendingExits.append(exit); } - orSetInits(tree, initsEnd); + inits.orSet(initsEnd); } } else { - assignToInits(tree, initsEnd); + inits.assign(initsEnd); uninits.assign(uninitsEnd); - ListBuffer<P> exits = pendingExits; + ListBuffer<AssignPendingExit> exits = pendingExits; pendingExits = prevPendingExits; while (exits.nonEmpty()) pendingExits.append(exits.next()); } @@ -2150,7 +2180,7 @@ public class Flow { scanCond(tree.cond); final Bits initsBeforeElse = new Bits(initsWhenFalse); final Bits uninitsBeforeElse = new Bits(uninitsWhenFalse); - assignToInits(tree.cond, initsWhenTrue); + inits.assign(initsWhenTrue); uninits.assign(uninitsWhenTrue); if (tree.truepart.type.hasTag(BOOLEAN) && tree.falsepart.type.hasTag(BOOLEAN)) { @@ -2163,7 +2193,7 @@ public class Flow { final Bits initsAfterThenWhenFalse = new Bits(initsWhenFalse); final Bits uninitsAfterThenWhenTrue = new Bits(uninitsWhenTrue); final Bits uninitsAfterThenWhenFalse = new Bits(uninitsWhenFalse); - assignToInits(tree.truepart, initsBeforeElse); + inits.assign(initsBeforeElse); uninits.assign(uninitsBeforeElse); scanCond(tree.falsepart); initsWhenTrue.andSet(initsAfterThenWhenTrue); @@ -2174,10 +2204,10 @@ public class Flow { scanExpr(tree.truepart); final Bits initsAfterThen = new Bits(inits); final Bits uninitsAfterThen = new Bits(uninits); - assignToInits(tree.truepart, initsBeforeElse); + inits.assign(initsBeforeElse); uninits.assign(uninitsBeforeElse); scanExpr(tree.falsepart); - andSetInits(tree.falsepart, initsAfterThen); + inits.andSet(initsAfterThen); uninits.andSet(uninitsAfterThen); } } @@ -2186,46 +2216,42 @@ public class Flow { scanCond(tree.cond); final Bits initsBeforeElse = new Bits(initsWhenFalse); final Bits uninitsBeforeElse = new Bits(uninitsWhenFalse); - assignToInits(tree.cond, initsWhenTrue); + inits.assign(initsWhenTrue); uninits.assign(uninitsWhenTrue); scan(tree.thenpart); if (tree.elsepart != null) { final Bits initsAfterThen = new Bits(inits); final Bits uninitsAfterThen = new Bits(uninits); - assignToInits(tree.thenpart, initsBeforeElse); + inits.assign(initsBeforeElse); uninits.assign(uninitsBeforeElse); scan(tree.elsepart); - andSetInits(tree.elsepart, initsAfterThen); + inits.andSet(initsAfterThen); uninits.andSet(uninitsAfterThen); } else { - andSetInits(tree.thenpart, initsBeforeElse); + inits.andSet(initsBeforeElse); uninits.andSet(uninitsBeforeElse); } } - protected P createNewPendingExit(JCTree tree, Bits inits, Bits uninits) { - return null; - } - @Override public void visitBreak(JCBreak tree) { - recordExit(tree, createNewPendingExit(tree, inits, uninits)); + recordExit(new AssignPendingExit(tree, inits, uninits)); } @Override public void visitContinue(JCContinue tree) { - recordExit(tree, createNewPendingExit(tree, inits, uninits)); + recordExit(new AssignPendingExit(tree, inits, uninits)); } @Override public void visitReturn(JCReturn tree) { scanExpr(tree.expr); - recordExit(tree, createNewPendingExit(tree, inits, uninits)); + recordExit(new AssignPendingExit(tree, inits, uninits)); } public void visitThrow(JCThrow tree) { scanExpr(tree.expr); - markDead(tree.expr); + markDead(); } public void visitApply(JCMethodInvocation tree) { @@ -2244,10 +2270,10 @@ public class Flow { final Bits prevUninits = new Bits(uninits); final Bits prevInits = new Bits(inits); int returnadrPrev = returnadr; - ListBuffer<P> prevPending = pendingExits; + ListBuffer<AssignPendingExit> prevPending = pendingExits; try { returnadr = nextadr; - pendingExits = new ListBuffer<P>(); + pendingExits = new ListBuffer<>(); for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { JCVariableDecl def = l.head; scan(def); @@ -2263,7 +2289,7 @@ public class Flow { finally { returnadr = returnadrPrev; uninits.assign(prevUninits); - assignToInits(tree, prevInits); + inits.assign(prevInits); pendingExits = prevPending; } } @@ -2279,11 +2305,11 @@ public class Flow { scanCond(tree.cond); uninitsExit.andSet(uninitsWhenTrue); if (tree.detail != null) { - assignToInits(tree, initsWhenFalse); + inits.assign(initsWhenFalse); uninits.assign(uninitsWhenFalse); scanExpr(tree.detail); } - assignToInits(tree, initsExit); + inits.assign(initsExit); uninits.assign(uninitsExit); } @@ -2351,7 +2377,7 @@ public class Flow { scanCond(tree.lhs); final Bits initsWhenFalseLeft = new Bits(initsWhenFalse); final Bits uninitsWhenFalseLeft = new Bits(uninitsWhenFalse); - assignToInits(tree.lhs, initsWhenTrue); + inits.assign(initsWhenTrue); uninits.assign(uninitsWhenTrue); scanCond(tree.rhs); initsWhenFalse.andSet(initsWhenFalseLeft); @@ -2361,7 +2387,7 @@ public class Flow { scanCond(tree.lhs); final Bits initsWhenTrueLeft = new Bits(initsWhenTrue); final Bits uninitsWhenTrueLeft = new Bits(uninitsWhenTrue); - assignToInits(tree.lhs, initsWhenFalse); + inits.assign(initsWhenFalse); uninits.assign(uninitsWhenFalse); scanCond(tree.rhs); initsWhenTrue.andSet(initsWhenTrueLeft); @@ -2436,136 +2462,6 @@ public class Flow { } } - public class AssignAnalyzer extends AbstractAssignAnalyzer<AssignAnalyzer.AssignPendingExit> { - - public class AssignPendingExit extends AbstractAssignAnalyzer<AssignPendingExit>.AbstractAssignPendingExit { - - public AssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) { - super(tree, inits, uninits); - } - } - - @Override - protected AssignPendingExit createNewPendingExit(JCTree tree, - Bits inits, Bits uninits) { - return new AssignPendingExit(tree, inits, uninits); - } - - /** Record an initialization of a trackable variable. - */ - @Override - void letInit(DiagnosticPosition pos, VarSymbol sym) { - if (sym.adr >= firstadr && trackable(sym)) { - if ((sym.flags() & EFFECTIVELY_FINAL) != 0) { - if (!uninits.isMember(sym.adr)) { - //assignment targeting an effectively final variable - //makes the variable lose its status of effectively final - //if the variable is _not_ definitively unassigned - sym.flags_field &= ~EFFECTIVELY_FINAL; - } else { - uninit(sym); - } - } - else if ((sym.flags() & FINAL) != 0) { - if ((sym.flags() & PARAMETER) != 0) { - if ((sym.flags() & UNION) != 0) { //multi-catch parameter - log.error(pos, "multicatch.parameter.may.not.be.assigned", sym); - } - else { - log.error(pos, "final.parameter.may.not.be.assigned", - sym); - } - } else if (!uninits.isMember(sym.adr)) { - log.error(pos, flowKind.errKey, sym); - } else { - uninit(sym); - } - } - inits.incl(sym.adr); - } else if ((sym.flags() & FINAL) != 0) { - log.error(pos, "var.might.already.be.assigned", sym); - } - } - - @Override - void checkInit(DiagnosticPosition pos, VarSymbol sym, String errkey) { - if ((sym.adr >= firstadr || sym.owner.kind != TYP) && - trackable(sym) && - !inits.isMember(sym.adr)) { - log.error(pos, errkey, sym); - inits.incl(sym.adr); - } - } - - @Override - void reportWarning(Lint.LintCategory lc, DiagnosticPosition pos, - String key, Object ... args) { - log.warning(lc, pos, key, args); - } - - @Override - int getLogNumberOfErrors() { - return log.nerrors; - } - - @Override - boolean isEnabled(Lint.LintCategory lc) { - return lint.isEnabled(lc); - } - - @Override - public void visitClassDef(JCClassDecl tree) { - if (tree.sym == null) { - return; - } - - Lint lintPrev = lint; - lint = lint.augment(tree.sym); - try { - super.visitClassDef(tree); - } finally { - lint = lintPrev; - } - } - - @Override - public void visitMethodDef(JCMethodDecl tree) { - if (tree.body == null) { - return; - } - - /* MemberEnter can generate synthetic methods ignore them - */ - if ((tree.sym.flags() & SYNTHETIC) != 0) { - return; - } - - Lint lintPrev = lint; - lint = lint.augment(tree.sym); - try { - super.visitMethodDef(tree); - } finally { - lint = lintPrev; - } - } - - @Override - public void visitVarDef(JCVariableDecl tree) { - if (tree.init == null) { - super.visitVarDef(tree); - } else { - Lint lintPrev = lint; - lint = lint.augment(tree.sym); - try{ - super.visitVarDef(tree); - } finally { - lint = lintPrev; - } - } - } - - } - /** * This pass implements the last step of the dataflow analysis, namely * the effectively-final analysis check. This checks that every local variable @@ -2578,7 +2474,7 @@ public class Flow { JCTree currentTree; //local class or lambda @Override - void markDead(JCTree tree) { + void markDead() { //do nothing } @@ -2715,7 +2611,7 @@ public class Flow { try { attrEnv = env; Flow.this.make = make; - pendingExits = new ListBuffer<PendingExit>(); + pendingExits = new ListBuffer<>(); scan(tree); } finally { pendingExits = null; diff --git a/src/share/classes/com/sun/tools/javac/comp/Infer.java b/src/share/classes/com/sun/tools/javac/comp/Infer.java index 9d7a01d8..c88386ed 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java @@ -315,11 +315,9 @@ public class Infer { for (Type aLowerBound : from.getBounds(InferenceBound.LOWER)) { for (Type anotherLowerBound : from.getBounds(InferenceBound.LOWER)) { if (aLowerBound != anotherLowerBound && - commonSuperWithDiffParameterization(aLowerBound, anotherLowerBound)) { - /* self comment check if any lower bound may be and undetVar, - * in that case the result of this call may be a false positive. - * Should this be restricted to non free types? - */ + !inferenceContext.free(aLowerBound) && + !inferenceContext.free(anotherLowerBound) && + commonSuperWithDiffParameterization(aLowerBound, anotherLowerBound)) { return generateReferenceToTargetConstraint(tree, from, to, resultInfo, inferenceContext); } @@ -375,7 +373,7 @@ public class Infer { List<Type> upperBounds = uv.getBounds(InferenceBound.UPPER); if (Type.containsAny(upperBounds, vars)) { TypeSymbol fresh_tvar = new TypeVariableSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner); - fresh_tvar.type = new TypeVar(fresh_tvar, types.makeCompoundType(uv.getBounds(InferenceBound.UPPER)), null); + fresh_tvar.type = new TypeVar(fresh_tvar, types.makeIntersectionType(uv.getBounds(InferenceBound.UPPER)), null); todo.append(uv); uv.inst = fresh_tvar.type; } else if (upperBounds.nonEmpty()) { diff --git a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java index 10e9a127..1253f872 100644 --- a/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java +++ b/src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java @@ -265,7 +265,7 @@ public class LambdaToMethod extends TreeTranslator { @Override public void visitLambda(JCLambda tree) { LambdaTranslationContext localContext = (LambdaTranslationContext)context; - MethodSymbol sym = (MethodSymbol)localContext.translatedSym; + MethodSymbol sym = localContext.translatedSym; MethodType lambdaType = (MethodType) sym.type; { @@ -1179,12 +1179,14 @@ public class LambdaToMethod extends TreeTranslator { @Override public void visitClassDef(JCClassDecl tree) { List<Frame> prevStack = frameStack; + int prevLambdaCount = lambdaCount; SyntheticMethodNameCounter prevSyntheticMethodNameCounts = syntheticMethodNameCounts; Map<ClassSymbol, Symbol> prevClinits = clinits; DiagnosticSource prevSource = log.currentSource(); try { log.useSource(tree.sym.sourcefile); + lambdaCount = 0; syntheticMethodNameCounts = new SyntheticMethodNameCounter(); prevClinits = new HashMap<ClassSymbol, Symbol>(); if (tree.sym.owner.kind == MTH) { @@ -1211,6 +1213,7 @@ public class LambdaToMethod extends TreeTranslator { finally { log.useSource(prevSource.getFile()); frameStack = prevStack; + lambdaCount = prevLambdaCount; syntheticMethodNameCounts = prevSyntheticMethodNameCounts; clinits = prevClinits; } @@ -1755,7 +1758,7 @@ public class LambdaToMethod extends TreeTranslator { Map<LambdaSymbolKind, Map<Symbol, Symbol>> translatedSymbols; /** the synthetic symbol for the method hoisting the translated lambda */ - Symbol translatedSym; + MethodSymbol translatedSym; List<JCVariableDecl> syntheticParams; @@ -1883,7 +1886,7 @@ public class LambdaToMethod extends TreeTranslator { * Translate a symbol of a given kind into something suitable for the * synthetic lambda body */ - Symbol translate(Name name, final Symbol sym, LambdaSymbolKind skind) { + Symbol translate(final Symbol sym, LambdaSymbolKind skind) { Symbol ret; switch (skind) { case CAPTURED_THIS: @@ -1891,7 +1894,7 @@ public class LambdaToMethod extends TreeTranslator { break; case TYPE_VAR: // Just erase the type var - ret = new VarSymbol(sym.flags(), name, + ret = new VarSymbol(sym.flags(), sym.name, types.erasure(sym.type), sym.owner); /* this information should also be kept for LVT generation at Gen @@ -1900,7 +1903,7 @@ public class LambdaToMethod extends TreeTranslator { ((VarSymbol)ret).pos = ((VarSymbol)sym).pos; break; case CAPTURED_VAR: - ret = new VarSymbol(SYNTHETIC | FINAL | PARAMETER, name, types.erasure(sym.type), translatedSym) { + ret = new VarSymbol(SYNTHETIC | FINAL | PARAMETER, sym.name, types.erasure(sym.type), translatedSym) { @Override public Symbol baseSymbol() { //keep mapping with original captured symbol @@ -1909,16 +1912,16 @@ public class LambdaToMethod extends TreeTranslator { }; break; case LOCAL_VAR: - ret = new VarSymbol(sym.flags() & FINAL, name, sym.type, translatedSym); + ret = new VarSymbol(sym.flags() & FINAL, sym.name, sym.type, translatedSym); ((VarSymbol) ret).pos = ((VarSymbol) sym).pos; break; case PARAM: - ret = new VarSymbol((sym.flags() & FINAL) | PARAMETER, name, types.erasure(sym.type), translatedSym); + ret = new VarSymbol((sym.flags() & FINAL) | PARAMETER, sym.name, types.erasure(sym.type), translatedSym); ((VarSymbol) ret).pos = ((VarSymbol) sym).pos; break; default: - ret = makeSyntheticVar(FINAL, name, types.erasure(sym.type), translatedSym); - ((VarSymbol) ret).pos = ((VarSymbol) sym).pos; + Assert.error(skind.name()); + throw new AssertionError(); } if (ret != sym) { ret.setDeclarationAttributes(sym.getRawAttributes()); @@ -1929,27 +1932,8 @@ public class LambdaToMethod extends TreeTranslator { void addSymbol(Symbol sym, LambdaSymbolKind skind) { Map<Symbol, Symbol> transMap = getSymbolMap(skind); - Name preferredName; - switch (skind) { - case CAPTURED_THIS: - preferredName = names.fromString("encl$" + transMap.size()); - break; - case CAPTURED_VAR: - preferredName = names.fromString("cap$" + transMap.size()); - break; - case LOCAL_VAR: - preferredName = sym.name; - break; - case PARAM: - preferredName = sym.name; - break; - case TYPE_VAR: - preferredName = sym.name; - break; - default: throw new AssertionError(); - } if (!transMap.containsKey(sym)) { - transMap.put(sym, translate(preferredName, sym, skind)); + transMap.put(sym, translate(sym, skind)); } } @@ -1997,6 +1981,7 @@ public class LambdaToMethod extends TreeTranslator { //compute synthetic params ListBuffer<JCVariableDecl> params = new ListBuffer<>(); + ListBuffer<VarSymbol> parameterSymbols = new ListBuffer<>(); // The signature of the method is augmented with the following // synthetic parameters: @@ -2005,19 +1990,16 @@ public class LambdaToMethod extends TreeTranslator { // 2) enclosing locals captured by the lambda expression for (Symbol thisSym : getSymbolMap(CAPTURED_VAR).values()) { params.append(make.VarDef((VarSymbol) thisSym, null)); - } - if (methodReferenceReceiver != null) { - params.append(make.VarDef( - make.Modifiers(PARAMETER|FINAL), - names.fromString("$rcvr$"), - make.Type(methodReferenceReceiver.type), - null)); + parameterSymbols.append((VarSymbol) thisSym); } for (Symbol thisSym : getSymbolMap(PARAM).values()) { params.append(make.VarDef((VarSymbol) thisSym, null)); + parameterSymbols.append((VarSymbol) thisSym); } syntheticParams = params.toList(); + translatedSym.params = parameterSymbols.toList(); + // Compute and set the lambda name translatedSym.name = isSerializable() ? serializedLambdaName() diff --git a/src/share/classes/com/sun/tools/javac/comp/Lower.java b/src/share/classes/com/sun/tools/javac/comp/Lower.java index 21e8f823..717a3160 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Lower.java +++ b/src/share/classes/com/sun/tools/javac/comp/Lower.java @@ -2540,7 +2540,7 @@ public class Lower extends TreeTranslator { currentMethodSym = currentMethodSymPrev; // Return empty block {} as a placeholder for an inner class. - result = make_at(tree.pos()).Block(0, List.<JCStatement>nil()); + result = make_at(tree.pos()).Block(SYNTHETIC, List.<JCStatement>nil()); } /** Translate an enum class. */ diff --git a/src/share/classes/com/sun/tools/javac/comp/Resolve.java b/src/share/classes/com/sun/tools/javac/comp/Resolve.java index 87a29320..7b3d3e26 100644 --- a/src/share/classes/com/sun/tools/javac/comp/Resolve.java +++ b/src/share/classes/com/sun/tools/javac/comp/Resolve.java @@ -271,7 +271,7 @@ public class Resolve { * the one of its outer environment */ protected static boolean isStatic(Env<AttrContext> env) { - return env.info.staticLevel > env.outer.info.staticLevel; + return env.outer != null && env.info.staticLevel > env.outer.info.staticLevel; } /** An environment is an "initializer" if it is a constructor or @@ -717,7 +717,8 @@ public class Resolve { Warner warn) { //should we expand formals? boolean useVarargs = deferredAttrContext.phase.isVarargsRequired(); - List<JCExpression> trees = TreeInfo.args(env.tree); + JCTree callTree = treeForDiagnostics(env); + List<JCExpression> trees = TreeInfo.args(callTree); //inference context used during this method check InferenceContext inferenceContext = deferredAttrContext.inferenceContext; @@ -726,7 +727,7 @@ public class Resolve { if (varargsFormal == null && argtypes.size() != formals.size()) { - reportMC(env.tree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args + reportMC(callTree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args } while (argtypes.nonEmpty() && formals.head != varargsFormal) { @@ -738,7 +739,7 @@ public class Resolve { } if (formals.head != varargsFormal) { - reportMC(env.tree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args + reportMC(callTree, MethodCheckDiag.ARITY_MISMATCH, inferenceContext); // not enough args } if (useVarargs) { @@ -754,6 +755,11 @@ public class Resolve { } } + // where + private JCTree treeForDiagnostics(Env<AttrContext> env) { + return env.info.preferredTreeForDiagnostics != null ? env.info.preferredTreeForDiagnostics : env.tree; + } + /** * Does the actual argument conforms to the corresponding formal? */ @@ -836,20 +842,19 @@ public class Resolve { List<Type> formals, Warner warn) { super.argumentsAcceptable(env, deferredAttrContext, argtypes, formals, warn); - //should we expand formals? + // should we check varargs element type accessibility? if (deferredAttrContext.phase.isVarargsRequired()) { - Type typeToCheck = null; - if (!checkVarargsAccessAfterResolution) { - typeToCheck = types.elemtype(formals.last()); - } else if (deferredAttrContext.mode == AttrMode.CHECK) { - typeToCheck = types.erasure(types.elemtype(formals.last())); - } - if (typeToCheck != null) { - varargsAccessible(env, typeToCheck, deferredAttrContext.inferenceContext); + if (deferredAttrContext.mode == AttrMode.CHECK || !checkVarargsAccessAfterResolution) { + varargsAccessible(env, types.elemtype(formals.last()), deferredAttrContext.inferenceContext); } } } + /** + * Test that the runtime array element type corresponding to 't' is accessible. 't' should be the + * varargs element type of either the method invocation type signature (after inference completes) + * or the method declaration signature (before inference completes). + */ private void varargsAccessible(final Env<AttrContext> env, final Type t, final InferenceContext inferenceContext) { if (inferenceContext.free(t)) { inferenceContext.addFreeTypeListener(List.of(t), new FreeTypeListener() { @@ -859,7 +864,7 @@ public class Resolve { } }); } else { - if (!isAccessible(env, t)) { + if (!isAccessible(env, types.erasure(t))) { Symbol location = env.enclClass.sym; reportMC(env.tree, MethodCheckDiag.INACCESSIBLE_VARARGS, inferenceContext, t, Kinds.kindName(location), location); } @@ -1829,17 +1834,23 @@ public class Resolve { boolean staticOnly = false; while (env1.outer != null) { if (isStatic(env1)) staticOnly = true; - sym = findMethod( - env1, env1.enclClass.sym.type, name, argtypes, typeargtypes, - allowBoxing, useVarargs, false); - if (sym.exists()) { - if (staticOnly && - sym.kind == MTH && - sym.owner.kind == TYP && - (sym.flags() & STATIC) == 0) return new StaticError(sym); - else return sym; - } else if (sym.kind < bestSoFar.kind) { - bestSoFar = sym; + Assert.check(env1.info.preferredTreeForDiagnostics == null); + env1.info.preferredTreeForDiagnostics = env.tree; + try { + sym = findMethod( + env1, env1.enclClass.sym.type, name, argtypes, typeargtypes, + allowBoxing, useVarargs, false); + if (sym.exists()) { + if (staticOnly && + sym.kind == MTH && + sym.owner.kind == TYP && + (sym.flags() & STATIC) == 0) return new StaticError(sym); + else return sym; + } else if (sym.kind < bestSoFar.kind) { + bestSoFar = sym; + } + } finally { + env1.info.preferredTreeForDiagnostics = null; } if ((env1.enclClass.sym.flags() & STATIC) != 0) staticOnly = true; env1 = env1.outer; @@ -4087,7 +4098,7 @@ public class Resolve { s : new MethodSymbol( s.flags(), s.name, - types.createMethodTypeWithThrown(mt, allThrown), + types.createMethodTypeWithThrown(s.type, allThrown), s.owner); } } @@ -4215,7 +4226,11 @@ public class Resolve { DiagnosticPosition preferedPos, DiagnosticSource preferredSource, DiagnosticType preferredKind, JCDiagnostic d) { JCDiagnostic cause = (JCDiagnostic)d.getArgs()[0]; - return diags.create(preferredKind, preferredSource, d.getDiagnosticPosition(), + DiagnosticPosition pos = d.getDiagnosticPosition(); + if (pos == null) { + pos = preferedPos; + } + return diags.create(preferredKind, preferredSource, pos, "prob.found.req", cause); } }); diff --git a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java index b7f0537e..ad00b788 100644 --- a/src/share/classes/com/sun/tools/javac/comp/TransTypes.java +++ b/src/share/classes/com/sun/tools/javac/comp/TransTypes.java @@ -750,7 +750,7 @@ public class TransTypes extends TreeTranslator { Type originalTarget = tree.type; tree.type = erasure(tree.type); tree.expr = translate(tree.expr, tree.type); - if (originalTarget.isCompound()) { + if (originalTarget.isIntersection()) { Type.IntersectionClassType ict = (Type.IntersectionClassType)originalTarget; for (Type c : ict.getExplicitComponents()) { Type ec = erasure(c); diff --git a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java index 84f2600a..40248923 100644 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassReader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -1779,15 +1779,17 @@ public class ClassReader { // The method wasn't found: emit a warning and recover JavaFileObject prevSource = log.useSource(requestingOwner.classfile); try { - if (failure == null) { - log.warning("annotation.method.not.found", - container, - name); - } else { - log.warning("annotation.method.not.found.reason", - container, - name, - failure.getDetailValue());//diagnostic, if present + if (lintClassfile) { + if (failure == null) { + log.warning("annotation.method.not.found", + container, + name); + } else { + log.warning("annotation.method.not.found.reason", + container, + name, + failure.getDetailValue()); //diagnostic, if present + } } } finally { log.useSource(prevSource); diff --git a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java index 83d43afc..eecd6807 100644 --- a/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java +++ b/src/share/classes/com/sun/tools/javac/jvm/ClassWriter.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -1027,6 +1027,7 @@ public class ClassWriter extends ClassFile { l.nonEmpty(); l = l.tail) { ClassSymbol inner = l.head; + inner.markAbstractIfNeeded(types); char flags = (char) adjustFlags(inner.flags_field); if ((flags & INTERFACE) != 0) flags |= ABSTRACT; // Interfaces are always ABSTRACT if (inner.name.isEmpty()) flags &= ~FINAL; // Anonymous class: unset FINAL flag @@ -1186,7 +1187,7 @@ public class ClassWriter extends ClassFile { Assert.check(r.start_pc >= 0 && r.start_pc <= code.cp); databuf.appendChar(r.start_pc); - Assert.check(r.length >= 0 + Assert.check(r.length > 0 && (r.start_pc + r.length) <= code.cp); databuf.appendChar(r.length); VarSymbol sym = var.sym; diff --git a/src/share/classes/com/sun/tools/javac/jvm/Code.java b/src/share/classes/com/sun/tools/javac/jvm/Code.java index b2a29e79..738c5a1d 100644 --- a/src/share/classes/com/sun/tools/javac/jvm/Code.java +++ b/src/share/classes/com/sun/tools/javac/jvm/Code.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -182,8 +182,6 @@ public class Code { final MethodSymbol meth; - final LVTRanges lvtRanges; - /** Construct a code object, given the settings of the fatcode, * debugging info switches and the CharacterRangeTable. */ @@ -196,8 +194,7 @@ public class Code { CRTable crt, Symtab syms, Types types, - Pool pool, - LVTRanges lvtRanges) { + Pool pool) { this.meth = meth; this.fatcode = fatcode; this.lineMap = lineMap; @@ -219,7 +216,6 @@ public class Code { state = new State(); lvar = new LocalVar[20]; this.pool = pool; - this.lvtRanges = lvtRanges; } @@ -1193,7 +1189,9 @@ public class Code { public int entryPoint(State state) { int pc = curCP(); alive = true; - this.state = state.dup(); + State newState = state.dup(); + setDefined(newState.defined); + this.state = newState; Assert.check(state.stacksize <= max_stack); if (debugCode) System.err.println("entry point " + state); pendingStackMap = needStackMap; @@ -1206,7 +1204,9 @@ public class Code { public int entryPoint(State state, Type pushed) { int pc = curCP(); alive = true; - this.state = state.dup(); + State newState = state.dup(); + setDefined(newState.defined); + this.state = newState; Assert.check(state.stacksize <= max_stack); this.state.push(pushed); if (debugCode) System.err.println("entry point " + state); @@ -2008,27 +2008,6 @@ public class Code { state.defined.excl(adr); } - - public void closeAliveRanges(JCTree tree) { - closeAliveRanges(tree, cp); - } - - public void closeAliveRanges(JCTree tree, int closingCP) { - List<VarSymbol> locals = lvtRanges.getVars(meth, tree); - for (LocalVar localVar: lvar) { - for (VarSymbol aliveLocal : locals) { - if (localVar != null) { - if (localVar.sym == aliveLocal && localVar.lastRange() != null) { - char length = (char)(closingCP - localVar.lastRange().start_pc); - if (length < Character.MAX_VALUE) { - localVar.closeRange(length); - } - } - } - } - } - } - void adjustAliveRanges(int oldCP, int delta) { for (LocalVar localVar: lvar) { if (localVar != null) { @@ -2193,7 +2172,11 @@ public class Code { boolean keepLocalVariables = varDebugInfo || (var.sym.isExceptionParameter() && var.sym.hasTypeAnnotations()); if (!keepLocalVariables) return; - if ((var.sym.flags() & Flags.SYNTHETIC) != 0) return; + //don't keep synthetic vars, unless they are lambda method parameters + boolean ignoredSyntheticVar = (var.sym.flags() & Flags.SYNTHETIC) != 0 && + ((var.sym.owner.flags() & Flags.LAMBDA_METHOD) == 0 || + (var.sym.flags() & Flags.PARAMETER) == 0); + if (ignoredSyntheticVar) return; if (varBuffer == null) varBuffer = new LocalVar[20]; else diff --git a/src/share/classes/com/sun/tools/javac/jvm/Gen.java b/src/share/classes/com/sun/tools/javac/jvm/Gen.java index 74a9fa82..f4e4aabe 100644 --- a/src/share/classes/com/sun/tools/javac/jvm/Gen.java +++ b/src/share/classes/com/sun/tools/javac/jvm/Gen.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -101,10 +101,6 @@ public class Gen extends JCTree.Visitor { */ private Pool pool; - /** LVTRanges info. - */ - private LVTRanges lvtRanges; - private final boolean typeAnnoAsserts; protected Gen(Context context) { @@ -137,9 +133,6 @@ public class Gen extends JCTree.Visitor { options.isUnset(G_CUSTOM) ? options.isSet(G) : options.isSet(G_CUSTOM, "vars"); - if (varDebugInfo) { - lvtRanges = LVTRanges.instance(context); - } genCrt = options.isSet(XJCOV); debugCode = options.isSet("debugcode"); allowInvokedynamic = target.hasInvokedynamic() || options.isSet("invokedynamic"); @@ -493,7 +486,7 @@ public class Gen extends JCTree.Visitor { JCBlock block = (JCBlock)def; if ((block.flags & STATIC) != 0) clinitCode.append(block); - else + else if ((block.flags & SYNTHETIC) == 0) initCode.append(block); break; case METHODDEF: @@ -521,6 +514,10 @@ public class Gen extends JCTree.Visitor { clinitTAs.addAll(getAndRemoveNonFieldTAs(sym)); } else { checkStringConstant(vdef.init.pos(), sym.getConstValue()); + /* if the init contains a reference to an external class, add it to the + * constant's pool + */ + vdef.init.accept(classReferenceVisitor); } } break; @@ -1103,8 +1100,7 @@ public class Gen extends JCTree.Visitor { : null, syms, types, - pool, - varDebugInfo ? lvtRanges : null); + pool); items = new Items(pool, code, syms, types); if (code.debugCode) { System.err.println(meth + " for body " + tree); @@ -1207,30 +1203,14 @@ public class Gen extends JCTree.Visitor { Chain loopDone = c.jumpFalse(); code.resolve(c.trueJumps); genStat(body, loopEnv, CRT_STATEMENT | CRT_FLOW_TARGET); - if (varDebugInfo) { - checkLoopLocalVarRangeEnding(loop, body, - LoopLocalVarRangeEndingPoint.BEFORE_STEPS); - } code.resolve(loopEnv.info.cont); genStats(step, loopEnv); - if (varDebugInfo) { - checkLoopLocalVarRangeEnding(loop, body, - LoopLocalVarRangeEndingPoint.AFTER_STEPS); - } code.resolve(code.branch(goto_), startpc); code.resolve(loopDone); } else { genStat(body, loopEnv, CRT_STATEMENT | CRT_FLOW_TARGET); - if (varDebugInfo) { - checkLoopLocalVarRangeEnding(loop, body, - LoopLocalVarRangeEndingPoint.BEFORE_STEPS); - } code.resolve(loopEnv.info.cont); genStats(step, loopEnv); - if (varDebugInfo) { - checkLoopLocalVarRangeEnding(loop, body, - LoopLocalVarRangeEndingPoint.AFTER_STEPS); - } CondItem c; if (cond != null) { code.statBegin(cond.pos); @@ -1247,44 +1227,6 @@ public class Gen extends JCTree.Visitor { } } - private enum LoopLocalVarRangeEndingPoint { - BEFORE_STEPS, - AFTER_STEPS, - } - - /** - * Checks whether we have reached an alive range ending point for local - * variables after a loop. - * - * Local variables alive range ending point for loops varies depending - * on the loop type. The range can be closed before or after the code - * for the steps sentences has been generated. - * - * - While loops has no steps so in that case the range is closed just - * after the body of the loop. - * - * - For-like loops may have steps so as long as the steps sentences - * can possibly contain non-synthetic local variables, the alive range - * for local variables must be closed after the steps in this case. - */ - private void checkLoopLocalVarRangeEnding(JCTree loop, JCTree body, - LoopLocalVarRangeEndingPoint endingPoint) { - if (varDebugInfo && lvtRanges.containsKey(code.meth, body)) { - switch (endingPoint) { - case BEFORE_STEPS: - if (!loop.hasTag(FORLOOP)) { - code.closeAliveRanges(body); - } - break; - case AFTER_STEPS: - if (loop.hasTag(FORLOOP)) { - code.closeAliveRanges(body); - } - break; - } - } - } - public void visitForeachLoop(JCEnhancedForLoop tree) { throw new AssertionError(); // should have been removed by Lower. } @@ -1398,9 +1340,6 @@ public class Gen extends JCTree.Visitor { // Generate code for the statements in this case. genStats(c.stats, switchEnv, CRT_FLOW_TARGET); - if (varDebugInfo && lvtRanges.containsKey(code.meth, c.stats.last())) { - code.closeAliveRanges(c.stats.last()); - } } // Resolve all breaks. @@ -1557,9 +1496,6 @@ public class Gen extends JCTree.Visitor { genFinalizer(env); code.statBegin(TreeInfo.endPos(env.tree)); Chain exitChain = code.branch(goto_); - if (varDebugInfo && lvtRanges.containsKey(code.meth, body)) { - code.closeAliveRanges(body); - } endFinalizerGap(env); if (startpc != endpc) for (List<JCCatch> l = catchers; l.nonEmpty(); l = l.tail) { // start off with exception on stack @@ -1815,17 +1751,11 @@ public class Gen extends JCTree.Visitor { code.resolve(c.trueJumps); 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, code.cp); - } } if (elseChain != null) { code.resolve(elseChain); if (tree.elsepart != null) { genStat(tree.elsepart, env,CRT_STATEMENT | CRT_FLOW_TARGET); - if (varDebugInfo && lvtRanges.containsKey(code.meth, tree.elsepart)) { - code.closeAliveRanges(tree.elsepart); - } } } code.resolve(thenExit); @@ -1863,6 +1793,11 @@ public class Gen extends JCTree.Visitor { public void visitReturn(JCReturn tree) { int limit = code.nextreg; final Env<GenContext> targetEnv; + + /* Save and then restore the location of the return in case a finally + * is expanded (with unwind()) in the middle of our bytecodes. + */ + int tmpPos = code.pendingStatPos; if (tree.expr != null) { Item r = genExpr(tree.expr, pt).load(); if (hasFinally(env.enclMethod, env)) { @@ -1870,17 +1805,10 @@ public class Gen extends JCTree.Visitor { r.store(); } targetEnv = unwind(env.enclMethod, env); + code.pendingStatPos = tmpPos; r.load(); code.emitop0(ireturn + Code.truncate(Code.typecode(pt))); } else { - /* If we have a statement like: - * - * return; - * - * we need to store the code.pendingStatPos value before generating - * the finalizer. - */ - int tmpPos = code.pendingStatPos; targetEnv = unwind(env.enclMethod, env); code.pendingStatPos = tmpPos; code.emitop0(return_); @@ -2505,25 +2433,18 @@ public class Gen extends JCTree.Visitor { && !allowGenerics // no Miranda methods available with generics ) implementInterfaceMethods(c); - cdef.defs = normalizeDefs(cdef.defs, c); c.pool = pool; pool.reset(); + /* method normalizeDefs() can add references to external classes into the constant pool + * so it should be called after pool.reset() + */ + cdef.defs = normalizeDefs(cdef.defs, c); generateReferencesToPrunedTree(c, pool); Env<GenContext> localEnv = new Env<GenContext>(cdef, new GenContext()); localEnv.toplevel = env.toplevel; localEnv.enclClass = cdef; - /* We must not analyze synthetic methods - */ - if (varDebugInfo && (cdef.sym.flags() & SYNTHETIC) == 0) { - try { - new LVTAssignAnalyzer().analyzeTree(localEnv); - } catch (Throwable e) { - throw e; - } - } - for (List<JCTree> l = cdef.defs; l.nonEmpty(); l = l.tail) { genDef(l.head, localEnv); } @@ -2609,282 +2530,4 @@ public class Gen extends JCTree.Visitor { } } - class LVTAssignAnalyzer - extends Flow.AbstractAssignAnalyzer<LVTAssignAnalyzer.LVTAssignPendingExit> { - - final LVTBits lvtInits; - - /* This class is anchored to a context dependent tree. The tree can - * vary inside the same instruction for example in the switch instruction - * the same FlowBits instance can be anchored to the whole tree, or - * to a given case. The aim is to always anchor the bits to the tree - * capable of closing a DA range. - */ - class LVTBits extends Bits { - - JCTree currentTree; - private int[] oldBits = null; - BitsState stateBeforeOp; - - @Override - public void clear() { - generalOp(null, -1, BitsOpKind.CLEAR); - } - - @Override - protected void internalReset() { - super.internalReset(); - oldBits = null; - } - - @Override - public Bits assign(Bits someBits) { - // bits can be null - oldBits = bits; - stateBeforeOp = currentState; - super.assign(someBits); - changed(); - return this; - } - - @Override - public void excludeFrom(int start) { - generalOp(null, start, BitsOpKind.EXCL_RANGE); - } - - @Override - public void excl(int x) { - Assert.check(x >= 0); - generalOp(null, x, BitsOpKind.EXCL_BIT); - } - - @Override - public Bits andSet(Bits xs) { - return generalOp(xs, -1, BitsOpKind.AND_SET); - } - - @Override - public Bits orSet(Bits xs) { - return generalOp(xs, -1, BitsOpKind.OR_SET); - } - - @Override - public Bits diffSet(Bits xs) { - return generalOp(xs, -1, BitsOpKind.DIFF_SET); - } - - @Override - public Bits xorSet(Bits xs) { - return generalOp(xs, -1, BitsOpKind.XOR_SET); - } - - private Bits generalOp(Bits xs, int i, BitsOpKind opKind) { - Assert.check(currentState != BitsState.UNKNOWN); - oldBits = dupBits(); - stateBeforeOp = currentState; - switch (opKind) { - case AND_SET: - super.andSet(xs); - break; - case OR_SET: - super.orSet(xs); - break; - case XOR_SET: - super.xorSet(xs); - break; - case DIFF_SET: - super.diffSet(xs); - break; - case CLEAR: - super.clear(); - break; - case EXCL_BIT: - super.excl(i); - break; - case EXCL_RANGE: - super.excludeFrom(i); - break; - } - changed(); - return this; - } - - /* The tree we need to anchor the bits instance to. - */ - LVTBits at(JCTree tree) { - this.currentTree = tree; - return this; - } - - /* If the instance should be changed but the tree is not a closing - * tree then a reset is needed or the former tree can mistakingly be - * used. - */ - LVTBits resetTree() { - this.currentTree = null; - return this; - } - - /** This method will be called after any operation that causes a change to - * the bits. Subclasses can thus override it in order to extract information - * from the changes produced to the bits by the given operation. - */ - public void changed() { - if (currentTree != null && - stateBeforeOp != BitsState.UNKNOWN && - trackTree(currentTree)) { - List<VarSymbol> locals = lvtRanges - .getVars(currentMethod, currentTree); - locals = locals != null ? - locals : List.<VarSymbol>nil(); - for (JCVariableDecl vardecl : vardecls) { - //once the first is null, the rest will be so. - if (vardecl == null) { - break; - } - if (trackVar(vardecl.sym) && bitChanged(vardecl.sym.adr)) { - locals = locals.prepend(vardecl.sym); - } - } - if (!locals.isEmpty()) { - lvtRanges.setEntry(currentMethod, - currentTree, locals); - } - } - } - - boolean bitChanged(int x) { - boolean isMemberOfBits = isMember(x); - int[] tmp = bits; - bits = oldBits; - boolean isMemberOfOldBits = isMember(x); - bits = tmp; - return (!isMemberOfBits && isMemberOfOldBits); - } - - boolean trackVar(VarSymbol var) { - return (var.owner.kind == MTH && - (var.flags() & PARAMETER) == 0 && - trackable(var)); - } - - boolean trackTree(JCTree tree) { - switch (tree.getTag()) { - // of course a method closes the alive range of a local variable. - case METHODDEF: - // for while loops we want only the body - case WHILELOOP: - return false; - } - return true; - } - - } - - public class LVTAssignPendingExit extends - Flow.AbstractAssignAnalyzer<LVTAssignPendingExit>.AbstractAssignPendingExit { - - LVTAssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) { - super(tree, inits, uninits); - } - - @Override - public void resolveJump(JCTree tree) { - lvtInits.at(tree); - super.resolveJump(tree); - } - } - - private LVTAssignAnalyzer() { - flow.super(); - lvtInits = new LVTBits(); - inits = lvtInits; - } - - @Override - protected void markDead(JCTree tree) { - lvtInits.at(tree).inclRange(returnadr, nextadr); - super.markDead(tree); - } - - @Override - protected void merge(JCTree tree) { - lvtInits.at(tree); - super.merge(tree); - } - - boolean isSyntheticOrMandated(Symbol sym) { - return (sym.flags() & (SYNTHETIC | MANDATED)) != 0; - } - - @Override - protected boolean trackable(VarSymbol sym) { - if (isSyntheticOrMandated(sym)) { - //fast check to avoid tracking synthetic or mandated variables - return false; - } - return super.trackable(sym); - } - - @Override - protected void initParam(JCVariableDecl def) { - if (!isSyntheticOrMandated(def.sym)) { - super.initParam(def); - } - } - - @Override - protected void assignToInits(JCTree tree, Bits bits) { - lvtInits.at(tree); - lvtInits.assign(bits); - } - - @Override - protected void andSetInits(JCTree tree, Bits bits) { - lvtInits.at(tree); - lvtInits.andSet(bits); - } - - @Override - protected void orSetInits(JCTree tree, Bits bits) { - lvtInits.at(tree); - lvtInits.orSet(bits); - } - - @Override - protected void exclVarFromInits(JCTree tree, int adr) { - lvtInits.at(tree); - lvtInits.excl(adr); - } - - @Override - protected LVTAssignPendingExit createNewPendingExit(JCTree tree, Bits inits, Bits uninits) { - return new LVTAssignPendingExit(tree, inits, uninits); - } - - MethodSymbol currentMethod; - - @Override - public void visitMethodDef(JCMethodDecl tree) { - if ((tree.sym.flags() & (SYNTHETIC | GENERATEDCONSTR)) != 0 - && (tree.sym.flags() & LAMBDA_METHOD) == 0) { - return; - } - if (tree.name.equals(names.clinit)) { - return; - } - boolean enumClass = (tree.sym.owner.flags() & ENUM) != 0; - if (enumClass && - (tree.name.equals(names.valueOf) || - tree.name.equals(names.values) || - tree.name.equals(names.init))) { - return; - } - currentMethod = tree.sym; - - super.visitMethodDef(tree); - } - - } - } diff --git a/src/share/classes/com/sun/tools/javac/jvm/LVTRanges.java b/src/share/classes/com/sun/tools/javac/jvm/LVTRanges.java deleted file mode 100644 index 71139ee7..00000000 --- a/src/share/classes/com/sun/tools/javac/jvm/LVTRanges.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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. 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.jvm; - -import java.util.Map; -import java.util.Map.Entry; -import java.util.WeakHashMap; - -import com.sun.tools.javac.code.Symbol.MethodSymbol; -import com.sun.tools.javac.code.Symbol.VarSymbol; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.List; - -/** This class contains a one to many relation between a tree and a set of variables. - * The relation implies that the given tree closes the DA (definite assignment) - * range for the set of variables. - * - * <p><b>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.</b> - */ -public class LVTRanges { - /** The context key for the LVT ranges. */ - protected static final Context.Key<LVTRanges> lvtRangesKey = new Context.Key<>(); - - /** Get the LVTRanges instance for this context. */ - public static LVTRanges instance(Context context) { - LVTRanges instance = context.get(lvtRangesKey); - if (instance == null) { - instance = new LVTRanges(context); - } - return instance; - } - - private static final long serialVersionUID = 1812267524140424433L; - - protected Context context; - - protected Map<MethodSymbol, Map<JCTree, List<VarSymbol>>> - aliveRangeClosingTrees = new WeakHashMap<>(); - - public LVTRanges(Context context) { - this.context = context; - context.put(lvtRangesKey, this); - } - - public List<VarSymbol> getVars(MethodSymbol method, JCTree tree) { - Map<JCTree, List<VarSymbol>> varMap = aliveRangeClosingTrees.get(method); - return (varMap != null) ? varMap.get(tree) : null; - } - - public boolean containsKey(MethodSymbol method, JCTree tree) { - Map<JCTree, List<VarSymbol>> varMap = aliveRangeClosingTrees.get(method); - if (varMap == null) { - return false; - } - return varMap.containsKey(tree); - } - - public void setEntry(MethodSymbol method, JCTree tree, List<VarSymbol> vars) { - Map<JCTree, List<VarSymbol>> varMap = aliveRangeClosingTrees.get(method); - if (varMap != null) { - varMap.put(tree, vars); - } else { - varMap = new WeakHashMap<>(); - varMap.put(tree, vars); - aliveRangeClosingTrees.put(method, varMap); - } - } - - public List<VarSymbol> removeEntry(MethodSymbol method, JCTree tree) { - Map<JCTree, List<VarSymbol>> varMap = aliveRangeClosingTrees.get(method); - if (varMap != null) { - List<VarSymbol> result = varMap.remove(tree); - if (varMap.isEmpty()) { - aliveRangeClosingTrees.remove(method); - } - return result; - } - return null; - } - - /* This method should be used for debugging LVT related issues. - */ - @Override - public String toString() { - String result = ""; - for (Entry<MethodSymbol, Map<JCTree, List<VarSymbol>>> mainEntry: aliveRangeClosingTrees.entrySet()) { - result += "Method: \n" + mainEntry.getKey().flatName() + "\n"; - int i = 1; - for (Entry<JCTree, List<VarSymbol>> treeEntry: mainEntry.getValue().entrySet()) { - result += " Tree " + i + ": \n" + treeEntry.getKey().toString() + "\n"; - result += " Variables closed:\n"; - for (VarSymbol var: treeEntry.getValue()) { - result += " " + var.toString(); - } - result += "\n"; - i++; - } - } - return result; - } - -} diff --git a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java index 077cc568..c1ae0474 100644 --- a/src/share/classes/com/sun/tools/javac/parser/JavacParser.java +++ b/src/share/classes/com/sun/tools/javac/parser/JavacParser.java @@ -2720,7 +2720,7 @@ public class JavacParser implements Parser { } else { JCExpression t = term(EXPR | TYPE); if ((lastmode & TYPE) != 0 && LAX_IDENTIFIER.accepts(token.kind)) { - return variableDeclarators(modifiersOpt(), t, stats).toList(); + return variableDeclarators(mods(pos, 0, List.<JCAnnotation>nil()), t, stats).toList(); } else if ((lastmode & TYPE) != 0 && token.kind == COLON) { error(pos, "bad.initializer", "for-loop"); return List.of((JCStatement)F.at(pos).VarDef(null, null, t, null)); @@ -2829,16 +2829,20 @@ public class JavacParser implements Parser { default: break; } - /* A modifiers tree with no modifier tokens or annotations - * has no text position. */ - if ((flags & (Flags.ModifierFlags | Flags.ANNOTATION)) == 0 && annotations.isEmpty()) - pos = Position.NOPOS; - - JCModifiers mods = F.at(pos).Modifiers(flags, annotations.toList()); - if (pos != Position.NOPOS) - storeEnd(mods, S.prevToken().endPos); - return mods; + return mods(pos, flags, annotations.toList()); } + //where + JCModifiers mods(int pos, long flags, List<JCAnnotation> annotations) { + /* A modifiers tree with no modifier tokens or annotations + * has no text position. */ + if ((flags & (Flags.ModifierFlags | Flags.ANNOTATION)) == 0 && annotations.isEmpty()) + pos = Position.NOPOS; + + JCModifiers mods = F.at(pos).Modifiers(flags, annotations); + if (pos != Position.NOPOS) + storeEnd(mods, S.prevToken().endPos); + return mods; + } /** Annotation = "@" Qualident [ "(" AnnotationFieldValues ")" ] * diff --git a/src/share/classes/com/sun/tools/javac/resources/javac.properties b/src/share/classes/com/sun/tools/javac/resources/javac.properties index 328d9fbf..f4079152 100644 --- a/src/share/classes/com/sun/tools/javac/resources/javac.properties +++ b/src/share/classes/com/sun/tools/javac/resources/javac.properties @@ -232,9 +232,9 @@ These options are non-standard and subject to change without notice. javac.msg.bug=\ An exception has occurred in the compiler ({0}). \ -Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) \ -after checking the Bug Parade for duplicates. \ -Include your program and the following diagnostic in your report. Thank you. +Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) \ +after checking the Bug Database (http://bugs.java.com) for duplicates. \ +Include your program and the following diagnostic in your report. Thank you. javac.msg.io=\ \n\nAn input/output error occurred.\n\ diff --git a/src/share/classes/com/sun/tools/javac/resources/javac_ja.properties b/src/share/classes/com/sun/tools/javac/resources/javac_ja.properties index 17d96af7..4d86f6aa 100644 --- a/src/share/classes/com/sun/tools/javac/resources/javac_ja.properties +++ b/src/share/classes/com/sun/tools/javac/resources/javac_ja.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1999, 2015, 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 @@ -133,7 +133,7 @@ javac.msg.usage=\u4F7F\u7528\u65B9\u6CD5: {0} <options> <source files>\n\u4F7F\u javac.msg.usage.nonstandard.footer=\u3053\u308C\u3089\u306F\u975E\u6A19\u6E96\u30AA\u30D7\u30B7\u30E7\u30F3\u3067\u3042\u308A\u4E88\u544A\u306A\u3057\u306B\u5909\u66F4\u3055\u308C\u308B\u3053\u3068\u304C\u3042\u308A\u307E\u3059\u3002 -javac.msg.bug=\u30B3\u30F3\u30D1\u30A4\u30E9\u3067\u4F8B\u5916\u304C\u767A\u751F\u3057\u307E\u3057\u305F({0})\u3002Bug Parade\u3067\u91CD\u8907\u304C\u306A\u3044\u304B\u3092\u3054\u78BA\u8A8D\u306E\u3046\u3048\u3001Java Developer Connection (http://java.sun.com/webapps/bugreport)\u3067bug\u306E\u767B\u9332\u3092\u304A\u9858\u3044\u3044\u305F\u3057\u307E\u3059\u3002\u30EC\u30DD\u30FC\u30C8\u306B\u306F\u3001\u305D\u306E\u30D7\u30ED\u30B0\u30E9\u30E0\u3068\u4E0B\u8A18\u306E\u8A3A\u65AD\u5185\u5BB9\u3092\u542B\u3081\u3066\u304F\u3060\u3055\u3044\u3002\u3054\u5354\u529B\u3042\u308A\u304C\u3068\u3046\u3054\u3056\u3044\u307E\u3059\u3002 +javac.msg.bug=\u30B3\u30F3\u30D1\u30A4\u30E9\u3067\u4F8B\u5916\u304C\u767A\u751F\u3057\u307E\u3057\u305F({0})\u3002Bug Database (http://bugs.java.com)\u3067\u91CD\u8907\u304C\u306A\u3044\u304B\u3092\u3054\u78BA\u8A8D\u306E\u3046\u3048\u3001Java bug\u30EC\u30DD\u30FC\u30C8\u30FB\u30DA\u30FC\u30B8(http://bugreport.java.com)\u3067Java\u30B3\u30F3\u30D1\u30A4\u30E9\u306B\u5BFE\u3059\u308Bbug\u306E\u767B\u9332\u3092\u304A\u9858\u3044\u3044\u305F\u3057\u307E\u3059\u3002\u30EC\u30DD\u30FC\u30C8\u306B\u306F\u3001\u305D\u306E\u30D7\u30ED\u30B0\u30E9\u30E0\u3068\u4E0B\u8A18\u306E\u8A3A\u65AD\u5185\u5BB9\u3092\u542B\u3081\u3066\u304F\u3060\u3055\u3044\u3002\u3054\u5354\u529B\u3042\u308A\u304C\u3068\u3046\u3054\u3056\u3044\u307E\u3059\u3002 javac.msg.io=\n\n\u5165\u51FA\u529B\u30A8\u30E9\u30FC\u304C\u767A\u751F\u3057\u307E\u3057\u305F\u3002\n\u8A73\u7D30\u306F\u6B21\u306E\u30B9\u30BF\u30C3\u30AF\u30FB\u30C8\u30EC\u30FC\u30B9\u3067\u8ABF\u67FB\u3057\u3066\u304F\u3060\u3055\u3044\u3002\n diff --git a/src/share/classes/com/sun/tools/javac/resources/javac_zh_CN.properties b/src/share/classes/com/sun/tools/javac/resources/javac_zh_CN.properties index 2ad0c68e..6f9f5f9a 100644 --- a/src/share/classes/com/sun/tools/javac/resources/javac_zh_CN.properties +++ b/src/share/classes/com/sun/tools/javac/resources/javac_zh_CN.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 1999, 2015, 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 @@ -133,7 +133,7 @@ javac.msg.usage=\u7528\u6CD5: {0} <options> <source files>\n-help \u7528\u4E8E\u javac.msg.usage.nonstandard.footer=\u8FD9\u4E9B\u9009\u9879\u90FD\u662F\u975E\u6807\u51C6\u9009\u9879, \u5982\u6709\u66F4\u6539, \u6055\u4E0D\u53E6\u884C\u901A\u77E5\u3002 -javac.msg.bug=\u7F16\u8BD1\u5668 ({0}) \u4E2D\u51FA\u73B0\u5F02\u5E38\u9519\u8BEF\u3002 \u5982\u679C\u5728 Bug Parade \u4E2D\u6CA1\u6709\u627E\u5230\u8BE5\u9519\u8BEF, \u8BF7\u5728 Java Developer Connection (http://java.sun.com/webapps/bugreport) \u4E2D\u5EFA\u7ACB Bug\u3002\u8BF7\u5728\u62A5\u544A\u4E2D\u9644\u4E0A\u60A8\u7684\u7A0B\u5E8F\u548C\u4EE5\u4E0B\u8BCA\u65AD\u4FE1\u606F\u3002\u8C22\u8C22\u3002 +javac.msg.bug=\u7F16\u8BD1\u5668 ({0}) \u4E2D\u51FA\u73B0\u5F02\u5E38\u9519\u8BEF\u3002\u5982\u679C\u5728 Bug Database (http://bugs.java.com) \u4E2D\u6CA1\u6709\u627E\u5230\u8BE5\u9519\u8BEF, \u8BF7\u901A\u8FC7 Java Bug \u62A5\u544A\u9875 (http://bugreport.java.com) \u5EFA\u7ACB\u8BE5 Java \u7F16\u8BD1\u5668 Bug\u3002\u8BF7\u5728\u62A5\u544A\u4E2D\u9644\u4E0A\u60A8\u7684\u7A0B\u5E8F\u548C\u4EE5\u4E0B\u8BCA\u65AD\u4FE1\u606F\u3002\u8C22\u8C22\u3002 javac.msg.io=\n\n\u53D1\u751F\u8F93\u5165/\u8F93\u51FA\u9519\u8BEF\u3002\n\u6709\u5173\u8BE6\u7EC6\u4FE1\u606F, \u8BF7\u53C2\u9605\u4EE5\u4E0B\u5806\u6808\u8DDF\u8E2A\u3002\n diff --git a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java index f8d7d583..66a61b1f 100644 --- a/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java +++ b/src/share/classes/com/sun/tools/javac/tree/TreeInfo.java @@ -28,6 +28,7 @@ package com.sun.tools.javac.tree; import com.sun.source.tree.Tree; +import com.sun.source.util.TreePath; import com.sun.tools.javac.code.*; import com.sun.tools.javac.comp.AttrContext; import com.sun.tools.javac.comp.Env; @@ -351,6 +352,18 @@ public class TreeInfo { return (lit.typetag == BOT); } + /** Return true iff this tree is a child of some annotation. */ + public static boolean isInAnnotation(Env<?> env, JCTree tree) { + TreePath tp = TreePath.getPath(env.toplevel, tree); + if (tp != null) { + for (Tree t : tp) { + if (t.getKind() == Tree.Kind.ANNOTATION) + return true; + } + } + return false; + } + public static String getCommentText(Env<?> env, JCTree tree) { DocCommentTable docComments = (tree.hasTag(JCTree.Tag.TOPLEVEL)) ? ((JCCompilationUnit) tree).docComments diff --git a/src/share/classes/com/sun/tools/javac/util/Bits.java b/src/share/classes/com/sun/tools/javac/util/Bits.java index 4319aad3..10efd474 100644 --- a/src/share/classes/com/sun/tools/javac/util/Bits.java +++ b/src/share/classes/com/sun/tools/javac/util/Bits.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, 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 @@ -84,20 +84,6 @@ public class Bits { } - public enum BitsOpKind { - INIT, - CLEAR, - INCL_BIT, - EXCL_BIT, - ASSIGN, - AND_SET, - OR_SET, - DIFF_SET, - XOR_SET, - INCL_RANGE, - EXCL_RANGE, - } - private final static int wordlen = 32; private final static int wordshift = 5; private final static int wordmask = wordlen - 1; diff --git a/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java b/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java index ae0cbd2d..11e54b84 100644 --- a/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java +++ b/src/share/classes/com/sun/tools/javadoc/ClassDocImpl.java @@ -124,19 +124,14 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc { * Returns the flags of a ClassSymbol in terms of javac's flags */ static long getFlags(ClassSymbol clazz) { - while (true) { - try { - return clazz.flags(); - } catch (CompletionFailure ex) { - /* Quietly ignore completion failures. - * Note that a CompletionFailure can only - * occur as a result of calling complete(), - * which will always remove the current - * completer, leaving it to be null or - * follow-up completer. Thus the loop - * is guaranteed to eventually terminate. - */ - } + try { + return clazz.flags(); + } catch (CompletionFailure ex) { + /* Quietly ignore completion failures and try again - the type + * for which the CompletionFailure was thrown shouldn't be completed + * again by the completer that threw the CompletionFailure. + */ + return getFlags(clazz); } } diff --git a/src/share/classes/com/sun/tools/javadoc/MethodDocImpl.java b/src/share/classes/com/sun/tools/javadoc/MethodDocImpl.java index 4d5d191b..7a3449d9 100644 --- a/src/share/classes/com/sun/tools/javadoc/MethodDocImpl.java +++ b/src/share/classes/com/sun/tools/javadoc/MethodDocImpl.java @@ -128,7 +128,7 @@ public class MethodDocImpl t.hasTag(CLASS); t = env.types.supertype(t)) { ClassSymbol c = (ClassSymbol)t.tsym; - for (Scope.Entry e = c.members().lookup(sym.name); e.scope != null; e = e.next()) { + for (Scope.Entry e = membersOf(c).lookup(sym.name); e.scope != null; e = e.next()) { if (sym.overrides(e.sym, origin, env.types, true)) { return TypeMaker.getType(env, t); } @@ -160,7 +160,7 @@ public class MethodDocImpl t.hasTag(CLASS); t = env.types.supertype(t)) { ClassSymbol c = (ClassSymbol)t.tsym; - for (Scope.Entry e = c.members().lookup(sym.name); e.scope != null; e = e.next()) { + for (Scope.Entry e = membersOf(c).lookup(sym.name); e.scope != null; e = e.next()) { if (sym.overrides(e.sym, origin, env.types, true)) { return env.getMethodDoc((MethodSymbol)e.sym); } @@ -169,6 +169,19 @@ public class MethodDocImpl return null; } + /**Retrieve members of c, ignoring any CompletionFailures that occur. */ + private Scope membersOf(ClassSymbol c) { + try { + return c.members(); + } catch (CompletionFailure cf) { + /* Quietly ignore completion failures and try again - the type + * for which the CompletionFailure was thrown shouldn't be completed + * again by the completer that threw the CompletionFailure. + */ + return membersOf(c); + } + } + /** * Tests whether this method overrides another. * The overridden method may be one declared in a superclass or diff --git a/src/share/classes/com/sun/tools/javadoc/TypeMaker.java b/src/share/classes/com/sun/tools/javadoc/TypeMaker.java index de4d54a6..5fc23819 100644 --- a/src/share/classes/com/sun/tools/javadoc/TypeMaker.java +++ b/src/share/classes/com/sun/tools/javadoc/TypeMaker.java @@ -28,6 +28,7 @@ package com.sun.tools.javadoc; import com.sun.javadoc.*; import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol.ClassSymbol; +import com.sun.tools.javac.code.Symbol.CompletionFailure; import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Type.ArrayType; import com.sun.tools.javac.code.Type.ClassType; @@ -56,9 +57,22 @@ public class TypeMaker { return getType(env, t, errorToClassDoc, true); } - @SuppressWarnings("fallthrough") public static com.sun.javadoc.Type getType(DocEnv env, Type t, boolean errToClassDoc, boolean considerAnnotations) { + try { + return getTypeImpl(env, t, errToClassDoc, considerAnnotations); + } catch (CompletionFailure cf) { + /* Quietly ignore completion failures and try again - the type + * for which the CompletionFailure was thrown shouldn't be completed + * again by the completer that threw the CompletionFailure. + */ + return getType(env, t, errToClassDoc, considerAnnotations); + } + } + + @SuppressWarnings("fallthrough") + private static com.sun.javadoc.Type getTypeImpl(DocEnv env, Type t, + boolean errToClassDoc, boolean considerAnnotations) { if (env.legacyDoclet) { t = env.types.erasure(t); } diff --git a/src/share/classes/com/sun/tools/jdeps/Analyzer.java b/src/share/classes/com/sun/tools/jdeps/Analyzer.java index afaa38e8..31d3ea60 100644 --- a/src/share/classes/com/sun/tools/jdeps/Analyzer.java +++ b/src/share/classes/com/sun/tools/jdeps/Analyzer.java @@ -223,7 +223,7 @@ public class Analyzer { Archive targetArchive = findArchive(t); if (filter.accepts(o, archive, t, targetArchive)) { addDep(o, t); - if (!requires.contains(targetArchive)) { + if (archive != targetArchive && !requires.contains(targetArchive)) { requires.add(targetArchive); } } diff --git a/src/share/classes/com/sun/tools/jdeps/JdepsTask.java b/src/share/classes/com/sun/tools/jdeps/JdepsTask.java index e75e9c76..2c72d57e 100644 --- a/src/share/classes/com/sun/tools/jdeps/JdepsTask.java +++ b/src/share/classes/com/sun/tools/jdeps/JdepsTask.java @@ -489,9 +489,11 @@ class JdepsTask { List<Archive> archives = new ArrayList<>(); Deque<String> roots = new LinkedList<>(); + List<Path> paths = new ArrayList<>(); for (String s : classes) { Path p = Paths.get(s); if (Files.exists(p)) { + paths.add(p); archives.add(Archive.getInstance(p)); } else { if (isValidClassName(s)) { @@ -504,7 +506,7 @@ class JdepsTask { sourceLocations.addAll(archives); List<Archive> classpaths = new ArrayList<>(); // for class file lookup - classpaths.addAll(getClassPathArchives(options.classpath)); + classpaths.addAll(getClassPathArchives(options.classpath, paths)); if (options.includePattern != null) { archives.addAll(classpaths); } @@ -545,6 +547,9 @@ class JdepsTask { deque.add(cn); } a.addClass(d.getOrigin(), d.getTarget()); + } else { + // ensure that the parsed class is added the archive + a.addClass(d.getOrigin()); } } for (String name : a.reader().skippedEntries()) { @@ -592,6 +597,9 @@ class JdepsTask { if (!doneClasses.contains(cn) && !deque.contains(cn)) { deque.add(cn); } + } else { + // ensure that the parsed class is added the archive + a.addClass(d.getOrigin()); } } } @@ -743,36 +751,52 @@ class JdepsTask { } } - private List<Archive> getClassPathArchives(String paths) throws IOException { + /* + * Returns the list of Archive specified in cpaths and not included + * initialArchives + */ + private List<Archive> getClassPathArchives(String cpaths, List<Path> initialArchives) + throws IOException + { List<Archive> result = new ArrayList<>(); - if (paths.isEmpty()) { + if (cpaths.isEmpty()) { return result; } - for (String p : paths.split(File.pathSeparator)) { + + List<Path> paths = new ArrayList<>(); + for (String p : cpaths.split(File.pathSeparator)) { if (p.length() > 0) { - List<Path> files = new ArrayList<>(); // wildcard to parse all JAR files e.g. -classpath dir/* int i = p.lastIndexOf(".*"); if (i > 0) { Path dir = Paths.get(p.substring(0, i)); try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "*.jar")) { for (Path entry : stream) { - files.add(entry); + paths.add(entry); } } } else { - files.add(Paths.get(p)); - } - for (Path f : files) { - if (Files.exists(f)) { - result.add(Archive.getInstance(f)); - } + paths.add(Paths.get(p)); } } } + for (Path p : paths) { + if (Files.exists(p) && !hasSameFile(initialArchives, p)) { + result.add(Archive.getInstance(p)); + } + } return result; } + private boolean hasSameFile(List<Path> paths, Path p2) throws IOException { + for (Path p1 : paths) { + if (Files.isSameFile(p1, p2)) { + return true; + } + } + return false; + } + class RawOutputFormatter implements Analyzer.Visitor { private final PrintWriter writer; private String pkg = ""; diff --git a/src/share/classes/com/sun/tools/jdeps/PlatformClassPath.java b/src/share/classes/com/sun/tools/jdeps/PlatformClassPath.java index 115f87e3..9fd075c6 100644 --- a/src/share/classes/com/sun/tools/jdeps/PlatformClassPath.java +++ b/src/share/classes/com/sun/tools/jdeps/PlatformClassPath.java @@ -46,7 +46,7 @@ import static com.sun.tools.classfile.Attribute.*; */ class PlatformClassPath { private static final List<String> NON_PLATFORM_JARFILES = - Arrays.asList("alt-rt.jar", "jfxrt.jar", "ant-javafx.jar", "javafx-mx.jar"); + Arrays.asList("alt-rt.jar", "ant-javafx.jar", "javafx-mx.jar"); private static final List<Archive> javaHomeArchives = init(); static List<Archive> getArchives() { @@ -124,6 +124,14 @@ class PlatformClassPath { */ static class JDKArchive extends Archive { private static List<String> PROFILE_JARS = Arrays.asList("rt.jar", "jce.jar"); + // Workaround: The following packages are not annotated as jdk.Exported + private static List<String> EXPORTED_PACKAGES = Arrays.asList( + "javax.jnlp", + "org.w3c.dom.css", + "org.w3c.dom.html", + "org.w3c.dom.stylesheets", + "org.w3c.dom.xpath" + ); public static boolean isProfileArchive(Archive archive) { if (archive instanceof JDKArchive) { return PROFILE_JARS.contains(archive.getName()); @@ -155,7 +163,11 @@ class PlatformClassPath { * Tests if a given package name is exported. */ public boolean isExportedPackage(String pn) { - if (Profile.getProfile(pn) != null || "javax.jnlp".equals(pn)) { + if (Profile.getProfile(pn) != null) { + return true; + } + // special case for JavaFX and APIs that are not annotated with @jdk.Exported) + if (EXPORTED_PACKAGES.contains(pn) || pn.startsWith("javafx.")) { return true; } return exportedPackages.containsKey(pn) ? exportedPackages.get(pn) : false; diff --git a/test/Makefile b/test/Makefile index 11fb171e..2238b291 100644 --- a/test/Makefile +++ b/test/Makefile @@ -21,7 +21,6 @@ OSNAME = $(shell uname -s) ifeq ($(OSNAME), SunOS) SLASH_JAVA = /java PLATFORM = solaris - JT_PLATFORM = solaris ARCH = $(shell uname -p) ifeq ($(ARCH), i386) ARCH=i586 @@ -30,7 +29,6 @@ endif ifeq ($(OSNAME), Linux) SLASH_JAVA = /java PLATFORM = linux - JT_PLATFORM = linux ARCH = $(shell uname -m) ifeq ($(ARCH), i386) ARCH=i586 @@ -38,7 +36,6 @@ ifeq ($(OSNAME), Linux) endif ifeq ($(OSNAME), Darwin) PLATFORM = bsd - JT_PLATFORM = linux ARCH = $(shell uname -m) ifeq ($(ARCH), i386) ARCH=i586 @@ -55,7 +52,6 @@ endif ifeq ($(PLATFORM), windows) SLASH_JAVA = J: - JT_PLATFORM = win32 ifeq ($(word 1, $(PROCESSOR_IDENTIFIER)),ia64) ARCH=ia64 else @@ -93,8 +89,8 @@ ifdef JPRT_JTREG_HOME else JTREG_HOME = $(SLASH_JAVA)/re/jtreg/4.1/promoted/latest/binaries/jtreg endif -JTREG = $(JTREG_HOME)/$(JT_PLATFORM)/bin/jtreg -JTDIFF = $(JTREG_HOME)/$(JT_PLATFORM)/bin/jtdiff +JTREG = $(JTREG_HOME)/bin/jtreg +JTDIFF = $(JTREG_HOME)/bin/jtdiff # Default JCK to run ifdef JPRT_JCK_HOME diff --git a/test/com/sun/javadoc/testStylesheet/TestStylesheet.java b/test/com/sun/javadoc/testStylesheet/TestStylesheet.java index 975a3f69..e5a70469 100644 --- a/test/com/sun/javadoc/testStylesheet/TestStylesheet.java +++ b/test/com/sun/javadoc/testStylesheet/TestStylesheet.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 4494033 7028815 7052425 8007338 8023608 8008164 8016549 + * @bug 4494033 7028815 7052425 8007338 8023608 8008164 8016549 8072461 * @summary Run tests on doclet stylesheet. * @author jamieh * @library ../lib/ @@ -34,7 +34,7 @@ public class TestStylesheet extends JavadocTester { //Test information. - private static final String BUG_ID = "4494033-7028815-7052425-8007338"; + private static final String BUG_ID = "4494033-7028815-7052425-8007338-8072461"; //Javadoc arguments. private static final String[] ARGS = new String[] { @@ -123,6 +123,23 @@ public class TestStylesheet extends JavadocTester { "}"}, {BUG_ID + FS + "stylesheet.css", "@import url('resources/fonts/dejavu.css');"}, + // Test the formatting styles for proper content display in use and constant values pages. + {BUG_ID + FS + "stylesheet.css", + ".overviewSummary td.colFirst, .overviewSummary th.colFirst," + NL + + ".useSummary td.colFirst, .useSummary th.colFirst," + NL + + ".overviewSummary td.colOne, .overviewSummary th.colOne," + NL + + ".memberSummary td.colFirst, .memberSummary th.colFirst," + NL + + ".memberSummary td.colOne, .memberSummary th.colOne," + NL + + ".typeSummary td.colFirst{" + NL + + " width:25%;" + NL + + " vertical-align:top;" + NL + + "}"}, + {BUG_ID + FS + "stylesheet.css", + ".overviewSummary td, .memberSummary td, .typeSummary td," + NL + + ".useSummary td, .constantsSummary td, .deprecatedSummary td {" + NL + + " text-align:left;" + NL + + " padding:0px 0px 12px 10px;" + NL + + "}"}, // Test whether a link to the stylesheet file is inserted properly // in the class documentation. {BUG_ID + FS + "pkg" + FS + "A.html", diff --git a/test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java b/test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java index 2e26cf6b..03376adc 100644 --- a/test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java +++ b/test/tools/javac/7153958/CPoolRefClassContainingInlinedCts.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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,9 +25,9 @@ /* * @test - * @bug 7153958 + * @bug 7153958 8073372 * @summary add constant pool reference to class containing inlined constants - * @compile pkg/ClassToBeStaticallyImported.java CPoolRefClassContainingInlinedCts.java + * @compile pkg/ClassToBeStaticallyImportedA.java pkg/ClassToBeStaticallyImportedB.java CPoolRefClassContainingInlinedCts.java * @run main CPoolRefClassContainingInlinedCts */ @@ -38,7 +38,8 @@ import com.sun.tools.classfile.ConstantPoolException; import java.io.File; import java.io.IOException; -import static pkg.ClassToBeStaticallyImported.staticField; +import static pkg.ClassToBeStaticallyImportedA.staticFieldA; +import static pkg.ClassToBeStaticallyImportedB.staticFieldB; public class CPoolRefClassContainingInlinedCts { @@ -54,10 +55,14 @@ public class CPoolRefClassContainingInlinedCts { void checkClassName(String className) { switch (className) { - case "SimpleAssignClass" : case "BinaryExpClass": - case "UnaryExpClass" : case "CastClass": - case "ParensClass" : case "CondClass": - case "IfClass" : case "pkg/ClassToBeStaticallyImported": + case "SimpleAssignClassA" : case "BinaryExpClassA": + case "UnaryExpClassA" : case "CastClassA": + case "ParensClassA" : case "CondClassA": + case "IfClassA" : case "pkg/ClassToBeStaticallyImportedA": + case "SimpleAssignClassB" : case "BinaryExpClassB": + case "UnaryExpClassB" : case "CastClassB": + case "ParensClassB" : case "CondClassB": + case "IfClassB" : case "pkg/ClassToBeStaticallyImportedB": numberOfReferencedClassesToBeChecked++; } } @@ -76,59 +81,111 @@ public class CPoolRefClassContainingInlinedCts { } i += cpInfo.size(); } - if (numberOfReferencedClassesToBeChecked != 8) { + if (numberOfReferencedClassesToBeChecked != 16) { throw new AssertionError("Class reference missing in the constant pool"); } } - private int assign = SimpleAssignClass.x; - private int binary = BinaryExpClass.x + 1; - private int unary = -UnaryExpClass.x; - private int cast = (int)CastClass.x; - private int parens = (ParensClass.x); - private int cond = (CondClass.x == 1) ? 1 : 2; - private static int ifConstant; - private static int importStatic; + private int assignA = SimpleAssignClassA.x; + private int binaryA = BinaryExpClassA.x + 1; + private int unaryA = -UnaryExpClassA.x; + private int castA = (int)CastClassA.x; + private int parensA = (ParensClassA.x); + private int condA = (CondClassA.x == 1) ? 1 : 2; + private static int ifConstantA; + private static int importStaticA; static { - if (IfClass.x == 1) { - ifConstant = 1; + if (IfClassA.x == 1) { + ifConstantA = 1; } else { - ifConstant = 2; + ifConstantA = 2; } } static { - if (staticField == 1) { - importStatic = 1; + if (staticFieldA == 1) { + importStaticA = 1; } else { - importStatic = 2; + importStaticA = 2; } } + + // now as final constants + private static final int assignB = SimpleAssignClassB.x; + private static final int binaryB = BinaryExpClassB.x + 1; + private static final int unaryB = -UnaryExpClassB.x; + private static final int castB = (int)CastClassB.x; + private static final int parensB = (ParensClassB.x); + private static final int condB = (CondClassB.x == 1) ? 1 : 2; + private static final int ifConstantB; + private static final int importStaticB; + static { + if (IfClassB.x == 1) { + ifConstantB = 1; + } else { + ifConstantB = 2; + } + } + static { + if (staticFieldB == 1) { + importStaticB = 1; + } else { + importStaticB = 2; + } + } +} + +class SimpleAssignClassA { + public static final int x = 1; +} + +class SimpleAssignClassB { + public static final int x = 1; +} + +class BinaryExpClassA { + public static final int x = 1; +} + +class BinaryExpClassB { + public static final int x = 1; +} + +class UnaryExpClassA { + public static final int x = 1; +} + +class UnaryExpClassB { + public static final int x = 1; +} + +class CastClassA { + public static final int x = 1; } -class SimpleAssignClass { +class CastClassB { public static final int x = 1; } -class BinaryExpClass { +class ParensClassA { public static final int x = 1; } -class UnaryExpClass { +class ParensClassB { public static final int x = 1; } -class CastClass { +class CondClassA { public static final int x = 1; } -class ParensClass { +class CondClassB { public static final int x = 1; } -class CondClass { +class IfClassA { public static final int x = 1; } -class IfClass { +class IfClassB { public static final int x = 1; } diff --git a/test/tools/javac/7153958/pkg/ClassToBeStaticallyImported.java b/test/tools/javac/7153958/pkg/ClassToBeStaticallyImportedA.java index 801098d0..b8fb39f4 100644 --- a/test/tools/javac/7153958/pkg/ClassToBeStaticallyImported.java +++ b/test/tools/javac/7153958/pkg/ClassToBeStaticallyImportedA.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2015, 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 @@ -24,6 +24,6 @@ */ package pkg; -public class ClassToBeStaticallyImported { - public static final int staticField = 1; +public class ClassToBeStaticallyImportedA { + public static final int staticFieldA = 1; } diff --git a/test/tools/javac/7153958/pkg/ClassToBeStaticallyImportedB.java b/test/tools/javac/7153958/pkg/ClassToBeStaticallyImportedB.java new file mode 100644 index 00000000..d05c6fba --- /dev/null +++ b/test/tools/javac/7153958/pkg/ClassToBeStaticallyImportedB.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2012, 2015, 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 pkg; + +public class ClassToBeStaticallyImportedB { + public static final int staticFieldB = 1; +} diff --git a/test/tools/javac/MethodParameters/ClassFileVisitor.java b/test/tools/javac/MethodParameters/ClassFileVisitor.java index 616d7f40..61c5e567 100644 --- a/test/tools/javac/MethodParameters/ClassFileVisitor.java +++ b/test/tools/javac/MethodParameters/ClassFileVisitor.java @@ -147,6 +147,7 @@ class ClassFileVisitor extends Tester.Visitor { public int mAttrs; public int mNumParams; public boolean mSynthetic; + public boolean mIsLambda; public boolean mIsConstructor; public boolean mIsClinit; public boolean mIsBridge; @@ -165,6 +166,7 @@ class ClassFileVisitor extends Tester.Visitor { mIsClinit = mName.equals("<clinit>"); prefix = cname + "." + mName + "() - "; mIsBridge = method.access_flags.is(AccessFlags.ACC_BRIDGE); + mIsLambda = mSynthetic && mName.startsWith("lambda$"); if (mIsClinit) { sb = new StringBuilder(); // Discard output @@ -225,7 +227,7 @@ class ClassFileVisitor extends Tester.Visitor { // IMPL: Whether MethodParameters attributes will be generated // for some synthetics is unresolved. For now, assume no. - if (mSynthetic) { + if (mSynthetic && !mIsLambda) { warn(prefix + "synthetic has MethodParameter attribute"); } @@ -349,10 +351,12 @@ class ClassFileVisitor extends Tester.Visitor { } else if (isEnum && mNumParams == 1 && index == 0 && mName.equals("valueOf")) { expect = "name"; allowMandated = true; - } else if (mIsBridge) { + } else if (mIsBridge || mIsLambda) { allowSynthetic = true; /* you can't expect an special name for bridges' parameters. - * The name of the original parameters are now copied. + * The name of the original parameters are now copied. Likewise + * for a method encoding the lambda expression, names are derived + * from source lambda's parameters and captured enclosing locals. */ expect = null; } diff --git a/test/tools/javac/MethodParameters/LambdaTest.java b/test/tools/javac/MethodParameters/LambdaTest.java index d7156824..b12d9cbf 100644 --- a/test/tools/javac/MethodParameters/LambdaTest.java +++ b/test/tools/javac/MethodParameters/LambdaTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 8006582 + * @bug 8006582 8037546 * @summary javac should generate method parameters correctly. * @build Tester * @compile -parameters LambdaTest.java @@ -31,8 +31,8 @@ */ /** - * Parameter names are not recorded for lambdas. This test verifies - * that there are no MethodParameters attribute for lambdas. + * Post https://bugs.openjdk.java.net/browse/JDK-8037546, this test verifies + * that MethodParameters attribute for lambdas are emitted properly. */ class LambdaTest { diff --git a/test/tools/javac/MethodParameters/LambdaTest.out b/test/tools/javac/MethodParameters/LambdaTest.out index da662e11..d8367934 100644 --- a/test/tools/javac/MethodParameters/LambdaTest.out +++ b/test/tools/javac/MethodParameters/LambdaTest.out @@ -1,7 +1,7 @@ class LambdaTest -- LambdaTest.<init>() LambdaTest.foo(i) -LambdaTest.lambda$static$1(arg0)/*synthetic*/ -LambdaTest.lambda$null$0(arg0, arg1)/*synthetic*/ +LambdaTest.lambda$static$1(x1/*synthetic*/)/*synthetic*/ +LambdaTest.lambda$null$0(final x1/*synthetic*/, x2/*synthetic*/)/*synthetic*/ static interface LambdaTest$I -- inner LambdaTest$I.m(x) diff --git a/test/tools/javac/MethodParameters/ReflectionVisitor.java b/test/tools/javac/MethodParameters/ReflectionVisitor.java index 8102854d..9441b216 100644 --- a/test/tools/javac/MethodParameters/ReflectionVisitor.java +++ b/test/tools/javac/MethodParameters/ReflectionVisitor.java @@ -277,7 +277,7 @@ public class ReflectionVisitor extends Tester.Visitor { param = "final " + param; } sb.append(sep).append(param); - if (!m.isBridge() && !expect.equals(param)) { + if (!m.isBridge() && !m.getName().startsWith("lambda$") && !expect.equals(param)) { error(prefix + "param[" + i + "]='" + param + "' expected '" + expect + "'"); break; diff --git a/test/tools/javac/annotations/6214965/T6214965.java b/test/tools/javac/annotations/6214965/T6214965.java index cdac2431..119c8978 100644 --- a/test/tools/javac/annotations/6214965/T6214965.java +++ b/test/tools/javac/annotations/6214965/T6214965.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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,9 +23,10 @@ /** * @test - * @bug 6214965 6365854 + * @bug 6214965 6365854 8068639 * @summary Compiler crash on redefing nested annotation types * @compile CompilerAnnotationTest.java CompilerAnnotationTest2.java * @compile CompilerAnnotationTest2bad.java - * @compile/ref=T6214965.out -XDrawDiagnostics CompilerAnnotationTest2bad.java + * @compile/ref=T6214965.out -XDrawDiagnostics -Xlint:classfile CompilerAnnotationTest2bad.java + * @compile -Werror CompilerAnnotationTest2bad.java */ diff --git a/test/tools/javac/annotations/6365854/T6365854.java b/test/tools/javac/annotations/6365854/T6365854.java index daa24f65..d056368f 100644 --- a/test/tools/javac/annotations/6365854/T6365854.java +++ b/test/tools/javac/annotations/6365854/T6365854.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 2015, 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 6365854 + * @bug 6365854 8068639 * @summary javac crashes when compiling against an annotated class * @compile TestAnnotation.java TestCore.java * @clean test.annotation.TestAnnotation @@ -33,11 +33,11 @@ * * @compile TestAnnotation.java TestCore.java * @clean test.annotation.TestAnnotation - * @compile/ref=test1.out -XDrawDiagnostics T6365854.java + * @compile/ref=test1.out -XDrawDiagnostics -Xlint:classfile T6365854.java * @run main T6365854 - * @compile/ref=test2.out -XDrawDiagnostics evolve/TestAnnotation.java T6365854.java + * @compile/ref=test2.out -XDrawDiagnostics -Xlint:classfile evolve/TestAnnotation.java T6365854.java * @run main T6365854 - * @compile/ref=test2.out -XDrawDiagnostics T6365854.java + * @compile/ref=test2.out -XDrawDiagnostics -Xlint:classfile T6365854.java * @run main T6365854 */ diff --git a/test/tools/javac/annotations/neg/AnonSubclass.java b/test/tools/javac/annotations/neg/AnonSubclass.java new file mode 100644 index 00000000..655a5716 --- /dev/null +++ b/test/tools/javac/annotations/neg/AnonSubclass.java @@ -0,0 +1,13 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8028389 + * @summary javac should output a proper error message when given something + * like new Object(){} as annotation argument. + * + * @compile/fail/ref=AnonSubclass.out -XDrawDiagnostics AnonSubclass.java + */ + +@AnonSubclass(new Object(){}) +@interface AnonSubclass { + String value(); +} diff --git a/test/tools/javac/annotations/neg/AnonSubclass.out b/test/tools/javac/annotations/neg/AnonSubclass.out new file mode 100644 index 00000000..48984a89 --- /dev/null +++ b/test/tools/javac/annotations/neg/AnonSubclass.out @@ -0,0 +1,2 @@ +AnonSubclass.java:10:15: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.anonymous.class: java.lang.Object, java.lang.String) +1 error diff --git a/test/tools/javac/annotations/neg/pkg/AnonSubclassOnPkg.java b/test/tools/javac/annotations/neg/pkg/AnonSubclassOnPkg.java new file mode 100644 index 00000000..e04135c4 --- /dev/null +++ b/test/tools/javac/annotations/neg/pkg/AnonSubclassOnPkg.java @@ -0,0 +1,28 @@ +/* + * 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 pkg; + +@interface AnonSubclassOnPkg { + String value(); +} diff --git a/test/tools/javac/annotations/neg/pkg/package-info.java b/test/tools/javac/annotations/neg/pkg/package-info.java new file mode 100644 index 00000000..7b8c2c5e --- /dev/null +++ b/test/tools/javac/annotations/neg/pkg/package-info.java @@ -0,0 +1,12 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8028389 + * @summary javac should output a proper error message when given something + * like new Object(){} as annotation argument. + * + * @compile AnonSubclassOnPkg.java + * @compile/fail/ref=package-info.out -XDrawDiagnostics package-info.java + */ + +@AnonSubclassOnPkg(new Object(){}) +package pkg; diff --git a/test/tools/javac/annotations/neg/pkg/package-info.out b/test/tools/javac/annotations/neg/pkg/package-info.out new file mode 100644 index 00000000..11c16e59 --- /dev/null +++ b/test/tools/javac/annotations/neg/pkg/package-info.out @@ -0,0 +1,2 @@ +package-info.java:11:20: compiler.err.prob.found.req: (compiler.misc.inconvertible.types: compiler.misc.anonymous.class: java.lang.Object, java.lang.String) +1 error diff --git a/test/tools/javac/annotations/typeAnnotations/classfile/TestAnonInnerClasses.java b/test/tools/javac/annotations/typeAnnotations/classfile/TestAnonInnerClasses.java index 0ce59a87..1bffe5a8 100644 --- a/test/tools/javac/annotations/typeAnnotations/classfile/TestAnonInnerClasses.java +++ b/test/tools/javac/annotations/typeAnnotations/classfile/TestAnonInnerClasses.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. + * 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 diff --git a/test/tools/javac/classfiles/InnerClasses/T8068517.java b/test/tools/javac/classfiles/InnerClasses/T8068517.java new file mode 100644 index 00000000..d9bbca9c --- /dev/null +++ b/test/tools/javac/classfiles/InnerClasses/T8068517.java @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2015, 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 8068517 + * @summary Verify that nested enums have correct abstract flag in the InnerClasses attribute. + * @library /tools/javac/lib + * @build ToolBox T8068517 + * @run main T8068517 + */ + +import com.sun.tools.javac.util.Assert; +import java.io.File; +import java.nio.file.Files; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import javax.tools.JavaCompiler; +import javax.tools.ToolProvider; + +public class T8068517 { + + public static void main(String[] args) throws Exception { + new T8068517().run(); + } + + void run() throws Exception { + runTest("class A {\n" + + " enum AInner implements Runnable {\n" + + " A {\n" + + " public void run() {}\n" + + " };\n" + + " }\n" + + "}\n", + "class B {\n" + + " A.AInner a;\n" + + "}"); + runTest("class A {\n" + + " enum AInner implements Runnable {\n" + + " A {\n" + + " public void run() {}\n" + + " };\n" + + " }\n" + + " AInner aInner;\n" + + "}\n", + "class B {\n" + + " void test(A a) {;\n" + + " switch (a.aInner) {\n" + + " case A: break;\n" + + " }\n" + + " };\n" + + "}"); + runTest("class A {\n" + + " enum AInner implements Runnable {\n" + + " A {\n" + + " public void run() {}\n" + + " };\n" + + " }\n" + + " AInner aInner;\n" + + "}\n", + "class B {\n" + + " void test(A a) {;\n" + + " System.err.println(a.aInner.toString());\n" + + " };\n" + + "}"); + runTest("class A {\n" + + " enum AInner implements Runnable {\n" + + " A {\n" + + " public void run() {}\n" + + " };\n" + + " }\n" + + " AInner aInner() {\n" + + " return null;\n" + + " }\n" + + "}\n", + "class B {\n" + + " void test(A a) {;\n" + + " System.err.println(a.aInner().toString());\n" + + " };\n" + + "}"); + } + + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + int testN = 0; + + void runTest(String aJava, String bJava) throws Exception { + File testClasses = new File(System.getProperty("test.classes")); + File target1 = new File(testClasses, "T8068517s" + testN++); + doCompile(target1, aJava, bJava); + File target2 = new File(testClasses, "T8068517s" + testN++); + doCompile(target2, bJava, aJava); + + Assert.check(Arrays.equals(Files.readAllBytes(new File(target1, "B.class").toPath()), + Files.readAllBytes(new File(target2, "B.class").toPath()))); + } + + void doCompile(File target, String... sources) throws Exception { + target.mkdirs(); + List<String> options = Arrays.asList("-d", target.getAbsolutePath()); + List<ToolBox.JavaSource> files = Stream.of(sources) + .map(ToolBox.JavaSource::new) + .collect(Collectors.toList()); + compiler.getTask(null, null, null, options, null, files).call(); + } +} diff --git a/test/tools/javac/diags/DiagnosticRewriterTest.java b/test/tools/javac/diags/DiagnosticRewriterTest.java new file mode 100644 index 00000000..867153f1 --- /dev/null +++ b/test/tools/javac/diags/DiagnosticRewriterTest.java @@ -0,0 +1,18 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8145466 8146533 + * @summary javac: No line numbers in compilation error + * @compile/fail/ref=DiagnosticRewriterTest.out -Xdiags:compact -XDrawDiagnostics DiagnosticRewriterTest.java + */ + +class DiagnosticRewriterTest { + void test() { + new Object() { + void g() { + m(2L); + } + }; + } + + void m(int i) { } +} diff --git a/test/tools/javac/diags/DiagnosticRewriterTest.out b/test/tools/javac/diags/DiagnosticRewriterTest.out new file mode 100644 index 00000000..f66d9663 --- /dev/null +++ b/test/tools/javac/diags/DiagnosticRewriterTest.out @@ -0,0 +1,3 @@ +DiagnosticRewriterTest.java:12:15: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: long, int) +- compiler.note.compressed.diags +1 error diff --git a/test/tools/javac/diags/DiagnosticRewriterTest2.java b/test/tools/javac/diags/DiagnosticRewriterTest2.java new file mode 100644 index 00000000..26ec2fc9 --- /dev/null +++ b/test/tools/javac/diags/DiagnosticRewriterTest2.java @@ -0,0 +1,22 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8145466 8146533 + * @summary javac: No line numbers in compilation error + * @compile/fail/ref=DiagnosticRewriterTest2.out -Xdiags:compact -XDrawDiagnostics DiagnosticRewriterTest2.java + */ + +class DiagnosticRewriterTest2 { + class Bar { + Bar(Object o) { } + } + void test() { + new Bar(null) { + void g() { + m(2L); + m(); + } + }; + } + + void m(int i) { } +} diff --git a/test/tools/javac/diags/DiagnosticRewriterTest2.out b/test/tools/javac/diags/DiagnosticRewriterTest2.out new file mode 100644 index 00000000..3076a6b7 --- /dev/null +++ b/test/tools/javac/diags/DiagnosticRewriterTest2.out @@ -0,0 +1,4 @@ +DiagnosticRewriterTest2.java:15:15: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: long, int) +DiagnosticRewriterTest2.java:16:13: compiler.err.cant.apply.symbol: kindname.method, m, int, compiler.misc.no.args, kindname.class, DiagnosticRewriterTest2, (compiler.misc.arg.length.mismatch) +- compiler.note.compressed.diags +2 errors diff --git a/test/tools/javac/diags/examples/MrefInferAndExplicitParams.java b/test/tools/javac/diags/examples/MrefInferAndExplicitParams.java index ce24f82e..a67a34ed 100644 --- a/test/tools/javac/diags/examples/MrefInferAndExplicitParams.java +++ b/test/tools/javac/diags/examples/MrefInferAndExplicitParams.java @@ -8,7 +8,7 @@ * * 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 + * 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). * diff --git a/test/tools/javac/enum/8069181/T8069181.java b/test/tools/javac/enum/8069181/T8069181.java new file mode 100644 index 00000000..4e4033dd --- /dev/null +++ b/test/tools/javac/enum/8069181/T8069181.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2015, 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. + */ + +/* + * @test + * @bug 8069181 + * @summary java.lang.AssertionError when compiling JDK 1.4 code in JDK 8 + * + * @compile -source 1.4 T8069181.java + */ +import java.util.Enumeration; +import java.util.Hashtable; +class T8069181 { + void test() { + Hashtable hTable = new Hashtable(); + hTable.put("hello", "value"); + for (Enumeration enum = hTable.keys();;){ + if(!enum.hasMoreElements()) + break; + enum.nextElement(); + } + } +} diff --git a/test/tools/javac/expression/DeeplyChainedNonPolyExpressionTest.java b/test/tools/javac/expression/DeeplyChainedNonPolyExpressionTest.java new file mode 100644 index 00000000..cc6a9efd --- /dev/null +++ b/test/tools/javac/expression/DeeplyChainedNonPolyExpressionTest.java @@ -0,0 +1,178 @@ +/* + * Copyright (c) 2015, 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 8079613 + * @summary Ensure that compiler ascertains a class of patently non-poly expressions as such + * @run main/timeout=10 DeeplyChainedNonPolyExpressionTest + */ + +public class DeeplyChainedNonPolyExpressionTest { + static class JSO { + + JSO put(String s, Object y) { + return null; + } + + JSO put(java.lang.String x, java.util.Collection<String> y) { + return null; + } + + JSO put(java.lang.String x, int y) { + return null; + } + + JSO put(java.lang.String x, long y) { + return null; + } + + JSO put(java.lang.String x, double y) { + return null; + } + + JSO put(java.lang.String x, java.util.Map<String, String> y) { + return null; + } + + JSO put(java.lang.String x, boolean y) { + return null; + } + } + + static class JSA { + + JSA put(Object o) { + return null; + } + + JSA put(int i, Object x) { + return null; + } + + JSA put(boolean x) { + return null; + } + + JSA put(int x) { + return null; + } + + JSA put(int i, int x) { + return null; + } + + JSA put(int x, boolean y) { + return null; + } + + JSA put(int i, long x) { + return null; + } + + JSA put(long x) { + return null; + } + + JSA put(java.util.Collection<String> x) { + return null; + } + + JSA put(int i, java.util.Collection<String> x) { + return null; + } + + JSA put(int i, java.util.Map<String, String> x) { + return null; + } + + JSA put(java.util.Map<String, String> x) { + return null; + } + + JSA put(int i, double x) { + return null; + } + + JSA put(double x) { + return null; + } + } + + public static void main(String [] args) { + } + public static void foo() { + new JSO() + .put("s", new JSA()) + .put("s", new JSA()) + .put("s", new JSO() + .put("s", new JSO() + .put("s", new JSA().put("s")) + .put("s", new JSA()) + .put("s", new JSO() + .put("s", new JSO() + .put("s", new JSA().put("s").put("s")) + .put("s", new JSA()) + .put("s", new JSO() + .put("s", new JSO() + .put("s", new JSA().put("s").put("s").put("s") + .put("s").put("s").put("s") + .put("s").put("s")) + .put("s", new JSA()) + .put("s", new JSO() + .put("s", new JSO() + .put("s", new JSA().put("s")) + .put("s", new JSA()) + ) + ) + ) + ) + ) + .put("s", new JSO() + .put("s", new JSA().put("s")) + .put("s", new JSA()) + .put("s", new JSO() + .put("s", new JSO() + .put("s", new JSA().put("s").put("s")) + .put("s", new JSA()) + .put("s", new JSO() + .put("s", new JSO() + .put("s", new JSA().put("s").put("s").put("s") + .put("s").put("s").put("s") + .put("s").put("s")) + .put("s", new JSA()) + .put("s", new JSO() + .put("s", new JSO() + .put("s", new JSA().put("s")) + .put("s", new JSA())) + ) + ) + ) + ) + ) + ) + ) + ) + ); + } +} diff --git a/test/tools/javac/flow/LVTHarness.java b/test/tools/javac/flow/LVTHarness.java index 33ab0441..921480c7 100644 --- a/test/tools/javac/flow/LVTHarness.java +++ b/test/tools/javac/flow/LVTHarness.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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 7047734 8027660 8037937 8047719 8058708 + * @bug 7047734 8027660 8037937 8047719 8058708 8064857 * @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 @@ -144,7 +144,7 @@ public class LVTHarness { } void checkMethod(ConstantPool constantPool, Method method, AliveRanges ranges) - throws InvalidIndex, UnexpectedEntry { + throws InvalidIndex, UnexpectedEntry, ConstantPoolException { Code_attribute code = (Code_attribute) method.attributes.get(Attribute.Code); LocalVariableTable_attribute lvt = (LocalVariableTable_attribute) (code.attributes.get(Attribute.LocalVariableTable)); @@ -166,7 +166,7 @@ public class LVTHarness { } if (i < infoFromRanges.size()) { - error(infoFromLVT, infoFromRanges); + error(infoFromLVT, infoFromRanges, method.getName(constantPool).toString()); } } @@ -202,9 +202,10 @@ public class LVTHarness { return sb.toString(); } - protected void error(List<String> infoFromLVT, List<String> infoFromRanges) { + protected void error(List<String> infoFromLVT, List<String> infoFromRanges, String methodName) { nerrors++; System.err.printf("Error occurred while checking file: %s\n", jfo.getName()); + System.err.printf("at method: %s\n", methodName); System.err.println("The range info from the annotations is"); printStringListToErrOutput(infoFromRanges); System.err.println(); diff --git a/test/tools/javac/flow/tests/TestCaseFor.java b/test/tools/javac/flow/tests/TestCaseFor.java index 10056b88..e7564994 100644 --- a/test/tools/javac/flow/tests/TestCaseFor.java +++ b/test/tools/javac/flow/tests/TestCaseFor.java @@ -2,7 +2,7 @@ public class TestCaseFor { - @AliveRange(varName="o", bytecodeStart=10, bytecodeLength=8) + @AliveRange(varName="o", bytecodeStart=10, bytecodeLength=11) @AliveRange(varName="o", bytecodeStart=24, bytecodeLength=1) void m1(String[] args) { Object o; @@ -13,7 +13,7 @@ public class TestCaseFor { o = ""; } - @AliveRange(varName="o", bytecodeStart=10, bytecodeLength=8) + @AliveRange(varName="o", bytecodeStart=10, bytecodeLength=11) @AliveRange(varName="o", bytecodeStart=24, bytecodeLength=1) void m2(String[] args) { Object o; diff --git a/test/tools/javac/flow/tests/TestCaseForEach.java b/test/tools/javac/flow/tests/TestCaseForEach.java index 219f1180..30b0c131 100644 --- a/test/tools/javac/flow/tests/TestCaseForEach.java +++ b/test/tools/javac/flow/tests/TestCaseForEach.java @@ -2,7 +2,7 @@ public class TestCaseForEach { - @AliveRange(varName="o", bytecodeStart=25, bytecodeLength=8) + @AliveRange(varName="o", bytecodeStart=25, bytecodeLength=11) @AliveRange(varName="o", bytecodeStart=39, bytecodeLength=1) void m(String[] args) { Object o; diff --git a/test/tools/javac/flow/tests/TestCaseIfElse.java b/test/tools/javac/flow/tests/TestCaseIfElse.java index d789853b..7318e545 100644 --- a/test/tools/javac/flow/tests/TestCaseIfElse.java +++ b/test/tools/javac/flow/tests/TestCaseIfElse.java @@ -60,4 +60,19 @@ public class TestCaseIfElse { } return null; } + + @AliveRange(varName="i", bytecodeStart=6, bytecodeLength=2) + int m4(boolean flag) { + int i; + label: + { + if (flag) { + i = 1; + } else { + break label; + } + return i; + } + return -1; + } } diff --git a/test/tools/javac/flow/tests/TestCaseSwitch.java b/test/tools/javac/flow/tests/TestCaseSwitch.java index e67e1911..43ab1502 100644 --- a/test/tools/javac/flow/tests/TestCaseSwitch.java +++ b/test/tools/javac/flow/tests/TestCaseSwitch.java @@ -81,4 +81,26 @@ public class TestCaseSwitch { o = "finish"; } + @AliveRange(varName="oCache", bytecodeStart=30, bytecodeLength=6) + @AliveRange(varName="cache", bytecodeStart=41, bytecodeLength=3) + @AliveRange(varName="cache", bytecodeStart=54, bytecodeLength=2) + @AliveRange(varName="service", bytecodeStart=39, bytecodeLength=5) + Object m4(int i) { + Object cache; + switch (i) { + case 0: + Object oCache = null; + if (oCache != null) { + return oCache; + } + case 1: + Object service = null; + cache = null; + break; + default: + throw new AssertionError(""); + } + return cache; + } + } diff --git a/test/tools/javac/flow/tests/TestCaseTry.java b/test/tools/javac/flow/tests/TestCaseTry.java index e987534d..b3a3762b 100644 --- a/test/tools/javac/flow/tests/TestCaseTry.java +++ b/test/tools/javac/flow/tests/TestCaseTry.java @@ -17,7 +17,8 @@ public class TestCaseTry { } @AliveRange(varName="o", bytecodeStart=3, bytecodeLength=16) - @AliveRange(varName="o", bytecodeStart=23, bytecodeLength=23) + @AliveRange(varName="o", bytecodeStart=23, bytecodeLength=8) + @AliveRange(varName="o", bytecodeStart=35, bytecodeLength=11) void m1() { Object o; try { @@ -33,7 +34,8 @@ public class TestCaseTry { } @AliveRange(varName="o", bytecodeStart=3, bytecodeLength=16) - @AliveRange(varName="o", bytecodeStart=23, bytecodeLength=31) + @AliveRange(varName="o", bytecodeStart=23, bytecodeLength=16) + @AliveRange(varName="o", bytecodeStart=43, bytecodeLength=11) void m2() { Object o; try { @@ -51,7 +53,8 @@ public class TestCaseTry { } @AliveRange(varName="o", bytecodeStart=22, bytecodeLength=38) - @AliveRange(varName="o", bytecodeStart=103, bytecodeLength=8) + @AliveRange(varName="o", bytecodeStart=103, bytecodeLength=3) + @AliveRange(varName="o", bytecodeStart=110, bytecodeLength=1) void m3() { Object o; try (BufferedReader br = diff --git a/test/tools/javac/flow/tests/TestCaseWhile.java b/test/tools/javac/flow/tests/TestCaseWhile.java index bbe1f844..47d3f327 100644 --- a/test/tools/javac/flow/tests/TestCaseWhile.java +++ b/test/tools/javac/flow/tests/TestCaseWhile.java @@ -2,7 +2,7 @@ public class TestCaseWhile { - @AliveRange(varName="o", bytecodeStart=9, bytecodeLength=5) + @AliveRange(varName="o", bytecodeStart=9, bytecodeLength=8) @AliveRange(varName="o", bytecodeStart=20, bytecodeLength=1) void m(String[] args) { Object o; diff --git a/test/tools/javac/generics/8064803/T8064803.java b/test/tools/javac/generics/8064803/T8064803.java new file mode 100644 index 00000000..c12abf26 --- /dev/null +++ b/test/tools/javac/generics/8064803/T8064803.java @@ -0,0 +1,53 @@ +/* + * 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. + */ + +/* + * @test + * @bug 8064803 + * @summary Javac erroneously uses instantiated signatures when merging abstract most-specific methods + */ +public class T8064803 { + interface ParentA<T> { + T process() throws Exception; + } + + interface ParentB<T> { + T process() throws Exception; + } + + interface Child<T> extends ParentA<T>, ParentB<T> { } + + static class ChildImpl<T> implements Child<T> { + @Override + public T process() { + return null; + } + } + + public static void main(String[] args) throws Exception { + Child<String> child = new ChildImpl<String>(); + child.process(); + } +} diff --git a/test/tools/javac/generics/diamond/8065986/T8065986a.java b/test/tools/javac/generics/diamond/8065986/T8065986a.java new file mode 100644 index 00000000..311b276c --- /dev/null +++ b/test/tools/javac/generics/diamond/8065986/T8065986a.java @@ -0,0 +1,33 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8065986 + * + * @summary Compiler fails to NullPointerException when calling super with Object<>() + * @compile/fail/ref=T8065986a.out T8065986a.java -XDrawDiagnostics + * + */ +import java.util.ArrayList; + +class T8065986a { + T8065986a() { + super(new Object<>()); + } + + T8065986a(boolean b) { + super(new ArrayList<>()); + } + + T8065986a(boolean b1, boolean b2) { + super(()->{}); + } + + T8065986a(boolean b1, boolean b2, boolean b3) { + super(T8065986a::m); + } + + T8065986a(boolean cond, Object o1, Object o2) { + super(cond ? o1 : o2); + } + + static void m() { } +} diff --git a/test/tools/javac/generics/diamond/8065986/T8065986a.out b/test/tools/javac/generics/diamond/8065986/T8065986a.out new file mode 100644 index 00000000..cb605f43 --- /dev/null +++ b/test/tools/javac/generics/diamond/8065986/T8065986a.out @@ -0,0 +1,6 @@ +T8065986a.java:13:25: compiler.err.cant.apply.diamond.1: java.lang.Object, (compiler.misc.diamond.non.generic: java.lang.Object) +T8065986a.java:17:9: compiler.err.cant.apply.symbol: kindname.constructor, Object, compiler.misc.no.args, java.util.ArrayList<java.lang.Object>, kindname.class, java.lang.Object, (compiler.misc.arg.length.mismatch) +T8065986a.java:21:9: compiler.err.cant.apply.symbol: kindname.constructor, Object, compiler.misc.no.args, @438, kindname.class, java.lang.Object, (compiler.misc.arg.length.mismatch) +T8065986a.java:25:9: compiler.err.cant.apply.symbol: kindname.constructor, Object, compiler.misc.no.args, @520, kindname.class, java.lang.Object, (compiler.misc.arg.length.mismatch) +T8065986a.java:29:9: compiler.err.cant.apply.symbol: kindname.constructor, Object, compiler.misc.no.args, @608, kindname.class, java.lang.Object, (compiler.misc.arg.length.mismatch) +5 errors diff --git a/test/tools/javac/generics/diamond/8065986/T8065986b.java b/test/tools/javac/generics/diamond/8065986/T8065986b.java new file mode 100644 index 00000000..40a6a8b5 --- /dev/null +++ b/test/tools/javac/generics/diamond/8065986/T8065986b.java @@ -0,0 +1,33 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8065986 + * + * @summary Compiler fails to NullPointerException when calling super with Object<>() + * @compile/fail/ref=T8065986b.out T8065986b.java -XDrawDiagnostics + * + */ +import java.util.ArrayList; + +class T8065986b { + T8065986b() { + this(new Object<>()); + } + + T8065986b(boolean b) { + this(new ArrayList<>()); + } + + T8065986b(boolean b1, boolean b2) { + this(()->{}); + } + + T8065986b(boolean b1, boolean b2, boolean b3) { + this(T8065986b::m); + } + + T8065986b(boolean cond, Object o1, Object o2) { + this(cond ? o1 : o2); + } + + static void m() { } +} diff --git a/test/tools/javac/generics/diamond/8065986/T8065986b.out b/test/tools/javac/generics/diamond/8065986/T8065986b.out new file mode 100644 index 00000000..30bcfb6e --- /dev/null +++ b/test/tools/javac/generics/diamond/8065986/T8065986b.out @@ -0,0 +1,6 @@ +T8065986b.java:13:24: compiler.err.cant.apply.diamond.1: java.lang.Object, (compiler.misc.diamond.non.generic: java.lang.Object) +T8065986b.java:17:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, java.util.ArrayList<java.lang.Object>,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.cant.apply.diamond.1: (compiler.misc.diamond: java.util.ArrayList), (compiler.misc.infer.no.conforming.instance.exists: E, java.util.ArrayList<E>, boolean)))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch))} +T8065986b.java:21:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, @435,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.not.a.functional.intf: boolean))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch))} +T8065986b.java:25:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, @516,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.not.a.functional.intf: boolean))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch))} +T8065986b.java:29:9: compiler.err.cant.apply.symbols: kindname.constructor, T8065986b, @603,{(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean), (compiler.misc.no.conforming.assignment.exists: (compiler.misc.incompatible.type.in.conditional: (compiler.misc.inconvertible.types: java.lang.Object, boolean)))),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,boolean,boolean), (compiler.misc.arg.length.mismatch)),(compiler.misc.inapplicable.method: kindname.constructor, T8065986b, T8065986b(boolean,java.lang.Object,java.lang.Object), (compiler.misc.arg.length.mismatch))} +5 errors diff --git a/test/tools/javac/generics/inference/8055963/T8055963.java b/test/tools/javac/generics/inference/8055963/T8055963.java new file mode 100644 index 00000000..82f00275 --- /dev/null +++ b/test/tools/javac/generics/inference/8055963/T8055963.java @@ -0,0 +1,41 @@ +/* + * 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. + */ + +/** + * @test + * @bug 8055963 + * @summary Inference failure with nested invocation + * @compile T8055963.java + */ +class T8055963 { + + static class C<T> {} + + <T> T choose(T first, T second) { return null; } + + void test() { + C<String> cs = choose(new C<String>(), new C<>()); + } +} diff --git a/test/tools/javac/lambda/8016177/T8016177g.java b/test/tools/javac/lambda/8016177/T8016177g.java index f8660e89..d3b91005 100644 --- a/test/tools/javac/lambda/8016177/T8016177g.java +++ b/test/tools/javac/lambda/8016177/T8016177g.java @@ -1,6 +1,6 @@ /* * @test /nodynamiccopyright/ - * @bug 8016081 8016178 + * @bug 8016081 8016178 8069545 * @summary structural most specific and stuckness * @compile/fail/ref=T8016177g.out -XDrawDiagnostics T8016177g.java */ diff --git a/test/tools/javac/lambda/8016177/T8016177g.out b/test/tools/javac/lambda/8016177/T8016177g.out index beb47b0f..f10d641e 100644 --- a/test/tools/javac/lambda/8016177/T8016177g.out +++ b/test/tools/javac/lambda/8016177/T8016177g.out @@ -1,2 +1,3 @@ -T8016177g.java:35:20: compiler.err.prob.found.req: (compiler.misc.possible.loss.of.precision: double, int) -1 error +T8016177g.java:34:14: compiler.err.cant.apply.symbol: kindname.method, print, java.lang.String, Test.Person, kindname.class, Test, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.inferred.do.not.conform.to.upper.bounds: Test.Person, java.lang.String,java.lang.Object)) +T8016177g.java:35:20: compiler.err.cant.apply.symbol: kindname.method, abs, int, java.lang.Double, kindname.class, Test, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.infer.no.conforming.instance.exists: , R, int)) +2 errors diff --git a/test/tools/javac/lambda/8023389/T8023389.java b/test/tools/javac/lambda/8023389/T8023389.java index 25eb0c8a..c8f91dcc 100644 --- a/test/tools/javac/lambda/8023389/T8023389.java +++ b/test/tools/javac/lambda/8023389/T8023389.java @@ -8,7 +8,7 @@ * * 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 + * 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). * diff --git a/test/tools/javac/lambda/8066974/T8066974.java b/test/tools/javac/lambda/8066974/T8066974.java new file mode 100644 index 00000000..8f47277f --- /dev/null +++ b/test/tools/javac/lambda/8066974/T8066974.java @@ -0,0 +1,44 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8066974 + * @summary Compiler doesn't infer method's generic type information in lambda body + * @compile/fail/ref=T8066974.out -XDrawDiagnostics T8066974.java + */ +class T8066974 { + static class Throwing<E extends Throwable> { } + static class RuntimeThrowing extends Throwing<RuntimeException> { } + static class CheckedThrowing extends Throwing<Exception> { } + + interface Parameter { + <E extends Throwable> Object m(Throwing<E> tw) throws E; + } + + interface Mapper<R> { + R m(Parameter p); + } + + <Z> Z map(Mapper<Z> mz) { return null; } + + <Z extends Throwable> Mapper<Throwing<Z>> mapper(Throwing<Z> tz) throws Z { return null; } + + static class ThrowingMapper<X extends Throwable> implements Mapper<Throwing<X>> { + ThrowingMapper(Throwing<X> arg) throws X { } + + @Override + public Throwing<X> m(Parameter p) { + return null; + } + } + + void testRuntime(RuntimeThrowing rt) { + map(p->p.m(rt)); + map(mapper(rt)); + map(new ThrowingMapper<>(rt)); + } + + void testChecked(CheckedThrowing ct) { + map(p->p.m(ct)); + map(mapper(ct)); + map(new ThrowingMapper<>(ct)); + } +} diff --git a/test/tools/javac/lambda/8066974/T8066974.out b/test/tools/javac/lambda/8066974/T8066974.out new file mode 100644 index 00000000..59772fc5 --- /dev/null +++ b/test/tools/javac/lambda/8066974/T8066974.out @@ -0,0 +1,4 @@ +T8066974.java:40:19: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception +T8066974.java:41:19: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception +T8066974.java:42:13: compiler.err.unreported.exception.need.to.catch.or.throw: java.lang.Exception +3 errors diff --git a/test/tools/javac/lambda/8068399/T8068399.java b/test/tools/javac/lambda/8068399/T8068399.java new file mode 100644 index 00000000..fead21e5 --- /dev/null +++ b/test/tools/javac/lambda/8068399/T8068399.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2015, 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. + */ +/* + * @test + * @bug 8068399 + * @summary structural most specific and stuckness + */ + +import java.util.function.Function; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +public class T8068399 { + + public static class Spectrum { + public double[] getEnergy() { + return new double[0]; + } + } + + protected Spectrum spectrum; + + public static class Ref<T> { + + T value; + + public Ref() { + } + + public Ref(T value) { + this.value = value; + } + + public boolean isNull() { + return value == null; + } + + public T get() { + return value; + } + + public void set(T value) { + this.value = value; + } + } + + public static <T>T maxKey(Stream<T> stream, Function<T, Double> function) { + Ref<Double> max = new Ref<>(); + Ref<T> index = new Ref<>(); + stream.forEach(v -> { + Double value = function.apply(v); + + if (max.isNull() || value > max.get()) { + max.set(value); + index.set(v); + } + }); + + return index.get(); + } + + public static int interpolate(int x, int x0, int x1, int y0, int y1) { + return y0 + (x - x0) * (y1 - y0) / (x1 - x0); + } + + public static double interpolate(double x, double x0, double x1, double y0, double y1) { + return y0 + (x - x0) * (y1 - y0) / (x1 - x0); + } + + protected int getXByFrequency(double frequency) { + return (int) Math.round(interpolate(frequency, + getMinSpectrumCoord(), + getMaxSpectrumCoord(), + 0, getWidth())); + } + + private int getWidth() { + return 0; + } + + private double getMaxSpectrumCoord() { + return 0; + } + + private double getMinSpectrumCoord() { + return 0; + } + + void foo() { + int maxBpmIndex = 0; + int xcur = getXByFrequency(maxKey(IntStream.range(0, maxBpmIndex).boxed(), + i -> Math.abs(spectrum.getEnergy()[i]))); + } + + public static void main(String [] args) { + } +} diff --git a/test/tools/javac/lambda/8068430/T8068430.java b/test/tools/javac/lambda/8068430/T8068430.java new file mode 100644 index 00000000..167aa6e1 --- /dev/null +++ b/test/tools/javac/lambda/8068430/T8068430.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, 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. + */ + +/* + * @test + * @bug 8068430 + * @summary structural most specific and stuckness + */ + +import java.util.HashMap; +import java.util.Map; + +public class T8068430 { + public static void main(String[] args) { + Map<Integer, String> mp = new HashMap<>(); + mp.put(1, "a"); + mp.put(2, "b"); + mp.put(3, "c"); + mp.put(4, "d"); + System.out.println(mp.entrySet().stream().reduce(0, + (i, e) -> i + e.getKey(), + (i1, i2) -> i1 + i2)); + } +}
\ No newline at end of file diff --git a/test/tools/javac/lambda/8071432/T8071432.java b/test/tools/javac/lambda/8071432/T8071432.java new file mode 100644 index 00000000..aa1539cf --- /dev/null +++ b/test/tools/javac/lambda/8071432/T8071432.java @@ -0,0 +1,50 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8071432 + * @summary structural most specific and stuckness + * @compile/fail/ref=T8071432.out -XDrawDiagnostics T8071432.java + */ + +import java.util.Arrays; +import java.util.Collection; + +class T8071432 { + + static class Point { + + private double x, y; + + public Point(double x, double y) { + this.x = x; + this.y = y; + } + + public double getX() { + return x; + } + + public double getY() { + return y; + } + + public double distance(Point p) { + return Math.sqrt((this.x - p.x) * (this.x - p.x) + + (this.y - p.y) * (this.y - p.y)); + } + + public double distance() { + return Math.sqrt(this.x * this.x + this.y * this.y); + } + + public String toString() { + return "(" + x + ":" + y + ")"; + } + } + + public static void main(String[] args) { + Collection<Point> c = Arrays.asList(new Point(1.0, 0.1)); + System.out.println("------- 1 ---------------"); + System.out.println(c.stream().reduce(0.0, + (s, p) -> s += p.distance(), (d1, d2) -> 0)); + } +} diff --git a/test/tools/javac/lambda/8071432/T8071432.out b/test/tools/javac/lambda/8071432/T8071432.out new file mode 100644 index 00000000..05ddd447 --- /dev/null +++ b/test/tools/javac/lambda/8071432/T8071432.out @@ -0,0 +1,3 @@ +T8071432.java:47:45: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.assignment.exists: U, (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: int, java.lang.Double))) +T8071432.java:47:27: compiler.err.cant.apply.symbol: kindname.method, println, java.lang.Object, <any>, kindname.class, java.io.PrintStream, (compiler.misc.no.conforming.assignment.exists: (compiler.misc.infer.no.conforming.assignment.exists: U, (compiler.misc.incompatible.ret.type.in.lambda: (compiler.misc.inconvertible.types: int, java.lang.Double)))) +2 errors diff --git a/test/tools/javac/lambda/LambdaExprLeadsToMissingClassFilesTest.java b/test/tools/javac/lambda/LambdaExprLeadsToMissingClassFilesTest.java index 72f503cb..fb6dbde8 100644 --- a/test/tools/javac/lambda/LambdaExprLeadsToMissingClassFilesTest.java +++ b/test/tools/javac/lambda/LambdaExprLeadsToMissingClassFilesTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012, 2014 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 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 diff --git a/test/tools/javac/lambda/LocalVariableTable.java b/test/tools/javac/lambda/LocalVariableTable.java index 8a4d04a0..b70bc735 100644 --- a/test/tools/javac/lambda/LocalVariableTable.java +++ b/test/tools/javac/lambda/LocalVariableTable.java @@ -23,7 +23,7 @@ /* * @test - * @bug 8025998 8026749 + * @bug 8025998 8026749 8054220 8058227 * @summary Missing LV table in lambda bodies * @compile -g LocalVariableTable.java * @run main LocalVariableTable @@ -183,7 +183,7 @@ public class LocalVariableTable { Run1 r = (a) -> { int x = a; }; } - @Expect({ "a", "x" }) + @Expect({ "a", "x", "v" }) static class Lambda_Args1_Local1_Captured1 { void m() { int v = 0; @@ -191,7 +191,7 @@ public class LocalVariableTable { } } - @Expect({ "a1", "a2", "x1", "x2", "this" }) + @Expect({ "a1", "a2", "x1", "x2", "this", "v1", "v2" }) static class Lambda_Args2_Local2_Captured2_this { int v; void m() { @@ -204,7 +204,7 @@ public class LocalVariableTable { } } - @Expect({ "e" }) + @Expect({ "e", "c" }) static class Lambda_Try_Catch { private static Runnable asUncheckedRunnable(Closeable c) { return () -> { diff --git a/test/tools/javac/lambda/lambdaNaming/TestNonSerializableLambdaNameStability.java b/test/tools/javac/lambda/lambdaNaming/TestNonSerializableLambdaNameStability.java new file mode 100644 index 00000000..cda7c9df --- /dev/null +++ b/test/tools/javac/lambda/lambdaNaming/TestNonSerializableLambdaNameStability.java @@ -0,0 +1,157 @@ +/* + * 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 8067422 + * @summary Check that the lambda names are not unnecessarily unstable + * @run main TestNonSerializableLambdaNameStability + */ + +import com.sun.tools.classfile.ClassFile; +import com.sun.tools.classfile.Method; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.tools.FileObject; +import javax.tools.ForwardingJavaFileManager; +import javax.tools.JavaCompiler; +import javax.tools.JavaFileManager; +import javax.tools.JavaFileObject; +import javax.tools.JavaFileObject.Kind; +import javax.tools.SimpleJavaFileObject; +import javax.tools.ToolProvider; + +public class TestNonSerializableLambdaNameStability { + + public static void main(String... args) throws Exception { + new TestNonSerializableLambdaNameStability().run(); + } + + String lambdaSource = "public class L%d {\n" + + " public static class A {\n" + + " private Runnable r = () -> { };\n" + + " }\n" + + " public static class B {\n" + + " private Runnable r = () -> { };\n" + + " }\n" + + " private Runnable r = () -> { };\n" + + "}\n"; + + String expectedLambdaMethodName = "lambda$new$0"; + + void run() throws Exception { + List<JavaFileObject> sources = new ArrayList<>(); + + for (int i = 0; i < 3; i++) { + sources.add(new SourceJavaFileObject("L" + i, String.format(lambdaSource, i))); + } + + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + + try (MemoryFileManager fm = new MemoryFileManager(compiler.getStandardFileManager(null, null, null))) { + if (!compiler.getTask(null, fm, null, null, null, sources).call()) { + throw new AssertionError("Compilation failed!"); + } + + for (String file : fm.name2Content.keySet()) { + byte[] fileBytes = fm.name2Content.get(file); + try (InputStream in = new ByteArrayInputStream(fileBytes)) { + boolean foundLambdaMethod = false; + ClassFile cf = ClassFile.read(in); + StringBuilder seenMethods = new StringBuilder(); + String sep = ""; + for (Method m : cf.methods) { + String methodName = m.getName(cf.constant_pool); + if (expectedLambdaMethodName.equals(methodName)) { + foundLambdaMethod = true; + break; + } + seenMethods.append(sep); + seenMethods.append(methodName); + sep = ", "; + } + + if (!foundLambdaMethod) { + throw new AbstractMethodError("Did not find the lambda method, " + + "found methods: " + seenMethods.toString()); + } + } + } + } + } + + class MemoryFileManager extends ForwardingJavaFileManager<JavaFileManager> { + + final Map<String, byte[]> name2Content = new HashMap<>(); + + public MemoryFileManager(JavaFileManager fileManager) { + super(fileManager); + } + + @Override + public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling) throws IOException { + try { + return new SimpleJavaFileObject(new URI("mem://" + className.replace('.', '/') + kind.extension), kind) { + @Override public OutputStream openOutputStream() throws IOException { + return new ByteArrayOutputStream() { + @Override public void close() throws IOException { + super.close(); + name2Content.put(className, toByteArray()); + } + }; + } + }; + } catch (URISyntaxException ex) { + throw new AssertionError(ex); + } + } + + } + + class SourceJavaFileObject extends SimpleJavaFileObject { + + private final String code; + + public SourceJavaFileObject(String name, String code) throws URISyntaxException { + super(new URI("mem:///" + name + ".java"), Kind.SOURCE); + this.code = code; + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { + return code; + } + + } +} diff --git a/test/tools/javac/linenumbers/FinallyLineNumberTest.java b/test/tools/javac/linenumbers/FinallyLineNumberTest.java new file mode 100644 index 00000000..892d3658 --- /dev/null +++ b/test/tools/javac/linenumbers/FinallyLineNumberTest.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2015, 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 8134759 + * @summary Add LineNumberTable attribute for return bytecodes split around finally code + * @modules jdk.jdeps/com.sun.tools.classfile + */ + +import com.sun.tools.classfile.ClassFile; +import com.sun.tools.classfile.ConstantPoolException; +import com.sun.tools.classfile.Method; +import com.sun.tools.classfile.Attribute; +import com.sun.tools.classfile.Code_attribute; +import com.sun.tools.classfile.LineNumberTable_attribute; +import com.sun.tools.classfile.LineNumberTable_attribute.Entry; + +import java.io.File; +import java.io.IOException; + +public class FinallyLineNumberTest { + public static void main(String[] args) throws Exception { + // check that we have 5 consecutive entries for method() + Entry[] lines = findEntries(); + if (lines == null) { + throw new Exception("finally line number table could not be loaded"); + } + if (lines.length != 4) { + // Help debug + System.err.println("LineTable error, got lines:"); + for (Entry e : lines) { + System.err.println(e.line_number); + } + throw new Exception("finally line number table incorrect: length=" + lines.length + " expected length=4"); + } + + // return null line, for the load null operation + int current = lines[0].line_number; + int first = current; + + // finally line + current = lines[1].line_number; + if (current != first + 2) { + throw new Exception("finally line number table incorrect: got=" + current + " expected=" + (first + 2)); + } + + // return null line, for the return operation + current = lines[2].line_number; + if (current != first) { + throw new Exception("finally line number table incorrect: got=" + current + " expected=" + first); + } + + // finally line, for when exception is thrown + current = lines[3].line_number; + if (current != first + 2) { + throw new Exception("finally line number table incorrect: got=" + current + " expected=" + (first + 2)); + } + } + + static Entry[] findEntries() throws IOException, ConstantPoolException { + ClassFile self = ClassFile.read(FinallyLineNumberTest.class.getResourceAsStream("FinallyLineNumberTest.class")); + for (Method m : self.methods) { + if ("method".equals(m.getName(self.constant_pool))) { + Code_attribute code_attribute = (Code_attribute)m.attributes.get(Attribute.Code); + for (Attribute at : code_attribute.attributes) { + if (Attribute.LineNumberTable.equals(at.getName(self.constant_pool))) { + return ((LineNumberTable_attribute)at).line_number_table; + } + } + } + } + return null; + } + + // This method should get LineNumberTable entries for: + // *) The load of the null + // *) The finally code for when an exception is *not* thrown + // *) The actual return, which should have the same line as the load of the null + // *) The finally code for when an exception *is* thrown, should have the same line as above finally code + public static String method(int field) { + try { + return null; + } finally { + field+=1; // Dummy + } + } +} diff --git a/test/tools/javac/linenumbers/NestedLineNumberTest.java b/test/tools/javac/linenumbers/NestedLineNumberTest.java new file mode 100644 index 00000000..562365ce --- /dev/null +++ b/test/tools/javac/linenumbers/NestedLineNumberTest.java @@ -0,0 +1,81 @@ +/* + * 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. + */ + +/* + * @test + * @bug 8061778 + * @summary Wrong LineNumberTable for default constructors + */ + +import com.sun.tools.classfile.ClassFile; +import com.sun.tools.classfile.ConstantPoolException; +import com.sun.tools.classfile.Method; +import com.sun.tools.classfile.Attribute; +import com.sun.tools.classfile.Code_attribute; +import com.sun.tools.classfile.LineNumberTable_attribute; +import com.sun.tools.classfile.LineNumberTable_attribute.Entry; + +import java.io.IOException; + +public class NestedLineNumberTest { + + public static void main(String[] args) throws Exception { + Entry[] lines = findEntries(); + if (lines == null || lines.length != 1) { + int found = lines == null ? 0 : lines.length; + error(String.format("LineNumberTable contains wrong number of entries - expected %d, found %d", 1, found)); + } + + int line = lines[0].line_number; + if (line != 78) { + error(String.format("LineNumberTable contains wrong line number - expected %d, found %d", 78, line)); + } + } + + static Entry[] findEntries() throws IOException, ConstantPoolException { + ClassFile self = ClassFile.read(NestedLineNumberTest.Test.class.getResourceAsStream("NestedLineNumberTest$Test.class")); + for (Method m : self.methods) { + if ("<init>".equals(m.getName(self.constant_pool))) { + Code_attribute code_attribute = (Code_attribute)m.attributes.get(Attribute.Code); + for (Attribute at : code_attribute.attributes) { + if (Attribute.LineNumberTable.equals(at.getName(self.constant_pool))) { + return ((LineNumberTable_attribute)at).line_number_table; + } + } + } + } + return null; + } + + static void error(String msg) { + throw new AssertionError(msg); + } + + // The default constructor in this class should get only one LineNumberTable entry, + // pointing to the first line of the declaration of class Test. + static class Test { + static class Empty { } + } +} diff --git a/test/tools/javac/links/LinksTest.java b/test/tools/javac/links/LinksTest.java index 6cdebb0a..b99de9f4 100644 --- a/test/tools/javac/links/LinksTest.java +++ b/test/tools/javac/links/LinksTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2015, 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,6 +30,7 @@ * @run main LinksTest */ +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; @@ -48,19 +49,26 @@ public class LinksTest { throws Exception { // mkdir tmp // cp ${TESTSRC}/b/B.java tmp - ToolBox.writeFile(Paths.get("tmp", "B.java"), BSrc); + ToolBox.writeFile(Paths.get("tmp/B.java"), BSrc); - try { + // Try to set up a symbolic link for the test. // ln -s `pwd`/tmp "${TESTCLASSES}/a" + try { Files.createSymbolicLink(Paths.get("a"), Paths.get("tmp")); - ////"${TESTJAVA}/bin/javac" ${TESTTOOLVMOPTS} -sourcepath "${TESTCLASSES}" -d "${TESTCLASSES}/classes" "${TESTSRC}/T.java" 2>&1 - ToolBox.JavaToolArgs javacArgs = - new ToolBox.JavaToolArgs() - .setOptions("-sourcepath", ".", "-d", ".").setSources(TSrc); - ToolBox.javac(javacArgs); - } catch (UnsupportedOperationException e) { - System.err.println("Symbolic links not supported on this system. The test can't finish"); + System.err.println("Created symbolic link"); + } catch (UnsupportedOperationException | IOException e) { + System.err.println("Problem creating symbolic link: " + e); + System.err.println("Test cannot continue; test passed by default"); + return; } + + // If symbolic link was successfully created, + // try a compilation that will use it. + ////"${TESTJAVA}/bin/javac" ${TESTTOOLVMOPTS} -sourcepath "${TESTCLASSES}" -d "${TESTCLASSES}/classes" "${TESTSRC}/T.java" 2>&1 + ToolBox.JavaToolArgs javacArgs = + new ToolBox.JavaToolArgs() + .setOptions("-sourcepath", ".", "-d", ".").setSources(TSrc); + ToolBox.javac(javacArgs); } } diff --git a/test/tools/javac/multicatch/8071291/T8071291.java b/test/tools/javac/multicatch/8071291/T8071291.java new file mode 100644 index 00000000..dd0e5809 --- /dev/null +++ b/test/tools/javac/multicatch/8071291/T8071291.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015, 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 8071291 + * @summary Compiler crashes trying to cast UnionType to IntersectionClassType + * @compile T8071291.java + */ + +class T8071291 { + + interface A { } + class Exception1 extends Exception implements A { } + class Exception2 extends Exception implements A { } + + void test(boolean cond) { + try { + if (cond) { + throw new Exception1(); + } else { + throw new Exception2(); + } + } + catch (Exception1|Exception2 x) { + if (x instanceof Exception1) { } + } + } +} diff --git a/test/tools/javac/resolve/tests/PrimitiveVsReferenceSamePhase.java b/test/tools/javac/resolve/tests/PrimitiveVsReferenceSamePhase.java index 0ac15984..9acf4454 100644 --- a/test/tools/javac/resolve/tests/PrimitiveVsReferenceSamePhase.java +++ b/test/tools/javac/resolve/tests/PrimitiveVsReferenceSamePhase.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. + * 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 diff --git a/test/tools/javac/scope/RemoveSymbolTest.java b/test/tools/javac/scope/RemoveSymbolTest.java new file mode 100644 index 00000000..bc466dfa --- /dev/null +++ b/test/tools/javac/scope/RemoveSymbolTest.java @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2015, 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 8080842 + * @summary Ensure Scope impl can cope with remove() when a field and method share the name. + * @run main RemoveSymbolTest + */ + +import java.util.Iterator; +import java.util.LinkedList; + +public class RemoveSymbolTest<W> implements Iterable<W> { + static class Widget { + private String name; + Widget(String s) { name = s; } + @Override public String toString() { return name; } + } + + private LinkedList<W> data; + // Instantiate an Iterable instance using a Lambda expression. + // Causes ClassFormatError if a local variable of type Widget is named after one of the methods. + private final Iterable<W> myIterator1 = () -> new Iterator<W>() { + private W hasNext = null; + private int index = 0; + @Override public boolean hasNext() { return index < data.size(); } + @Override public W next() { return data.get(index++); } + }; + + // Instantiate an Iterable instance using an anonymous class. + // Always works fine regardless of the name of the local variable. + private final Iterable<W> myIterator2 = + new Iterable<W>() { + @Override + public Iterator<W> iterator() { + return new Iterator<W>() { + private W hasNext = null; + private int index = 0; + @Override public boolean hasNext() { return index < data.size(); } + @Override public W next() { return data.get(index++); } + }; + } + }; + public RemoveSymbolTest() { data = new LinkedList<>(); } + public void add(W e) { data.add(e); } + @Override public String toString() { return data.toString(); } + @Override public Iterator<W> iterator() { return myIterator1.iterator(); } + public static void main(String[] args) { + RemoveSymbolTest<Widget> widgets = new RemoveSymbolTest<>(); + widgets.add(new Widget("W1")); + widgets.add(new Widget("W2")); + widgets.add(new Widget("W3")); + System.out.println(".foreach() call: "); + widgets.forEach(w -> System.out.println(w + " ")); + } +} diff --git a/test/tools/javac/scope/RemoveSymbolUnitTest.java b/test/tools/javac/scope/RemoveSymbolUnitTest.java new file mode 100644 index 00000000..8be14a54 --- /dev/null +++ b/test/tools/javac/scope/RemoveSymbolUnitTest.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2015 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 8080842 + * @summary Ensure Scope impl can cope with remove() when a field and method share the name. + */ + +import com.sun.tools.javac.util.*; +import com.sun.tools.javac.code.*; +import com.sun.tools.javac.code.Scope.*; +import com.sun.tools.javac.code.Symbol.*; +import com.sun.tools.javac.file.JavacFileManager; + +public class RemoveSymbolUnitTest { + + Context context; + Names names; + Symtab symtab; + + public static void main(String... args) throws Exception { + new RemoveSymbolUnitTest().run(); + } + + public void run() { + context = new Context(); + JavacFileManager.preRegister(context); // required by ClassReader which is required by Symtab + names = Names.instance(context); + symtab = Symtab.instance(context); + + Name hasNext = names.fromString("hasNext"); + ClassSymbol clazz = new ClassSymbol(0, + names.fromString("X"), + Type.noType, + symtab.unnamedPackage); + + VarSymbol v = new VarSymbol(0, hasNext, Type.noType, clazz); + MethodSymbol m = new MethodSymbol(0, hasNext, Type.noType, clazz); + + // Try enter and remove in different shuffled combinations. + // working with fresh scope each time. + Scope cs = new Scope(clazz); + cs.enter(v); + cs.enter(m); + cs.remove(v); + Symbol s = cs.lookup(hasNext).sym; + if (s != m) + throw new AssertionError("Wrong symbol"); + + cs = new Scope(clazz); + cs.enter(m); + cs.enter(v); + cs.remove(v); + s = cs.lookup(hasNext).sym; + if (s != m) + throw new AssertionError("Wrong symbol"); + + cs = new Scope(clazz); + cs.enter(v); + cs.enter(m); + cs.remove(m); + s = cs.lookup(hasNext).sym; + if (s != v) + throw new AssertionError("Wrong symbol"); + + cs = new Scope(clazz); + cs.enter(m); + cs.enter(v); + cs.remove(m); + s = cs.lookup(hasNext).sym; + if (s != v) + throw new AssertionError("Wrong symbol"); + } +} diff --git a/test/tools/javac/types/ScopeListenerTest.java b/test/tools/javac/types/ScopeListenerTest.java new file mode 100644 index 00000000..651d410b --- /dev/null +++ b/test/tools/javac/types/ScopeListenerTest.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2015, 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 8039262 + * @summary Ensure that using Types.membersClosure does not increase the number of listeners on the + * class's members Scope. + */ + +import com.sun.tools.javac.code.Scope; +import com.sun.tools.javac.code.Symbol; +import com.sun.tools.javac.code.Symtab; +import com.sun.tools.javac.code.Types; +import com.sun.tools.javac.file.JavacFileManager; +import com.sun.tools.javac.util.Context; +import com.sun.tools.javac.util.Names; +import java.lang.reflect.Field; +import java.util.Collection; + +public class ScopeListenerTest { + + public static void main(String[] args) throws Exception { + new ScopeListenerTest().run(); + } + + void run() throws Exception { + Context context = new Context(); + JavacFileManager.preRegister(context); + Types types = Types.instance(context); + Symtab syms = Symtab.instance(context); + Names names = Names.instance(context); + types.membersClosure(syms.stringType, true); + types.membersClosure(syms.stringType, false); + + Field listenersField = Scope.class.getDeclaredField("listeners"); + + listenersField.setAccessible(true); + + int listenerCount = + ((Collection) listenersField.get(syms.stringType.tsym.members())).size(); + + for (int i = 0; i < 100; i++) { + types.membersClosure(syms.stringType, true); + types.membersClosure(syms.stringType, false); + } + + int newListenerCount + = ((Collection) listenersField.get(syms.stringType.tsym.members())).size(); + + if (listenerCount != newListenerCount) { + throw new AssertionError("Orig listener count: " + listenerCount + + "; new listener count: " + newListenerCount); + } + + for (Symbol s : types.membersClosure(syms.stringType, true).getElements()) + ; + for (Symbol s : types.membersClosure(syms.stringType, false).getElementsByName(names.fromString("substring"))) + ; + } + +} diff --git a/test/tools/javac/varargs/access/OtherPackage.java b/test/tools/javac/varargs/access/OtherPackage.java new file mode 100644 index 00000000..2bfd4c3f --- /dev/null +++ b/test/tools/javac/varargs/access/OtherPackage.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015, 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. + */ + +/* + * Auxiliary file for VarargsInferredPrivateType + */ + +package otherpackage; + +public class OtherPackage { + public static Private getPrivate() { + return new Private(); + } + + private static class Private {} +}
\ No newline at end of file diff --git a/test/tools/javac/varargs/T8049075/VarargsAndWildcardParameterizedTypeTest.java b/test/tools/javac/varargs/access/VarargsAndWildcardParameterizedTypeTest.java index c9618766..9879924e 100644 --- a/test/tools/javac/varargs/T8049075/VarargsAndWildcardParameterizedTypeTest.java +++ b/test/tools/javac/varargs/access/VarargsAndWildcardParameterizedTypeTest.java @@ -26,6 +26,8 @@ * @bug 8049075 * @summary javac, wildcards and generic vararg method invocation not accepted * @compile VarargsAndWildcardParameterizedTypeTest.java + * @compile -source 8 VarargsAndWildcardParameterizedTypeTest.java + * @compile -source 7 VarargsAndWildcardParameterizedTypeTest.java */ class VarargsAndWildcardParameterizedTypeTest { diff --git a/test/tools/javac/varargs/access/VarargsAndWildcardParameterizedTypeTest2.java b/test/tools/javac/varargs/access/VarargsAndWildcardParameterizedTypeTest2.java new file mode 100644 index 00000000..39371972 --- /dev/null +++ b/test/tools/javac/varargs/access/VarargsAndWildcardParameterizedTypeTest2.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2015, 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 8075520 + * @summary Varargs access check mishandles capture variables + * @compile VarargsAndWildcardParameterizedTypeTest2.java + * @compile -source 8 VarargsAndWildcardParameterizedTypeTest2.java + * @compile -source 7 VarargsAndWildcardParameterizedTypeTest2.java + */ + +class VarargsAndWildcardParameterizedTypeTest2 { + interface I { + <T> void m(T... t); + } + + interface Box<T> { + T get(); + } + + void m(I i, Box<? extends Number> b) { + i.m(b.get()); + } +} diff --git a/test/tools/javac/varargs/access/VarargsAndWildcardParameterizedTypeTest3.java b/test/tools/javac/varargs/access/VarargsAndWildcardParameterizedTypeTest3.java new file mode 100644 index 00000000..ae468513 --- /dev/null +++ b/test/tools/javac/varargs/access/VarargsAndWildcardParameterizedTypeTest3.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015, 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 8075520 + * @summary Varargs access check mishandles capture variables + * @compile VarargsAndWildcardParameterizedTypeTest3.java + * @compile -source 8 VarargsAndWildcardParameterizedTypeTest3.java + * @compile -source 7 VarargsAndWildcardParameterizedTypeTest3.java + */ + +class VarargsAndWildcardParameterizedTypeTest2 { + interface I { + <T> void m(Box<? extends T> iter, T... t); + } + + interface Box<T> {} + + void m(I i, Box<? extends Number> b) { + i.m(b); + } +} diff --git a/test/tools/javac/varargs/access/VarargsAndWildcardParameterizedTypeTest4.java b/test/tools/javac/varargs/access/VarargsAndWildcardParameterizedTypeTest4.java new file mode 100644 index 00000000..77c61d67 --- /dev/null +++ b/test/tools/javac/varargs/access/VarargsAndWildcardParameterizedTypeTest4.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015, 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 8075520 + * @summary Varargs access check mishandles capture variables + * @compile VarargsAndWildcardParameterizedTypeTest4.java + * @compile -source 8 VarargsAndWildcardParameterizedTypeTest4.java + * @compile -source 7 VarargsAndWildcardParameterizedTypeTest4.java + */ + +class VarargsAndWildcardParameterizedTypeTest2 { + interface I { + <T> void m(Box<T> iter, T... t); + } + + interface Box<T> {} + + void m(I i, Box<? extends Number> b) { + i.m(b); + } +} diff --git a/test/tools/javac/varargs/access/VarargsInferredPrivateType-source7.out b/test/tools/javac/varargs/access/VarargsInferredPrivateType-source7.out new file mode 100644 index 00000000..87670f62 --- /dev/null +++ b/test/tools/javac/varargs/access/VarargsInferredPrivateType-source7.out @@ -0,0 +1,4 @@ +VarargsInferredPrivateType.java:16:10: compiler.err.cant.apply.symbol: kindname.method, m, T[], otherpackage.OtherPackage.Private, kindname.interface, VarargsInferredPrivateType.I, (compiler.misc.inaccessible.varargs.type: otherpackage.OtherPackage.Private, kindname.class, VarargsInferredPrivateType) +- compiler.note.unchecked.filename: VarargsInferredPrivateType.java +- compiler.note.unchecked.recompile +1 error diff --git a/test/tools/javac/varargs/access/VarargsInferredPrivateType.java b/test/tools/javac/varargs/access/VarargsInferredPrivateType.java new file mode 100644 index 00000000..efe8d62e --- /dev/null +++ b/test/tools/javac/varargs/access/VarargsInferredPrivateType.java @@ -0,0 +1,18 @@ +/* + * @test /nodynamiccopyright/ + * @bug 8077786 + * @summary Check varargs access against inferred signature + * @compile/fail/ref=VarargsInferredPrivateType.out -nowarn -XDrawDiagnostics VarargsInferredPrivateType.java OtherPackage.java + * @compile/fail/ref=VarargsInferredPrivateType.out -source 8 -nowarn -XDrawDiagnostics VarargsInferredPrivateType.java OtherPackage.java + * @compile/fail/ref=VarargsInferredPrivateType-source7.out -source 7 -nowarn -XDrawDiagnostics VarargsInferredPrivateType.java OtherPackage.java + */ + +class VarargsInferredPrivateType { + interface I { + <T> void m(T... t); + } + + void m(I i) { + i.m(otherpackage.OtherPackage.getPrivate()); + } +} diff --git a/test/tools/javac/varargs/access/VarargsInferredPrivateType.out b/test/tools/javac/varargs/access/VarargsInferredPrivateType.out new file mode 100644 index 00000000..aae7daba --- /dev/null +++ b/test/tools/javac/varargs/access/VarargsInferredPrivateType.out @@ -0,0 +1,4 @@ +VarargsInferredPrivateType.java:16:12: compiler.err.prob.found.req: (compiler.misc.inaccessible.varargs.type: otherpackage.OtherPackage.Private, kindname.class, VarargsInferredPrivateType) +- compiler.note.unchecked.filename: VarargsInferredPrivateType.java +- compiler.note.unchecked.recompile +1 error diff --git a/test/tools/javadoc/CompletionError.java b/test/tools/javadoc/CompletionError.java new file mode 100644 index 00000000..d32b7a3e --- /dev/null +++ b/test/tools/javadoc/CompletionError.java @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2015, 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 8135307 + * @summary Check that CompletionFailures for missing classes are not incorrectly passed to + * the javadoc API clients. + * @modules jdk.javadoc + * @run main CompletionError + */ + +import java.io.File; +import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; + +import javax.tools.JavaCompiler; +import javax.tools.JavaFileObject; +import javax.tools.SimpleJavaFileObject; +import javax.tools.ToolProvider; + +import com.sun.javadoc.*; +import com.sun.tools.javadoc.Main; + +public class CompletionError extends Doclet +{ + private static final String template = + "public class CompletionErrorAuxiliary #extends CompletionErrorMissing# #implements CompletionErrorIntfMissing# {" + + " #public CompletionErrorMissing tf;#" + + " #public CompletionErrorMissing tm() { return null; }#" + + " #public void tm(CompletionErrorMissing m) {}#" + + " #public void tm() throws CompletionErrorExcMissing {}#" + + " #public <T extends CompletionErrorMissing> void tm() {}#" + + " public String toString() { return null; }" + + "}"; + + public static void main(String[] args) throws Exception { + JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); + String[] templateParts = template.split("#"); + int sources = templateParts.length / 2; + for (int source = 0; source < sources; source++) { + StringBuilder testSource = new StringBuilder(); + for (int i = 0; i < templateParts.length; i += 2) { + testSource.append(templateParts[i]); + if (i == 2 * source) { + testSource.append(templateParts[i + 1]); + } + } + test = 0; + testsDone = false; + while (!testsDone) { + List<JavaSource> fileObjects = + Arrays.asList(new JavaSource("CompletionErrorAuxiliary", testSource.toString()), + new JavaSource("CompletionErrorMissing", "public class CompletionErrorMissing {}"), + new JavaSource("CompletionErrorIntfMissing", "public interface CompletionErrorIntfMissing {}"), + new JavaSource("CompletionErrorExcMissing", "public class CompletionErrorExcMissing extends Exception {}")); + Boolean result = compiler.getTask(null, null, null, Arrays.asList("-d", "."), null, fileObjects).call(); + if (!result) + throw new Error(); + for (String delete : new String[] {"CompletionErrorMissing.class", "CompletionErrorIntfMissing.class", "CompletionErrorExcMissing.class"}) { + Files.delete(Paths.get(delete)); + } + // run javadoc: + if (Main.execute("javadoc", "CompletionError", CompletionError.class.getClassLoader(), + "-classpath", ".", + System.getProperty("test.src", ".") + File.separatorChar + "CompletionError.java") != 0) + throw new Error(); + } + } + } + + private static int test; + private static boolean testsDone; + + public static boolean start(com.sun.javadoc.RootDoc root) { + ClassDoc aux = root.classNamed("CompletionErrorAuxiliary"); + if (aux == null) + throw new AssertionError("Cannot find CompletionErrorAuxiliary"); + + FieldDoc tf = findField(aux, "tf"); + MethodDoc tm = findMethod(aux, "tm"); + MethodDoc cm = findMethod(aux, "toString"); + switch (test) { + case 0: aux.superclass(); break; + case 1: aux.superclassType(); break; + case 2: aux.interfaces(); break; + case 3: aux.interfaceTypes(); break; + case 4: if (tf != null) tf.type(); break; + case 5: if (tm != null) tm.overriddenClass(); break; + case 6: if (tm != null) tm.overriddenMethod(); break; + case 7: if (tm != null) tm.overriddenType(); break; + case 8: + if (tm != null) { + for (Parameter p : tm.parameters()) { + p.type(); + } + } + break; + case 9: if (tm != null) tm.receiverType(); break; + case 10: if (tm != null) tm.returnType(); break; + case 11: if (tm != null) tm.thrownExceptionTypes(); break; + case 12: if (tm != null) tm.thrownExceptions(); break; + case 13: + if (tm != null) { + for (TypeVariable tv : tm.typeParameters()) { + tv.bounds(); + } + } + break; + case 14: if (cm != null) cm.overriddenClass(); break; + case 15: if (cm != null) cm.overriddenMethod(); break; + case 16: if (cm != null) cm.overriddenType(); testsDone = true; break; + default: + throw new IllegalStateException("Unrecognized test!"); + } + test++; + return true; + } + + private static MethodDoc findMethod(ClassDoc cd, String name) { + for (MethodDoc m : cd.methods()) { + if (name.equals(m.name())) + return m; + } + + return null; + } + + private static FieldDoc findField(ClassDoc cd, String name) { + for (FieldDoc m : cd.fields()) { + if (name.equals(m.name())) + return m; + } + + return null; + } + + static class JavaSource extends SimpleJavaFileObject { + final String source; + + public JavaSource(String name, String source) { + super(URI.create("myfo:/" + name + ".java"), JavaFileObject.Kind.SOURCE); + this.source = source; + } + + @Override + public CharSequence getCharContent(boolean ignoreEncodingErrors) { + return source; + } + } +} diff --git a/test/tools/jdeps/APIDeps.java b/test/tools/jdeps/APIDeps.java index c3d2c997..25859dca 100644 --- a/test/tools/jdeps/APIDeps.java +++ b/test/tools/jdeps/APIDeps.java @@ -90,8 +90,9 @@ public class APIDeps { new String[] {"-classpath", testDir.getPath(), "-verbose:class", "-filter:none", "-P"}); test(new File(mDir, "Gee.class"), new String[] {"g.G", "sun.misc.Lock", "com.sun.tools.classfile.ClassFile", - "com.sun.management.ThreadMXBean", "com.sun.source.tree.BinaryTree"}, - new String[] {testDirBasename, "JDK internal API", "compact3", ""}, + "com.sun.management.ThreadMXBean", "com.sun.source.tree.BinaryTree", + "org.w3c.dom.css.CSSValue"}, + new String[] {testDirBasename, "JDK internal API", "compact2", "compact3", ""}, new String[] {"-classpath", testDir.getPath(), "-verbose", "-P"}); // -jdkinternals diff --git a/test/tools/jdeps/Basic.java b/test/tools/jdeps/Basic.java index 046a047f..f64f1304 100644 --- a/test/tools/jdeps/Basic.java +++ b/test/tools/jdeps/Basic.java @@ -23,9 +23,9 @@ /* * @test - * @bug 8003562 8005428 8015912 8027481 8048063 + * @bug 8003562 8005428 8015912 8027481 8048063 8068937 * @summary Basic tests for jdeps tool - * @build Test p.Foo p.Bar javax.activity.NotCompactProfile + * @build Test p.Foo p.Bar p.C p.SubClass q.Gee javax.activity.NotCompactProfile * @run main Basic */ @@ -111,6 +111,19 @@ public class Basic { new String[] {"compact1"}, new String[] {"-verbose:package", "-e", "java\\.lang\\..*"}); + // parse p.C, p.SubClass and q.* + // p.SubClass have no dependency other than p.C + // q.Gee depends on p.SubClass that should be found + test(testDir, + new String[] {"java.lang", "p"}, + new String[] {"compact1", testDir.getName()}, + new String[] {"-include", "p.C|p.SubClass|q\\..*"}); + test(testDir, + new String[] {"java.lang", "p"}, + new String[] {"compact1", testDir.getName()}, + new String[] {"-classpath", testDir.getPath(), "-include", "p.C|p.SubClass|q\\..*"}); + + // test -classpath and -include options test(null, new String[] {"java.lang", "java.util", "java.lang.management", diff --git a/test/tools/jdeps/m/Gee.java b/test/tools/jdeps/m/Gee.java index 0020b18d..aabc50ca 100644 --- a/test/tools/jdeps/m/Gee.java +++ b/test/tools/jdeps/m/Gee.java @@ -29,4 +29,5 @@ class Gee extends g.G { public com.sun.tools.classfile.ClassFile cf; // @jdk.Exported(false) public com.sun.source.tree.BinaryTree tree; // @jdk.Exported public com.sun.management.ThreadMXBean mxbean; // @jdk.Exported on package-info + public org.w3c.dom.css.CSSValue value; // special case } diff --git a/test/tools/jdeps/p/C.java b/test/tools/jdeps/p/C.java new file mode 100644 index 00000000..6ad93182 --- /dev/null +++ b/test/tools/jdeps/p/C.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2015, 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 p; + +public class C { + public String name() { + return "C"; + } +} diff --git a/test/tools/jdeps/p/SubClass.java b/test/tools/jdeps/p/SubClass.java new file mode 100644 index 00000000..020953d8 --- /dev/null +++ b/test/tools/jdeps/p/SubClass.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2015, 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 p; + +// SubClass only references types in package p +public class SubClass extends C { +} diff --git a/test/tools/jdeps/q/Gee.java b/test/tools/jdeps/q/Gee.java new file mode 100644 index 00000000..0db04fb7 --- /dev/null +++ b/test/tools/jdeps/q/Gee.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2015, 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 q; + +public class Gee extends p.SubClass { +} |