From pankaj.b.bansal at oracle.com Thu Jan 2 07:03:55 2020 From: pankaj.b.bansal at oracle.com (Pankaj Bansal) Date: Wed, 1 Jan 2020 23:03:55 -0800 (PST) Subject: (no subject) Message-ID: Hi All, Please review the following test only fix for jdk15. Bug: https://bugs.openjdk.java.net/browse/JDK-8224475 webrev: http://cr.openjdk.java.net/~pbansal/8224475/webrev00/ The present bug is a regression of [1], which was itself a regression of [2] which was regression of [3]. [1] has also caused one more regression, which was fixed in [4], which itself caused one regression which I have fixed in [5]. Hoping to close this regression series for good by current fix. The images are not being displayed properly due to improper scaling after [1] as some code was removed unnecessarily. The testcase attached in this bug exposes that issue. More details in the JBS. I have added the code removed unnecessarily in [1] taking into consideration all the changes done after [1] in same code. I have run all the test cases added in all these bugs to ensure that no old issues are being introduced by current change. I have run the new testcase as well and it works fine with the changes. [1] https://bugs.openjdk.java.net/browse/JDK-8208638 [2] https://bugs.openjdk.java.net/browse/JDK-8206238 [3] https://bugs.openjdk.java.net/browse/JDK-8195095 [4] https://bugs.openjdk.java.net/browse/JDK-8218674 [5] https://bugs.openjdk.java.net/browse/JDK-8230235 Regards, Pankaj Bansal -------------- next part -------------- An HTML attachment was scrubbed... URL: From pankaj.b.bansal at oracle.com Thu Jan 2 07:09:50 2020 From: pankaj.b.bansal at oracle.com (Pankaj Bansal) Date: Wed, 1 Jan 2020 23:09:50 -0800 (PST) Subject: [15] RFR JDK-8224475: JTextPane does not show images in HTML rendering Message-ID: <7e309a8f-c5d6-4ec1-8919-731d9c4121dd@default> Adding proper subject missed in initial mail by mistake. -Pankaj From: Pankaj Bansal Sent: Thursday, January 2, 2020 12:34 PM To: swing-dev at openjdk.java.net Subject: Hi All, Please review the following test only fix for jdk15. Bug: https://bugs.openjdk.java.net/browse/JDK-8224475 webrev: http://cr.openjdk.java.net/~pbansal/8224475/webrev00/ The present bug is a regression of [1], which was itself a regression of [2] which was regression of [3]. [1] has also caused one more regression, which was fixed in [4], which itself caused one regression which I have fixed in [5]. Hoping to close this regression series for good by current fix. The images are not being displayed properly due to improper scaling after [1] as some code was removed unnecessarily. The testcase attached in this bug exposes that issue. More details in the JBS. I have added the code removed unnecessarily in [1] taking into consideration all the changes done after [1] in same code. I have run all the test cases added in all these bugs to ensure that no old issues are being introduced by current change. I have run the new testcase as well and it works fine with the changes. [1] https://bugs.openjdk.java.net/browse/JDK-8208638 [2] https://bugs.openjdk.java.net/browse/JDK-8206238 [3] https://bugs.openjdk.java.net/browse/JDK-8195095 [4] https://bugs.openjdk.java.net/browse/JDK-8218674 [5] https://bugs.openjdk.java.net/browse/JDK-8230235 Regards, Pankaj Bansal -------------- next part -------------- An HTML attachment was scrubbed... URL: From erik.joelsson at oracle.com Thu Jan 2 07:57:07 2020 From: erik.joelsson at oracle.com (Erik Joelsson) Date: Thu, 2 Jan 2020 08:57:07 +0100 Subject: [15] Review Request: 8235975 Update copyright year to match last edit in jdk repository for 2014/15/16/17/18 In-Reply-To: <3460a6f6-6178-cc45-5840-0f215eebc53f@oracle.com> References: <1e7d0395-fc57-4d5b-9cfa-c33e0f6462d5@oracle.com> <3460a6f6-6178-cc45-5840-0f215eebc53f@oracle.com> Message-ID: <7b67e39d-752c-50a8-8e18-9a8f86bd641c@oracle.com> Build files look good. /Erik On 2019-12-24 19:22, Sergey Bylokhov wrote: > Hello. > > Here is an updated version: > ? Bug: https://bugs.openjdk.java.net/browse/JDK-8235975 > ? Patch (2 Mb): > http://cr.openjdk.java.net/~serb/8235975/webrev.03/open.patch > ? Fix: http://cr.openjdk.java.net/~serb/8235975/webrev.03/ > > ?- "jdk.internal.vm.compiler" is removed from the patch. > ?- "Aes128CtsHmacSha2EType.java" is updated to "Copyright (c) 2018" > > On 12/22/19 11:24 pm, Sergey Bylokhov wrote: >> Hello. >> Please review the fix for JDK 15. >> >> Bug: https://bugs.openjdk.java.net/browse/JDK-8235975 >> Patch (2 Mb): >> http://cr.openjdk.java.net/~serb/8235975/webrev.02/open.patch >> Fix: http://cr.openjdk.java.net/~serb/8235975/webrev.02 >> >> I have updated the source code copyrights by the >> "update_copyright_year.sh" >> script for 2014/15/16/18/19 years, unfortunately, cannot run it for 2017 >> because of: "JDK-8187443: Forest Consolidation: Move files to unified >> layout" >> which touched all files. >> >> > > From Sergey.Bylokhov at oracle.com Thu Jan 2 12:02:14 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Thu, 2 Jan 2020 15:02:14 +0300 Subject: [15] Review Request: 8235975 Update copyright year to match last edit in jdk repository for 2014/15/16/17/18 In-Reply-To: <7b67e39d-752c-50a8-8e18-9a8f86bd641c@oracle.com> References: <1e7d0395-fc57-4d5b-9cfa-c33e0f6462d5@oracle.com> <3460a6f6-6178-cc45-5840-0f215eebc53f@oracle.com> <7b67e39d-752c-50a8-8e18-9a8f86bd641c@oracle.com> Message-ID: <0caab700-28e3-16e7-db00-b698557443f0@oracle.com> I guess it is too late to fix it, will need to update the files at the end of 2020. On 1/2/20 10:57 am, Erik Joelsson wrote: > Build files look good. > > /Erik > > On 2019-12-24 19:22, Sergey Bylokhov wrote: >> Hello. >> >> Here is an updated version: >> ? Bug: https://bugs.openjdk.java.net/browse/JDK-8235975 >> ? Patch (2 Mb): http://cr.openjdk.java.net/~serb/8235975/webrev.03/open.patch >> ? Fix: http://cr.openjdk.java.net/~serb/8235975/webrev.03/ >> >> ?- "jdk.internal.vm.compiler" is removed from the patch. >> ?- "Aes128CtsHmacSha2EType.java" is updated to "Copyright (c) 2018" >> >> On 12/22/19 11:24 pm, Sergey Bylokhov wrote: >>> Hello. >>> Please review the fix for JDK 15. >>> >>> Bug: https://bugs.openjdk.java.net/browse/JDK-8235975 >>> Patch (2 Mb): http://cr.openjdk.java.net/~serb/8235975/webrev.02/open.patch >>> Fix: http://cr.openjdk.java.net/~serb/8235975/webrev.02 >>> >>> I have updated the source code copyrights by the "update_copyright_year.sh" >>> script for 2014/15/16/18/19 years, unfortunately, cannot run it for 2017 >>> because of: "JDK-8187443: Forest Consolidation: Move files to unified layout" >>> which touched all files. >>> >>> >> >> -- Best regards, Sergey. From Sergey.Bylokhov at oracle.com Sat Jan 4 19:33:32 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Sat, 4 Jan 2020 22:33:32 +0300 Subject: [15] RFR JDK-8224475: JTextPane does not show images in HTML rendering In-Reply-To: <7e309a8f-c5d6-4ec1-8919-731d9c4121dd@default> References: <7e309a8f-c5d6-4ec1-8919-731d9c4121dd@default> Message-ID: <7fdcce6f-32a5-bd99-d859-73b073072c0b@oracle.com> Looks fine. On 1/2/20 10:09 am, Pankaj Bansal wrote: > Adding proper subject missed in initial mail by mistake. > > -Pankaj > > *From:*Pankaj Bansal > *Sent:* Thursday, January 2, 2020 12:34 PM > *To:* swing-dev at openjdk.java.net > *Subject:* > > Hi All, > > Please review the following test only fix for jdk15. > > > Bug: > > https://bugs.openjdk.java.net/browse/JDK-8224475 > > webrev: > > http://cr.openjdk.java.net/~pbansal/8224475/webrev00/ > > The present bug is a regression of [1], which was itself a regression of [2] which was regression of [3]. [1] has also caused one more regression, which was fixed in [4], which itself caused one regression which I have fixed in [5]. Hoping to close this regression series for good by current fix. > > The images are not being displayed properly due to improper scaling after [1] as some code was removed unnecessarily. The testcase attached in this bug exposes that issue. More details in the JBS. > > I have added the code removed unnecessarily in [1]? taking into consideration all the changes done after [1] in same code. > > I have run all the test cases added in all these bugs to ensure that no old issues are being introduced by current change. I have run the new testcase as well and it works fine with the changes. > > [1] https://bugs.openjdk.java.net/browse/JDK-8208638 > > [2] https://bugs.openjdk.java.net/browse/JDK-8206238 > > [3] https://bugs.openjdk.java.net/browse/JDK-8195095 > > [4] https://bugs.openjdk.java.net/browse/JDK-8218674 > > [5] https://bugs.openjdk.java.net/browse/JDK-8230235 > > > Regards, > Pankaj Bansal > -- Best regards, Sergey. From Sergey.Bylokhov at oracle.com Sat Jan 4 19:40:12 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Sat, 4 Jan 2020 22:40:12 +0300 Subject: RFR(S): 8234913 Improve parsing of Length Units in javax/swing/text/html/CSS In-Reply-To: References: <7F8C6B28-D791-4987-9BC3-935B752D639B@sap.com> <69110780-70f3-6518-83d8-2c018438f24a@oracle.com> Message-ID: <09f0033d-c336-8045-31ee-be5f68d6548a@oracle.com> Hi, Vladislav. The fix looks fine, but please add a copyright header to the test. > If you think that my work might be helpful, I have identified few other places, where exceptions were either improperly handled, or thrown when it can be avoided. I can improve that part as well. Such improvements are welcome. > Regarding boxing & unboxing optimizations, I followed suggestions from IntelliJ. > > Kind regards, > Vlad > > -----Original Message----- > From: Sergey Bylokhov > Sent: Dienstag, 3. Dezember 2019 01:13 > To: Volodin, Vladislav > Cc: swing-dev at openjdk.java.net > Subject: Re: RFR(S): 8234913 Improve parsing of Length Units in javax/swing/text/html/CSS > > Probably "java -verbose:class" might help? I guess after the fix > this exception should not be loaded on successful parsing of "%". > > On 12/2/19 2:38 pm, Volodin, Vladislav wrote: >> Hello Sergey, >> >> indeed I wish I can create it. The main difficulty is that the exception (when it occurs) is handled by try-catch and swallowed. So only if I turn on the debugger with ?any exception? breakpoint, I will be able to find that the execution path was wrong. >> >> I am new here, and I will appreciate if you can give me an idea how to test the exception presence? Something with reflection? E.g. count a number of NumberFormatException constructor calls? >> >> Kind regards, >> Vlad >> >> Sent from myFone >> >>> On 2. Dec 2019, at 23:24, Sergey Bylokhov wrote: >>> >>> ?Hi, Vladislav. >>> >>> Is it possible to provide an automated test for this change? >>> >>> On 11/28/19 2:08 am, Volodin, Vladislav wrote: >>>> Hello everyone, >>>> I'd like to contribute a little improvement to javax/swing/text/html/CSS. The issue is that "font-size: 100%" throws NumberFormatException for 100%, because of a wrong execution path. It is possible to reproduce the issue with the code below (but you should create Java exception breakpoints to see the place): >>>> package com.test; >>>> import javax.swing.text.MutableAttributeSet; >>>> import javax.swing.text.SimpleAttributeSet; >>>> import javax.swing.text.html.CSS; >>>> import javax.swing.text.html.StyleSheet; >>>> public class Main { >>>> ????public static void main(String[] args) { >>>> ????????StyleSheet ss = new StyleSheet(); >>>> ????????MutableAttributeSet attr = new SimpleAttributeSet(); >>>> ????????ss.addCSSAttribute(attr, CSS.Attribute.FONT_SIZE, "100%"); >>>> ????} >>>> } >>>> Bug: https://bugs.openjdk.java.net/browse/JDK-8234913 >>>> Webrev: http://cr.openjdk.java.net/~clanger/webrevs/8234913.0/ >>>> Kind regards, >>>> Vlad >>> >>> >>> -- >>> Best regards, Sergey. > > -- Best regards, Sergey. From matthias.perktold at asaon.com Sun Jan 5 08:53:19 2020 From: matthias.perktold at asaon.com (Matthias Perktold - ASA) Date: Sun, 5 Jan 2020 08:53:19 +0000 Subject: Remove System.out.println from ImageIcon.loadImage Message-ID: Hi all, In javax.swing.ImageIcon.loadImage(), there is a call to System.out.println() when loading the Image has been interrupted. In our system, this is a problem because redirect System.out to be displayed to the user to make sure no errors remain unnoticed. But in this case, the message does not really represent an error, so we should not display a message. Instead, I propose to restore the interrupt status. Best regards, Matthias Perktold -------------- next part -------------- An HTML attachment was scrubbed... URL: From Sergey.Bylokhov at oracle.com Sun Jan 5 13:33:54 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Sun, 5 Jan 2020 16:33:54 +0300 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: References: Message-ID: Hi, Matthias. I suggest to create a bug report for this issue: https://bugs.java.com/bugdatabase On 1/5/20 11:53 am, Matthias Perktold - ASA wrote: > Hi all, > > In javax.swing.ImageIcon.loadImage(), there is a call to System.out.println() when loading the Image has been interrupted. > > In our system, this is a problem because redirect System.out to be displayed to the user to make sure no errors remain unnoticed. > > But in this case, the message does not really represent an error, so we should not display a message. > > Instead, I propose to restore the interrupt status. > > Best regards, > > Matthias Perktold > -- Best regards, Sergey. From prasanta.sadhukhan at oracle.com Tue Jan 7 09:17:00 2020 From: prasanta.sadhukhan at oracle.com (Prasanta Sadhukhan) Date: Tue, 7 Jan 2020 14:47:00 +0530 Subject: [15] RFR JDK-8224475: JTextPane does not show images in HTML rendering In-Reply-To: <7e309a8f-c5d6-4ec1-8919-731d9c4121dd@default> References: <7e309a8f-c5d6-4ec1-8919-731d9c4121dd@default> Message-ID: <1effacaa-ca3f-b2a4-4c83-a71a4263a7d0@oracle.com> I guess it's not a "test only fix"? but a product fix. Also, copyright of test should be 2020 which you can change while pushing. +1 Regards Prasanta On 02-Jan-20 12:39 PM, Pankaj Bansal wrote: > > Adding proper subject missed in initial mail by mistake. > > -Pankaj > > *From:*Pankaj Bansal > *Sent:* Thursday, January 2, 2020 12:34 PM > *To:* swing-dev at openjdk.java.net > *Subject:* > > Hi All, > > Please review the following test only fix for jdk15. > > > Bug: > > https://bugs.openjdk.java.net/browse/JDK-8224475 > > webrev: > > http://cr.openjdk.java.net/~pbansal/8224475/webrev00/ > > The present bug is a regression of [1], which was itself a regression > of [2] which was regression of [3]. [1] has also caused one more > regression, which was fixed in [4], which itself caused one regression > which I have fixed in [5]. Hoping to close this regression series for > good by current fix. > > The images are not being displayed properly due to improper scaling > after [1] as some code was removed unnecessarily. The testcase > attached in this bug exposes that issue. More details in the JBS. > > I have added the code removed unnecessarily in [1]? taking into > consideration all the changes done after [1] in same code. > > I have run all the test cases added in all these bugs to ensure that > no old issues are being introduced by current change. I have run the > new testcase as well and it works fine with the changes. > > [1] https://bugs.openjdk.java.net/browse/JDK-8208638 > > [2] https://bugs.openjdk.java.net/browse/JDK-8206238 > > [3] https://bugs.openjdk.java.net/browse/JDK-8195095 > > [4] https://bugs.openjdk.java.net/browse/JDK-8218674 > > [5] https://bugs.openjdk.java.net/browse/JDK-8230235 > > > Regards, > Pankaj Bansal > -------------- next part -------------- An HTML attachment was scrubbed... URL: From christoph.langer at sap.com Wed Jan 8 15:30:20 2020 From: christoph.langer at sap.com (Langer, Christoph) Date: Wed, 8 Jan 2020 15:30:20 +0000 Subject: RFR(S): 8234913 Improve parsing of Length Units in javax/swing/text/html/CSS In-Reply-To: <09f0033d-c336-8045-31ee-be5f68d6548a@oracle.com> References: <7F8C6B28-D791-4987-9BC3-935B752D639B@sap.com> <69110780-70f3-6518-83d8-2c018438f24a@oracle.com> <09f0033d-c336-8045-31ee-be5f68d6548a@oracle.com> Message-ID: Hi, thanks for the review, Sergey. I also think this is a good change and a smart way to test it. I'll sponsor the fix and push it to the client repo with a copyright header added to the test. Cheers Christoph > -----Original Message----- > From: swing-dev On Behalf Of > Sergey Bylokhov > Sent: Samstag, 4. Januar 2020 20:40 > To: Volodin, Vladislav > Cc: swing-dev at openjdk.java.net > Subject: Re: RFR(S): 8234913 Improve parsing of Length Units in > javax/swing/text/html/CSS > > Hi, Vladislav. > > The fix looks fine, but please add a copyright header to the test. > > > If you think that my work might be helpful, I have identified few other > places, where exceptions were either improperly handled, or thrown when it > can be avoided. I can improve that part as well. > > Such improvements are welcome. > > > Regarding boxing & unboxing optimizations, I followed suggestions from > IntelliJ. > > > > Kind regards, > > Vlad > > > > -----Original Message----- > > From: Sergey Bylokhov > > Sent: Dienstag, 3. Dezember 2019 01:13 > > To: Volodin, Vladislav > > Cc: swing-dev at openjdk.java.net > > Subject: Re: RFR(S): 8234913 Improve parsing of Length Units > in javax/swing/text/html/CSS > > > > Probably "java -verbose:class" might help? I guess after the fix > > this exception should not be loaded on successful parsing of "%". > > > > On 12/2/19 2:38 pm, Volodin, Vladislav wrote: > >> Hello Sergey, > >> > >> indeed I wish I can create it. The main difficulty is that the exception > (when it occurs) is handled by try-catch and swallowed. So only if I turn on > the debugger with ?any exception? breakpoint, I will be able to find that the > execution path was wrong. > >> > >> I am new here, and I will appreciate if you can give me an idea how to test > the exception presence? Something with reflection? E.g. count a number of > NumberFormatException constructor calls? > >> > >> Kind regards, > >> Vlad > >> > >> Sent from myFone > >> > >>> On 2. Dec 2019, at 23:24, Sergey Bylokhov > wrote: > >>> > >>> ?Hi, Vladislav. > >>> > >>> Is it possible to provide an automated test for this change? > >>> > >>> On 11/28/19 2:08 am, Volodin, Vladislav wrote: > >>>> Hello everyone, > >>>> I'd like to contribute a little improvement to > javax/swing/text/html/CSS. The issue is that "font-size: 100%" throws > NumberFormatException for 100%, because of a wrong execution path. It is > possible to reproduce the issue with the code below (but you should create > Java exception breakpoints to see the place): > >>>> package com.test; > >>>> import javax.swing.text.MutableAttributeSet; > >>>> import javax.swing.text.SimpleAttributeSet; > >>>> import javax.swing.text.html.CSS; > >>>> import javax.swing.text.html.StyleSheet; > >>>> public class Main { > >>>> ????public static void main(String[] args) { > >>>> ????????StyleSheet ss = new StyleSheet(); > >>>> ????????MutableAttributeSet attr = new SimpleAttributeSet(); > >>>> ????????ss.addCSSAttribute(attr, CSS.Attribute.FONT_SIZE, "100%"); > >>>> ????} > >>>> } > >>>> Bug: https://bugs.openjdk.java.net/browse/JDK-8234913 > >>>> Webrev: http://cr.openjdk.java.net/~clanger/webrevs/8234913.0/ > >>>> Kind regards, > >>>> Vlad > >>> > >>> > >>> -- > >>> Best regards, Sergey. > > > > > > > -- > Best regards, Sergey. From tejpal.rebari at oracle.com Fri Jan 10 09:32:05 2020 From: tejpal.rebari at oracle.com (Tejpal Rebari) Date: Fri, 10 Jan 2020 15:02:05 +0530 Subject: [14] RFR JDK-8223788 - [macos] JSpinner buttons in JColorChooser dialog may capture focus using TAB Key In-Reply-To: References: <88F4F5A7-2547-468D-BC4B-D55E4F8DF1DA@oracle.com> <06ce2ef5-6e90-3c52-f2ca-27b496c18564@oracle.com> <52B7A8CC-FC9F-4D95-A702-2B57150D3F36@oracle.com> Message-ID: Hi Sergey, I had removed the colorchooser and created a frame and added two spinner to it. Then noticed that the issue is reproducible only when the ContainerOrderFocusTraversalPolicy is set. When ContainerOrderFocusTraversalPolicy is set, in JSpinner there are four components which captures focus 1)JSpinner 2)JSpinner$NumberEditor 3)JFormattedTextField 4)AquaSpinnerUI$SpinPainter In JColorChooser, SlidingSpinner is used which sets focusable property to false for 1)JSpinner and 2)JSpinner$NumberEditor So in the test I used ContainerOrderFocusTraversalPolicy and set the focusable property false for 1)JSpinner and 2)JSpinner$NumberEditor and then check that the spinpainter is capturing focus or not. Here is the updated webrev : http://cr.openjdk.java.net/~trebari/swing/8223788/webrev2/ Regards Tejpal -------------- next part -------------- An HTML attachment was scrubbed... URL: From Sergey.Bylokhov at oracle.com Sun Jan 12 19:45:19 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Sun, 12 Jan 2020 11:45:19 -0800 Subject: [14] RFR JDK-8223788 - [macos] JSpinner buttons in JColorChooser dialog may capture focus using TAB Key In-Reply-To: References: <88F4F5A7-2547-468D-BC4B-D55E4F8DF1DA@oracle.com> <06ce2ef5-6e90-3c52-f2ca-27b496c18564@oracle.com> <52B7A8CC-FC9F-4D95-A702-2B57150D3F36@oracle.com> Message-ID: Hi, Tejpal Small note that "editor2.getTextField().isFocusOwner()" should be called on EDT, it is a Swing component. On 1/10/20 1:32 am, Tejpal Rebari wrote: > Hi Sergey, > I had removed the colorchooser and created a frame and added two spinner to it. > Then noticed that the issue is reproducible only when the ContainerOrderFocusTraversalPolicyis set. > WhenContainerOrderFocusTraversalPolicy is set, in JSpinner there are four components which captures focus > 1)JSpinner > 2)JSpinner$NumberEditor > 3)JFormattedTextField > 4)AquaSpinnerUI$SpinPainter > > In JColorChooser, SlidingSpinner is used which sets focusable property to false for1)JSpinner and 2)JSpinner$NumberEditor > > So in the test I usedContainerOrderFocusTraversalPolicy and set the focusable property false for 1)JSpinner and 2)JSpinner$NumberEditor and then?check that the?spinpainter is?capturing focus or not. > > Here is the updated webrev:http://cr.openjdk.java.net/~trebari/swing/8223788/webrev2/ > > Regards > Tejpal > > -- Best regards, Sergey. From tejpal.rebari at oracle.com Mon Jan 13 06:32:14 2020 From: tejpal.rebari at oracle.com (Tejpal Rebari) Date: Mon, 13 Jan 2020 12:02:14 +0530 Subject: [14] RFR JDK-8223788 - [macos] JSpinner buttons in JColorChooser dialog may capture focus using TAB Key In-Reply-To: References: <88F4F5A7-2547-468D-BC4B-D55E4F8DF1DA@oracle.com> <06ce2ef5-6e90-3c52-f2ca-27b496c18564@oracle.com> <52B7A8CC-FC9F-4D95-A702-2B57150D3F36@oracle.com> Message-ID: <55AB2E7D-02CB-43A2-A972-9A64F1BD4265@oracle.com> Hi Sergey, > On 13-Jan-2020, at 1:15 AM, Sergey Bylokhov wrote: > > Hi, Tejpal > > Small note that "editor2.getTextField().isFocusOwner()" should be called on EDT, it is a Swing component. I have modified the test. webrev : http://cr.openjdk.java.net/~trebari/swing/8223788/webrev3/ regards Tejpal > > On 1/10/20 1:32 am, Tejpal Rebari wrote: >> Hi Sergey, >> I had removed the colorchooser and created a frame and added two spinner to it. >> Then noticed that the issue is reproducible only when the ContainerOrderFocusTraversalPolicyis set. >> WhenContainerOrderFocusTraversalPolicy is set, in JSpinner there are four components which captures focus >> 1)JSpinner >> 2)JSpinner$NumberEditor >> 3)JFormattedTextField >> 4)AquaSpinnerUI$SpinPainter >> In JColorChooser, SlidingSpinner is used which sets focusable property to false for1)JSpinner and 2)JSpinner$NumberEditor >> So in the test I usedContainerOrderFocusTraversalPolicy and set the focusable property false for 1)JSpinner and 2)JSpinner$NumberEditor and then check that the spinpainter is capturing focus or not. >> Here is the updated webrev:http://cr.openjdk.java.net/~trebari/swing/8223788/webrev2/ >> Regards >> Tejpal > > > -- > Best regards, Sergey. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Sergey.Bylokhov at oracle.com Mon Jan 13 06:46:43 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Sun, 12 Jan 2020 22:46:43 -0800 Subject: [14] RFR JDK-8223788 - [macos] JSpinner buttons in JColorChooser dialog may capture focus using TAB Key In-Reply-To: <55AB2E7D-02CB-43A2-A972-9A64F1BD4265@oracle.com> References: <88F4F5A7-2547-468D-BC4B-D55E4F8DF1DA@oracle.com> <06ce2ef5-6e90-3c52-f2ca-27b496c18564@oracle.com> <52B7A8CC-FC9F-4D95-A702-2B57150D3F36@oracle.com> <55AB2E7D-02CB-43A2-A972-9A64F1BD4265@oracle.com> Message-ID: <868b3bcd-98c7-3656-8780-448f5268f06a@oracle.com> Looks fine. On 1/12/20 10:32 pm, Tejpal Rebari wrote: > Hi Sergey, > >> On 13-Jan-2020, at 1:15 AM, Sergey Bylokhov > wrote: >> >> Hi, Tejpal >> >> Small note that "editor2.getTextField().isFocusOwner()" should be called on EDT, it is a Swing component. > > I have modified the test. > webrev : http://cr.openjdk.java.net/~trebari/swing/8223788/webrev3/ > > regards > Tejpal > >> >> On 1/10/20 1:32 am, Tejpal Rebari wrote: >>> Hi Sergey, >>> I had removed the colorchooser and created a frame and added two spinner to it. >>> Then noticed that the issue is reproducible only when the ContainerOrderFocusTraversalPolicyis set. >>> WhenContainerOrderFocusTraversalPolicy is set, in JSpinner there are four components which captures focus >>> 1)JSpinner >>> 2)JSpinner$NumberEditor >>> 3)JFormattedTextField >>> 4)AquaSpinnerUI$SpinPainter >>> In JColorChooser, SlidingSpinner is used which sets focusable property to false for1)JSpinner and 2)JSpinner$NumberEditor >>> So in the test I usedContainerOrderFocusTraversalPolicy and set the focusable property false for 1)JSpinner and 2)JSpinner$NumberEditor and then?check that the?spinpainter is?capturing focus or not. >>> Here is the updated webrev:http://cr.openjdk.java.net/~trebari/swing/8223788/webrev2/ >>> Regards >>> Tejpal >> >> >> -- >> Best regards, Sergey. > -- Best regards, Sergey. From pankaj.b.bansal at oracle.com Mon Jan 13 07:20:31 2020 From: pankaj.b.bansal at oracle.com (Pankaj Bansal) Date: Sun, 12 Jan 2020 23:20:31 -0800 (PST) Subject: [14] RFR JDK-8223788 - [macos] JSpinner buttons in JColorChooser dialog may capture focus using TAB Key In-Reply-To: <868b3bcd-98c7-3656-8780-448f5268f06a@oracle.com> References: <88F4F5A7-2547-468D-BC4B-D55E4F8DF1DA@oracle.com> <06ce2ef5-6e90-3c52-f2ca-27b496c18564@oracle.com> <52B7A8CC-FC9F-4D95-A702-2B57150D3F36@oracle.com> <55AB2E7D-02CB-43A2-A972-9A64F1BD4265@oracle.com> <868b3bcd-98c7-3656-8780-448f5268f06a@oracle.com> Message-ID: <995ce446-9e14-4009-b8fa-3fe489a9584c@default> Hello Tejpal, I have few minor comments. You can fix them before pushing this fix. 1. Import individual packages instead of import javax.swing.*. 2. You don't need to create editor1 variable. 3. There should be space after comma editor1,editor2. 4. Rename variables JTextField_Focus_Status, LF according to rules. Regards, Pankaj -----Original Message----- From: Sergey Bylokhov Sent: Monday, January 13, 2020 12:17 PM To: Tejpal Rebari Cc: swing-dev at openjdk.java.net Subject: Re: [14] RFR JDK-8223788 - [macos] JSpinner buttons in JColorChooser dialog may capture focus using TAB Key Looks fine. On 1/12/20 10:32 pm, Tejpal Rebari wrote: > Hi Sergey, > >> On 13-Jan-2020, at 1:15 AM, Sergey Bylokhov > wrote: >> >> Hi, Tejpal >> >> Small note that "editor2.getTextField().isFocusOwner()" should be called on EDT, it is a Swing component. > > I have modified the test. > webrev : http://cr.openjdk.java.net/~trebari/swing/8223788/webrev3/ > > regards > Tejpal > >> >> On 1/10/20 1:32 am, Tejpal Rebari wrote: >>> Hi Sergey, >>> I had removed the colorchooser and created a frame and added two spinner to it. >>> Then noticed that the issue is reproducible only when the ContainerOrderFocusTraversalPolicyis set. >>> WhenContainerOrderFocusTraversalPolicy is set, in JSpinner there are >>> four components which captures focus 1)JSpinner >>> 2)JSpinner$NumberEditor 3)JFormattedTextField >>> 4)AquaSpinnerUI$SpinPainter In JColorChooser, SlidingSpinner is used >>> which sets focusable property to false for1)JSpinner and >>> 2)JSpinner$NumberEditor So in the test I usedContainerOrderFocusTraversalPolicy and set the focusable property false for 1)JSpinner and 2)JSpinner$NumberEditor and then?check that the?spinpainter is?capturing focus or not. >>> Here is the updated >>> webrev:http://cr.openjdk.java.net/~trebari/swing/8223788/webrev2/ >>> Regards >>> Tejpal >> >> >> -- >> Best regards, Sergey. > -- Best regards, Sergey. From sureshkumar.mahaliswamy at oracle.com Tue Jan 14 06:49:07 2020 From: sureshkumar.mahaliswamy at oracle.com (Sureshkumar Mahaliswamy) Date: Mon, 13 Jan 2020 22:49:07 -0800 (PST) Subject: RFR : [15] : 8235900 : PopupMenu Opaque property is not reflecting the Parents property on MAC OS In-Reply-To: References: <8f7b190d-9c9d-4474-bb80-8ea6fc9ab07f@default> Message-ID: Hi Sergey, Thanks for the comments. I have removed the annotation that ignores the macOS completely and added a check to ignore the validations for Aqua LAF only. The LookandFeel parameter is normally set as part of the test execution as VM arguments, hence not looping through all the available LAF. Kindly review and let me know if there are any comments. JBS:https://bugs.openjdk.java.net/browse/JDK-8235900 Webrev: http://cr.openjdk.java.net/~nnigam/8235900/webrev.1/ Testing: tested with jtreg on mac and other platforms. Thanks, Suresh. -----Original Message----- From: Sergey Bylokhov Sent: Monday, December 23, 2019 12:43 AM To: Sureshkumar Mahaliswamy ; swing-dev at openjdk.java.net Subject: Re: RFR : [15] : 8235900 : PopupMenu Opaque property is not reflecting the Parents property on MAC OS Hi, Sureshkumar. Probably it will be better to do something instead of completely disabling the test. The problem exists in Aqua, but we can test some other L&F on macOS. I guess the best solution is to iterate over all installed L&fs, but exclude Aqua. On 12/17/19 11:55 am, Sureshkumar Mahaliswamy wrote: > Hi All, > > Kindly review the small patch. > > Added the annotation @requires(os.family!=mac) to ignore the test execution on MAC,since Aqua LaF forces all popups to be heavyweight. > > Marking this test not to be executed for MAC platform. > > JBS:https://bugs.openjdk.java.net/browse/JDK-8235900 > > Webrev: http://cr.openjdk.java.net/~nnigam/8235900/webrev.0/ > > Testing: tested with jtreg. > > Thanks, > > Suresh. > -- Best regards, Sergey. From jason_mehrens at hotmail.com Tue Jan 14 20:58:46 2020 From: jason_mehrens at hotmail.com (Jason Mehrens) Date: Tue, 14 Jan 2020 20:58:46 +0000 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: References: , Message-ID: This was the bug id when I reported it: https://bugs.openjdk.java.net/browse/JDK-6421373 Notice it was closed as will not fix. I think that is incorrect but, I'm biased :) Jason ________________________________________ From: swing-dev on behalf of Sergey Bylokhov Sent: Sunday, January 5, 2020 7:33 AM To: swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage Hi, Matthias. I suggest to create a bug report for this issue: https://bugs.java.com/bugdatabase On 1/5/20 11:53 am, Matthias Perktold - ASA wrote: > Hi all, > > In javax.swing.ImageIcon.loadImage(), there is a call to System.out.println() when loading the Image has been interrupted. > > In our system, this is a problem because redirect System.out to be displayed to the user to make sure no errors remain unnoticed. > > But in this case, the message does not really represent an error, so we should not display a message. > > Instead, I propose to restore the interrupt status. > > Best regards, > > Matthias Perktold > -- Best regards, Sergey. From vladislav.volodin at sap.com Thu Jan 16 15:05:43 2020 From: vladislav.volodin at sap.com (Volodin, Vladislav) Date: Thu, 16 Jan 2020 15:05:43 +0000 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: References: , Message-ID: Hello Jason (and everyone), I have studied the code a little, and found out that this logging doesn't give any significant benefits to the functionality. It seems that either it can be removed, or replaced with a better logging handling. I went through different parts in the code, and I found out that there is AbstractButton, where InterruptedException is handled silently. Nothing is logged anywhere. On the opposite side, there are classes where PlatformLogger is used for logging. If people in this distribution list agree, I can start working on a simple fix and either remove the logging (System.out.println), or replace it with PlatformLogger. I guess the second solution sounds better, but I don't know what is the better way to write a test-case for it. Kind regards, Vlad -----Original Message----- From: swing-dev On Behalf Of Jason Mehrens Sent: Dienstag, 14. Januar 2020 21:59 To: Sergey Bylokhov ; swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage This was the bug id when I reported it: https://bugs.openjdk.java.net/browse/JDK-6421373 Notice it was closed as will not fix. I think that is incorrect but, I'm biased :) Jason ________________________________________ From: swing-dev on behalf of Sergey Bylokhov Sent: Sunday, January 5, 2020 7:33 AM To: swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage Hi, Matthias. I suggest to create a bug report for this issue: https://bugs.java.com/bugdatabase On 1/5/20 11:53 am, Matthias Perktold - ASA wrote: > Hi all, > > In javax.swing.ImageIcon.loadImage(), there is a call to System.out.println() when loading the Image has been interrupted. > > In our system, this is a problem because redirect System.out to be displayed to the user to make sure no errors remain unnoticed. > > But in this case, the message does not really represent an error, so we should not display a message. > > Instead, I propose to restore the interrupt status. > > Best regards, > > Matthias Perktold > -- Best regards, Sergey. From Sergey.Bylokhov at oracle.com Mon Jan 20 03:31:54 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Sun, 19 Jan 2020 19:31:54 -0800 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: References: Message-ID: I guess there are no objections, probably the best way to fix it is to drop the System.out.println and set interrupted flag. On 1/16/20 7:05 am, Volodin, Vladislav wrote: > If people in this distribution list agree, I can start working on a simple fix and either remove the logging (System.out.println), or replace it with PlatformLogger. I guess the second solution sounds better, but I don't know what is the better way to write a test-case for it. -- Best regards, Sergey. From Sergey.Bylokhov at oracle.com Mon Jan 20 03:34:21 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Sun, 19 Jan 2020 19:34:21 -0800 Subject: RFR : [15] : 8235900 : PopupMenu Opaque property is not reflecting the Parents property on MAC OS In-Reply-To: References: <8f7b190d-9c9d-4474-bb80-8ea6fc9ab07f@default> Message-ID: <0805b3a6-9979-111b-a9a2-a6d44d1e6bfa@oracle.com> On 1/13/20 10:49 pm, Sureshkumar Mahaliswamy wrote: > The LookandFeel parameter is normally set as part of the test execution as VM arguments, > hence not looping through all the available LAF. This parameter is rarely set, actually never set when the tests are executed via mach5, I suggest to iterate over the list of L&F in the test since we know that its behavior can depend on them. > > Kindly review and let me know if there are any comments. > > JBS:https://bugs.openjdk.java.net/browse/JDK-8235900 > > Webrev: http://cr.openjdk.java.net/~nnigam/8235900/webrev.1/ > > Testing: tested with jtreg on mac and other platforms. > Thanks, > Suresh. > > > -----Original Message----- > From: Sergey Bylokhov > Sent: Monday, December 23, 2019 12:43 AM > To: Sureshkumar Mahaliswamy ; swing-dev at openjdk.java.net > Subject: Re: RFR : [15] : 8235900 : PopupMenu Opaque property is not reflecting the Parents property on MAC OS > > Hi, Sureshkumar. > > Probably it will be better to do something instead of completely disabling the test. The problem exists in Aqua, but we can test some other L&F on macOS. > I guess the best solution is to iterate over all installed L&fs, but exclude Aqua. > > On 12/17/19 11:55 am, Sureshkumar Mahaliswamy wrote: >> Hi All, >> >> Kindly review the small patch. >> >> Added the annotation @requires(os.family!=mac) to ignore the test execution on MAC,since Aqua LaF forces all popups to be heavyweight. >> >> Marking this test not to be executed for MAC platform. >> >> JBS:https://bugs.openjdk.java.net/browse/JDK-8235900 >> >> Webrev: http://cr.openjdk.java.net/~nnigam/8235900/webrev.0/ >> >> Testing: tested with jtreg. >> >> Thanks, >> >> Suresh. >> > > > -- > Best regards, Sergey. > -- Best regards, Sergey. From Sergey.Bylokhov at oracle.com Mon Jan 20 03:44:17 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Sun, 19 Jan 2020 19:44:17 -0800 Subject: RFR : [15] : 8235900 : PopupMenu Opaque property is not reflecting the Parents property on MAC OS In-Reply-To: <0805b3a6-9979-111b-a9a2-a6d44d1e6bfa@oracle.com> References: <8f7b190d-9c9d-4474-bb80-8ea6fc9ab07f@default> <0805b3a6-9979-111b-a9a2-a6d44d1e6bfa@oracle.com> Message-ID: On 1/19/20 7:34 pm, Sergey Bylokhov wrote: > On 1/13/20 10:49 pm, Sureshkumar Mahaliswamy wrote: >> The LookandFeel parameter is normally set as part of the test execution as VM arguments, >> hence not looping through all the available LAF. > > This parameter is rarely set, actually never set when the tests are executed > via mach5, I suggest to iterate over the list of L&F in the test since we > know that its behavior can depend on them. Or probably we need to try to load the image again because of the spec of the method state this: "Loads the image, returning only when the image is loaded." > >> >> Kindly review and let me know if there are any comments. >> >> JBS:https://bugs.openjdk.java.net/browse/JDK-8235900 >> >> Webrev: http://cr.openjdk.java.net/~nnigam/8235900/webrev.1/ >> Testing: tested with jtreg on mac and other platforms. >> Thanks, >> Suresh. >> >> >> -----Original Message----- >> From: Sergey Bylokhov >> Sent: Monday, December 23, 2019 12:43 AM >> To: Sureshkumar Mahaliswamy ; swing-dev at openjdk.java.net >> Subject: Re: RFR : [15] : 8235900 : PopupMenu Opaque property is not reflecting the Parents property on MAC OS >> >> Hi, Sureshkumar. >> >> Probably it will be better to do something instead of completely disabling the test. The problem exists in Aqua, but we can test some other L&F on macOS. >> I guess the best solution is to iterate over all installed L&fs, but exclude Aqua. >> >> On 12/17/19 11:55 am, Sureshkumar Mahaliswamy wrote: >>> Hi All, >>> >>> Kindly review the small patch. >>> >>> Added the annotation @requires(os.family!=mac) to ignore the test execution on MAC,since Aqua LaF forces all popups to be heavyweight. >>> >>> Marking this test not to be executed for MAC platform. >>> >>> JBS:https://bugs.openjdk.java.net/browse/JDK-8235900 >>> >>> Webrev: http://cr.openjdk.java.net/~nnigam/8235900/webrev.0/ >>> >>> Testing: tested with jtreg. >>> >>> Thanks, >>> >>> Suresh. >>> >> >> >> -- >> Best regards, Sergey. >> > > -- Best regards, Sergey. From sureshkumar.mahaliswamy at oracle.com Tue Jan 21 10:13:46 2020 From: sureshkumar.mahaliswamy at oracle.com (Sureshkumar Mahaliswamy) Date: Tue, 21 Jan 2020 02:13:46 -0800 (PST) Subject: RFR : [15] : 8235900 : PopupMenu Opaque property is not reflecting the Parents property on MAC OS In-Reply-To: <0805b3a6-9979-111b-a9a2-a6d44d1e6bfa@oracle.com> References: <8f7b190d-9c9d-4474-bb80-8ea6fc9ab07f@default> <0805b3a6-9979-111b-a9a2-a6d44d1e6bfa@oracle.com> Message-ID: <67d8b4c4-1ae2-4f73-a4a1-a851a708c7aa@default> Hi Sergey, I have modified the test to iterate over all the installed look and feel, but excluding aqua. JBS:https://bugs.openjdk.java.net/browse/JDK-8235900 Webrev: http://cr.openjdk.java.net/~nnigam/8235900/webrev.2/ Testing: tested with jtreg. Kindly review and let me know your thoughts. Thanks, Suresh. -----Original Message----- From: Sergey Bylokhov Sent: Monday, January 20, 2020 9:04 AM To: Sureshkumar Mahaliswamy ; swing-dev at openjdk.java.net Subject: Re: RFR : [15] : 8235900 : PopupMenu Opaque property is not reflecting the Parents property on MAC OS On 1/13/20 10:49 pm, Sureshkumar Mahaliswamy wrote: > The LookandFeel parameter is normally set as part of the test > execution as VM arguments, hence not looping through all the available LAF. This parameter is rarely set, actually never set when the tests are executed via mach5, I suggest to iterate over the list of L&F in the test since we know that its behavior can depend on them. > > Kindly review and let me know if there are any comments. > > JBS:https://bugs.openjdk.java.net/browse/JDK-8235900 > > Webrev: http://cr.openjdk.java.net/~nnigam/8235900/webrev.1/ > > Testing: tested with jtreg on mac and other platforms. > Thanks, > Suresh. > > > -----Original Message----- > From: Sergey Bylokhov > Sent: Monday, December 23, 2019 12:43 AM > To: Sureshkumar Mahaliswamy ; > swing-dev at openjdk.java.net > Subject: Re: RFR : [15] : 8235900 : PopupMenu Opaque > property is not reflecting the Parents property on MAC OS > > Hi, Sureshkumar. > > Probably it will be better to do something instead of completely disabling the test. The problem exists in Aqua, but we can test some other L&F on macOS. > I guess the best solution is to iterate over all installed L&fs, but exclude Aqua. > > On 12/17/19 11:55 am, Sureshkumar Mahaliswamy wrote: >> Hi All, >> >> Kindly review the small patch. >> >> Added the annotation @requires(os.family!=mac) to ignore the test execution on MAC,since Aqua LaF forces all popups to be heavyweight. >> >> Marking this test not to be executed for MAC platform. >> >> JBS:https://bugs.openjdk.java.net/browse/JDK-8235900 >> >> Webrev: http://cr.openjdk.java.net/~nnigam/8235900/webrev.0/ >> >> Testing: tested with jtreg. >> >> Thanks, >> >> Suresh. >> > > > -- > Best regards, Sergey. > -- Best regards, Sergey. From jason_mehrens at hotmail.com Tue Jan 21 20:26:08 2020 From: jason_mehrens at hotmail.com (Jason Mehrens) Date: Tue, 21 Jan 2020 20:26:08 +0000 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: References: , Message-ID: +1 for Sergey suggestion. ________________________________________ From: Sergey Bylokhov Sent: Sunday, January 19, 2020 9:31 PM To: Volodin, Vladislav; Jason Mehrens Cc: swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage I guess there are no objections, probably the best way to fix it is to drop the System.out.println and set interrupted flag. On 1/16/20 7:05 am, Volodin, Vladislav wrote: > If people in this distribution list agree, I can start working on a simple fix and either remove the logging (System.out.println), or replace it with PlatformLogger. I guess the second solution sounds better, but I don't know what is the better way to write a test-case for it. -- Best regards, Sergey. From Sergey.Bylokhov at oracle.com Tue Jan 21 20:55:28 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Tue, 21 Jan 2020 12:55:28 -0800 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: References: Message-ID: On 1/21/20 12:26 pm, Jason Mehrens wrote: > +1 for Sergey suggestion. Or probably we need to try to load the image again because of the spec of the method state this: "Loads the image, returning only when the image is loaded." > > ________________________________________ > From: Sergey Bylokhov > Sent: Sunday, January 19, 2020 9:31 PM > To: Volodin, Vladislav; Jason Mehrens > Cc: swing-dev at openjdk.java.net > Subject: Re: Remove System.out.println from ImageIcon.loadImage > > I guess there are no objections, probably the best way to fix > it is to drop the System.out.println and set interrupted flag. > > On 1/16/20 7:05 am, Volodin, Vladislav wrote: >> If people in this distribution list agree, I can start working on a simple fix and either remove the logging (System.out.println), or replace it with PlatformLogger. I guess the second solution sounds better, but I don't know what is the better way to write a test-case for it. > > > -- > Best regards, Sergey. > -- Best regards, Sergey. From Sergey.Bylokhov at oracle.com Tue Jan 21 20:58:19 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Tue, 21 Jan 2020 12:58:19 -0800 Subject: RFR : [15] : 8235900 : PopupMenu Opaque property is not reflecting the Parents property on MAC OS In-Reply-To: <67d8b4c4-1ae2-4f73-a4a1-a851a708c7aa@default> References: <8f7b190d-9c9d-4474-bb80-8ea6fc9ab07f@default> <0805b3a6-9979-111b-a9a2-a6d44d1e6bfa@oracle.com> <67d8b4c4-1ae2-4f73-a4a1-a851a708c7aa@default> Message-ID: <19212bec-fd69-6563-ca68-c1befffce785@oracle.com> Looks fine, please split the long lines before the push, we use (at least try to use) 80 chars per line. On 1/21/20 2:13 am, Sureshkumar Mahaliswamy wrote: > Hi Sergey, > > I have modified the test to iterate over all the installed look and feel, but excluding aqua. > > JBS:https://bugs.openjdk.java.net/browse/JDK-8235900 > Webrev: http://cr.openjdk.java.net/~nnigam/8235900/webrev.2/ > > Testing: tested with jtreg. > > Kindly review and let me know your thoughts. > > Thanks, > Suresh. > > -----Original Message----- > From: Sergey Bylokhov > Sent: Monday, January 20, 2020 9:04 AM > To: Sureshkumar Mahaliswamy ; swing-dev at openjdk.java.net > Subject: Re: RFR : [15] : 8235900 : PopupMenu Opaque property is not reflecting the Parents property on MAC OS > On 1/13/20 10:49 pm, Sureshkumar Mahaliswamy wrote: >> The LookandFeel parameter is normally set as part of the test >> execution as VM arguments, hence not looping through all the available LAF. > > This parameter is rarely set, actually never set when the tests are executed via mach5, I suggest to iterate over the list of L&F in the test since we know that its behavior can depend on them. > >> >> Kindly review and let me know if there are any comments. >> >> JBS:https://bugs.openjdk.java.net/browse/JDK-8235900 >> >> Webrev: http://cr.openjdk.java.net/~nnigam/8235900/webrev.1/ >> >> Testing: tested with jtreg on mac and other platforms. >> Thanks, >> Suresh. >> >> >> -----Original Message----- >> From: Sergey Bylokhov >> Sent: Monday, December 23, 2019 12:43 AM >> To: Sureshkumar Mahaliswamy ; >> swing-dev at openjdk.java.net >> Subject: Re: RFR : [15] : 8235900 : PopupMenu Opaque >> property is not reflecting the Parents property on MAC OS >> >> Hi, Sureshkumar. >> >> Probably it will be better to do something instead of completely disabling the test. The problem exists in Aqua, but we can test some other L&F on macOS. >> I guess the best solution is to iterate over all installed L&fs, but exclude Aqua. >> >> On 12/17/19 11:55 am, Sureshkumar Mahaliswamy wrote: >>> Hi All, >>> >>> Kindly review the small patch. >>> >>> Added the annotation @requires(os.family!=mac) to ignore the test execution on MAC,since Aqua LaF forces all popups to be heavyweight. >>> >>> Marking this test not to be executed for MAC platform. >>> >>> JBS:https://bugs.openjdk.java.net/browse/JDK-8235900 >>> >>> Webrev: http://cr.openjdk.java.net/~nnigam/8235900/webrev.0/ >>> >>> Testing: tested with jtreg. >>> >>> Thanks, >>> >>> Suresh. >>> >> >> >> -- >> Best regards, Sergey. >> > > > -- > Best regards, Sergey. > -- Best regards, Sergey. From vladislav.volodin at sap.com Tue Jan 21 21:14:17 2020 From: vladislav.volodin at sap.com (Volodin, Vladislav) Date: Tue, 21 Jan 2020 21:14:17 +0000 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: References: , Message-ID: <2310F0FD-DAA6-4E24-85AD-776D6F979CC0@sap.com> Hi all, If I am not mistaken, this method is called from the constructor and other methods. How long should we try loading the icon using the unmanaged (by any thread pool, but I am not sure about this statement) thread? We don?t even have the flag ?interrupted?. So technically this icon has to be loaded. Thanks, Vlad Sent from myFone On 21. Jan 2020, at 21:55, Sergey Bylokhov wrote: ?On 1/21/20 12:26 pm, Jason Mehrens wrote: +1 for Sergey suggestion. Or probably we need to try to load the image again because of the spec of the method state this: "Loads the image, returning only when the image is loaded." ________________________________________ From: Sergey Bylokhov Sent: Sunday, January 19, 2020 9:31 PM To: Volodin, Vladislav; Jason Mehrens Cc: swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage I guess there are no objections, probably the best way to fix it is to drop the System.out.println and set interrupted flag. On 1/16/20 7:05 am, Volodin, Vladislav wrote: If people in this distribution list agree, I can start working on a simple fix and either remove the logging (System.out.println), or replace it with PlatformLogger. I guess the second solution sounds better, but I don't know what is the better way to write a test-case for it. -- Best regards, Sergey. -- Best regards, Sergey. -------------- next part -------------- An HTML attachment was scrubbed... URL: From Sergey.Bylokhov at oracle.com Tue Jan 21 21:26:04 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Tue, 21 Jan 2020 13:26:04 -0800 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: <2310F0FD-DAA6-4E24-85AD-776D6F979CC0@sap.com> References: <2310F0FD-DAA6-4E24-85AD-776D6F979CC0@sap.com> Message-ID: <549622d0-fe72-f267-c105-53b1399471dc@oracle.com> On 1/21/20 1:14 pm, Volodin, Vladislav wrote: > Hi all, > > If I am not mistaken, this method is called from the constructor and other methods. How long should we try loading the icon using the unmanaged (by any thread pool, but I am not sure about this statement) thread? > > We don?t even have the flag ?interrupted?. So technically this icon has to be loaded. I think it is necessary to save the "interrupted" state in the catch block and try to call waitForID() again. It will be necessary to set "interrupted" flag for the Thread after that(when the waitForID will return without exception). > Sent from myFone > >> On 21. Jan 2020, at 21:55, Sergey Bylokhov wrote: >> >> ?On 1/21/20 12:26 pm, Jason Mehrens wrote: >>> +1 for Sergey suggestion. >> >> Or probably we need to try to load the image again because of the spec of the method state this: >> "Loads the image, returning only when the image is loaded." >> >>> ________________________________________ >>> From: Sergey Bylokhov >>> Sent: Sunday, January 19, 2020 9:31 PM >>> To: Volodin, Vladislav; Jason Mehrens >>> Cc: swing-dev at openjdk.java.net >>> Subject: Re: Remove System.out.println from ImageIcon.loadImage >>> I guess there are no objections, probably the best way to fix >>> it is to drop the System.out.println and set interrupted flag. >>> On 1/16/20 7:05 am, Volodin, Vladislav wrote: >>>> If people in this distribution list agree, I can start working on a simple fix and either remove the logging (System.out.println), or replace it with PlatformLogger. I guess the second solution sounds better, but I don't know what is the better way to write a test-case for it. >>> -- >>> Best regards, Sergey. >> >> >> -- >> Best regards, Sergey. -- Best regards, Sergey. From Sergey.Bylokhov at oracle.com Thu Jan 23 00:35:31 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Wed, 22 Jan 2020 16:35:31 -0800 Subject: [15] Review Request: 8237746 Fixing compiler warnings in src/demo/share/jfc Message-ID: Hello. Please review the fix for compiler warnings in the demo/jfc in JDK 15. Bug: https://bugs.openjdk.java.net/browse/JDK-8237746 Fix: http://cr.openjdk.java.net/~serb/8237746/webrev.00 This fix contributed by the Marc Hoffmann: https://mail.openjdk.java.net/pipermail/swing-dev/2019-October/009846.html Fixed warnings: raw types, deprecated APIs, deprecated Applet APIs. -- Best regards, Sergey. From hoffmann at mountainminds.com Thu Jan 23 08:54:38 2020 From: hoffmann at mountainminds.com (Marc Hoffmann) Date: Thu, 23 Jan 2020 09:54:38 +0100 Subject: [15] Review Request: 8237746 Fixing compiler warnings in src/demo/share/jfc In-Reply-To: References: Message-ID: Hi Sergey, thanks for sponsoring this patch! I successfully applied the webrev patch on current JDK head (57807:7bae17e00566). The build runs without warnings on the demo code :) But I noticed a minor glitch: I inserted a tab in src/demo/share/jfc/SwingSet2/DirectionPanel.java Line 97 where only spaces are used in the rest of the file. Probably this should be fixed before merge. Regards, -marc > On 23. Jan 2020, at 01:35, Sergey Bylokhov wrote: > > Hello. > Please review the fix for compiler warnings in the demo/jfc in JDK 15. > > Bug: https://bugs.openjdk.java.net/browse/JDK-8237746 > Fix: http://cr.openjdk.java.net/~serb/8237746/webrev.00 > > This fix contributed by the Marc Hoffmann: > https://mail.openjdk.java.net/pipermail/swing-dev/2019-October/009846.html > > Fixed warnings: raw types, deprecated APIs, deprecated Applet APIs. > > -- > Best regards, Sergey. From pankaj.b.bansal at oracle.com Thu Jan 23 11:05:09 2020 From: pankaj.b.bansal at oracle.com (Pankaj Bansal) Date: Thu, 23 Jan 2020 03:05:09 -0800 (PST) Subject: [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition Message-ID: <90cea53e-117d-4252-86d7-7d7b2163d6f3@default> Hi All, Please review the following fix for jdk15. Bug: https://bugs.openjdk.java.net/browse/JDK-8216329 webrev: http://cr.openjdk.java.net/~pbansal/8216329/webrev00/ Issue: The JCheckBoxMenuItem is not being resized properly when setHorizontalTextPosition is called on it. This results in some text getting truncated from the end. The issue is specific to Synth L&F. Cause: The present bug is a regression of [1]. Fix: The problem in [1] was specific to Windows L&F. but the fix was done in BasicMenuItemUI which is shared by all the L&F. The current fix moves the fix done for [1] to Windows L&F specific code. This fixes the current issue. I have run the tests that was added for [1]. All works fine. [1] https://bugs.openjdk.java.net/browse/JDK-8152981 Regards, Pankaj Bansal -------------- next part -------------- An HTML attachment was scrubbed... URL: From Sergey.Bylokhov at oracle.com Fri Jan 24 00:25:22 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Thu, 23 Jan 2020 16:25:22 -0800 Subject: [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition In-Reply-To: <90cea53e-117d-4252-86d7-7d7b2163d6f3@default> References: <90cea53e-117d-4252-86d7-7d7b2163d6f3@default> Message-ID: <37805088-6e0e-5b39-44fd-3fdc6d5f89b0@oracle.com> Hi, Pankaj. The updateCheckIcon() was a private method in the public class from the javax.swing.plaf.basic package you cannot simply make it protected. Can you please provide some more details why the call to updateCheckIcon() break the resize? On 1/23/20 3:05 am, Pankaj Bansal wrote: > Hi All, > > Please review the following fix for jdk15. > > > Bug: > > https://bugs.openjdk.java.net/browse/JDK-8216329 > > webrev: > > http://cr.openjdk.java.net/~pbansal/8216329/webrev00/ > > Issue: > > The JCheckBoxMenuItem is not being resized properly when setHorizontalTextPosition is called on it. This results in some text getting truncated from the end. The issue is specific to Synth L&F. > > Cause: > > The present bug is a regression of [1]. > > Fix: > > The problem in [1] was specific to Windows L&F. but the fix was done in BasicMenuItemUI which is shared by all the L&F. The current fix moves the fix done for [1] to Windows L&F specific code. This fixes the current issue. I have run the tests that was added for [1]. All works fine. > > [1] https://bugs.openjdk.java.net/browse/JDK-8152981 > > > Regards, > Pankaj Bansal > -- Best regards, Sergey. From pankaj.b.bansal at oracle.com Mon Jan 27 06:33:45 2020 From: pankaj.b.bansal at oracle.com (Pankaj Bansal) Date: Sun, 26 Jan 2020 22:33:45 -0800 (PST) Subject: [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition In-Reply-To: <37805088-6e0e-5b39-44fd-3fdc6d5f89b0@oracle.com> References: <90cea53e-117d-4252-86d7-7d7b2163d6f3@default> <37805088-6e0e-5b39-44fd-3fdc6d5f89b0@oracle.com> Message-ID: <03c19198-abc0-4b5d-8430-147d6c2b0e11@default> Hello Sergey, << The updateCheckIcon() was a private method in the public class from the javax.swing.plaf.basic package you cannot simply make it protected. The updateCheckIcon function was made from installDefaults function while fixing [1], so that it can be called from multiple places [2]. installDefaults is a protected function only, so I have not exposed any code which was not exposed earlier. So I think it should not be an issue to do this. << Can you please provide some more details why the call to updateCheckIcon() break the resize? In the fix, we are not reinstalling the full UI, but are changing it partially. If we reinstall it fully as done in first iteration of review for [1], this works fine[3]. [1] https://bugs.openjdk.java.net/browse/JDK-8152981 [2] http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/5fb24aaf6945 [3] http://cr.openjdk.java.net/~rchamyal/8152981/webrev.00/ Regards, Pankaj -----Original Message----- From: Sergey Bylokhov Sent: Friday, January 24, 2020 5:55 AM To: Pankaj Bansal; swing-dev at openjdk.java.net Subject: Re: [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition Hi, Pankaj. The updateCheckIcon() was a private method in the public class from the javax.swing.plaf.basic package you cannot simply make it protected. Can you please provide some more details why the call to updateCheckIcon() break the resize? On 1/23/20 3:05 am, Pankaj Bansal wrote: > Hi All, > > Please review the following fix for jdk15. > > > Bug: > > https://bugs.openjdk.java.net/browse/JDK-8216329 > > webrev: > > http://cr.openjdk.java.net/~pbansal/8216329/webrev00/ > > Issue: > > The JCheckBoxMenuItem is not being resized properly when setHorizontalTextPosition is called on it. This results in some text getting truncated from the end. The issue is specific to Synth L&F. > > Cause: > > The present bug is a regression of [1]. > > Fix: > > The problem in [1] was specific to Windows L&F. but the fix was done in BasicMenuItemUI which is shared by all the L&F. The current fix moves the fix done for [1] to Windows L&F specific code. This fixes the current issue. I have run the tests that was added for [1]. All works fine. > > [1] https://bugs.openjdk.java.net/browse/JDK-8152981 > > > Regards, > Pankaj Bansal > -- Best regards, Sergey. From Sergey.Bylokhov at oracle.com Mon Jan 27 07:44:45 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Sun, 26 Jan 2020 23:44:45 -0800 Subject: [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition In-Reply-To: <03c19198-abc0-4b5d-8430-147d6c2b0e11@default> References: <90cea53e-117d-4252-86d7-7d7b2163d6f3@default> <37805088-6e0e-5b39-44fd-3fdc6d5f89b0@oracle.com> <03c19198-abc0-4b5d-8430-147d6c2b0e11@default> Message-ID: On 1/26/20 10:33 pm, Pankaj Bansal wrote: > Hello Sergey, > > << The updateCheckIcon() was a private method in the public class from the javax.swing.plaf.basic package you cannot simply make it protected. > The updateCheckIcon function was made from installDefaults function while fixing [1], so that it can be called from multiple places [2]. installDefaults is a protected function only, so I have not exposed any code which was not exposed earlier. So I think it should not be an issue to do this. It is not a big issue, but for such a fix we will need a proper specification and CSR, it is like adding a new method to the public class. It is preferable to try to fix it in some other way first. > > << Can you please provide some more details why the call to updateCheckIcon() break the resize? > In the fix, we are not reinstalling the full UI, but are changing it partially. If we reinstall it fully as done in first iteration of review for [1], this works fine[3]. So the problem is that we need to reinstall all UI on "horizontalTextPosition" event?(what exact property is missing?) > > [1] https://bugs.openjdk.java.net/browse/JDK-8152981 > [2] http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/5fb24aaf6945 > [3] http://cr.openjdk.java.net/~rchamyal/8152981/webrev.00/ > > > Regards, > Pankaj > > -----Original Message----- > From: Sergey Bylokhov > Sent: Friday, January 24, 2020 5:55 AM > To: Pankaj Bansal; swing-dev at openjdk.java.net > Subject: Re: [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition > > Hi, Pankaj. > > The updateCheckIcon() was a private method in the public class from the javax.swing.plaf.basic package you cannot simply make it protected. > > Can you please provide some more details why the call to updateCheckIcon() break the resize? > > > On 1/23/20 3:05 am, Pankaj Bansal wrote: >> Hi All, >> >> Please review the following fix for jdk15. >> >> >> Bug: >> >> https://bugs.openjdk.java.net/browse/JDK-8216329 >> >> webrev: >> >> http://cr.openjdk.java.net/~pbansal/8216329/webrev00/ >> >> Issue: >> >> The JCheckBoxMenuItem is not being resized properly when setHorizontalTextPosition is called on it. This results in some text getting truncated from the end. The issue is specific to Synth L&F. >> >> Cause: >> >> The present bug is a regression of [1]. >> >> Fix: >> >> The problem in [1] was specific to Windows L&F. but the fix was done in BasicMenuItemUI which is shared by all the L&F. The current fix moves the fix done for [1] to Windows L&F specific code. This fixes the current issue. I have run the tests that was added for [1]. All works fine. >> >> [1] https://bugs.openjdk.java.net/browse/JDK-8152981 >> >> >> Regards, >> Pankaj Bansal >> > > > -- > Best regards, Sergey. > -- Best regards, Sergey. From pankaj.b.bansal at oracle.com Mon Jan 27 15:15:55 2020 From: pankaj.b.bansal at oracle.com (Pankaj Bansal) Date: Mon, 27 Jan 2020 07:15:55 -0800 (PST) Subject: [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition In-Reply-To: References: <90cea53e-117d-4252-86d7-7d7b2163d6f3@default> <37805088-6e0e-5b39-44fd-3fdc6d5f89b0@oracle.com> <03c19198-abc0-4b5d-8430-147d6c2b0e11@default> Message-ID: <479e09b7-ea1b-4156-b127-4a57414cb4f0@default> Hello Sergey, < [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition On 1/26/20 10:33 pm, Pankaj Bansal wrote: > Hello Sergey, > > << The updateCheckIcon() was a private method in the public class from the javax.swing.plaf.basic package you cannot simply make it protected. > The updateCheckIcon function was made from installDefaults function while fixing [1], so that it can be called from multiple places [2]. installDefaults is a protected function only, so I have not exposed any code which was not exposed earlier. So I think it should not be an issue to do this. It is not a big issue, but for such a fix we will need a proper specification and CSR, it is like adding a new method to the public class. It is preferable to try to fix it in some other way first. > > << Can you please provide some more details why the call to updateCheckIcon() break the resize? > In the fix, we are not reinstalling the full UI, but are changing it partially. If we reinstall it fully as done in first iteration of review for [1], this works fine[3]. So the problem is that we need to reinstall all UI on "horizontalTextPosition" event?(what exact property is missing?) > > [1] https://bugs.openjdk.java.net/browse/JDK-8152981 > [2] http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/5fb24aaf6945 > [3] http://cr.openjdk.java.net/~rchamyal/8152981/webrev.00/ > > > Regards, > Pankaj > > -----Original Message----- > From: Sergey Bylokhov > Sent: Friday, January 24, 2020 5:55 AM > To: Pankaj Bansal; swing-dev at openjdk.java.net > Subject: Re: [15] RFR JDK-8216329: Cannot resize > CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition > > Hi, Pankaj. > > The updateCheckIcon() was a private method in the public class from the javax.swing.plaf.basic package you cannot simply make it protected. > > Can you please provide some more details why the call to updateCheckIcon() break the resize? > > > On 1/23/20 3:05 am, Pankaj Bansal wrote: >> Hi All, >> >> Please review the following fix for jdk15. >> >> >> Bug: >> >> https://bugs.openjdk.java.net/browse/JDK-8216329 >> >> webrev: >> >> http://cr.openjdk.java.net/~pbansal/8216329/webrev00/ >> >> Issue: >> >> The JCheckBoxMenuItem is not being resized properly when setHorizontalTextPosition is called on it. This results in some text getting truncated from the end. The issue is specific to Synth L&F. >> >> Cause: >> >> The present bug is a regression of [1]. >> >> Fix: >> >> The problem in [1] was specific to Windows L&F. but the fix was done in BasicMenuItemUI which is shared by all the L&F. The current fix moves the fix done for [1] to Windows L&F specific code. This fixes the current issue. I have run the tests that was added for [1]. All works fine. >> >> [1] https://bugs.openjdk.java.net/browse/JDK-8152981 >> >> >> Regards, >> Pankaj Bansal >> > > > -- > Best regards, Sergey. > -- Best regards, Sergey. From vladislav.volodin at sap.com Mon Jan 27 17:11:05 2020 From: vladislav.volodin at sap.com (Volodin, Vladislav) Date: Mon, 27 Jan 2020 17:11:05 +0000 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: <549622d0-fe72-f267-c105-53b1399471dc@oracle.com> References: <2310F0FD-DAA6-4E24-85AD-776D6F979CC0@sap.com> <549622d0-fe72-f267-c105-53b1399471dc@oracle.com> Message-ID: Hello Sergey, and others, here is the patch (made with "git diff") in the attachment. I have read that sometimes the attachments are lost. So here is my version with few comments regarding my code. I decided to use your approach with a small improvement. There is an excerpt of my patch. The idea is pretty simple: 1. I create an empty gif 1x1; 2. Initialize DefaultToolkit (I plan to interrupt the main thread, and if I do not initialize the toolkit in advance, my test will fail at the beginning 3. Interrupt the main thread 4. Try to load the icon: import javax.swing.*; import java.awt.*; public class imageIconInterrupted { static byte[] EMPTY_GIF = new byte[]{ (byte) 0x47, (byte) 0x49, (byte) 0x46, (byte) 0x38, (byte) 0x39, (byte) 0x61, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x21, (byte) 0xF9, (byte) 0x04, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x02 }; public static void main(String[] args) throws Exception { Toolkit ignoreToolkit = Toolkit.getDefaultToolkit(); Thread.currentThread().interrupt(); ImageIcon iconInterrupt = new ImageIcon(EMPTY_GIF); if (iconInterrupt.getImageLoadStatus() != MediaTracker.COMPLETE) { throw new RuntimeException("Couldn't load GIF from bytes after interruption"); } } } The code of loadImage I have changed as follows: 1. I clear loadStatus for "finally" part; 2. Check the interruption according to your comments; 3. Change the status to ABORTED, if the interruption happened again (this part I cannot test, because I cannot properly interrupt the thread whenever I want. Multithreading is quite fragile there :( ) 4. update the status "interrupted" again; 5. and then - finally block. protected void loadImage(Image image) { ... try { loadStatus = 0; mTracker.addImage(image, id); mTracker.waitForID(id, 0); } catch (InterruptedException e1) { try { mTracker.waitForID(id, 0); } catch (InterruptedException e2) { loadStatus = MediaTracker.ABORTED; Thread.currentThread().interrupt(); } } finally { if (loadStatus == 0) { loadStatus = mTracker.statusID(id, false); } mTracker.removeImage(image, id); } P.S. if you think that my patch sounds fine, I will find a sponsor for the bug report and the patch preparation, so you can review it later. After the second attempt, my EMPTY_GIF was loaded successfully. The ABORTED part it seems that I don't know if it has ever worked. My patch (in the attachment) checks also the state ERROR for the URL that doesn't exist. Something like: ImageIcon iconNotExist = new ImageIcon(new URL("http://doesnt.exist.anywhere/1.gif")); // I am not sure if I spelled this URL grammatically correct if (iconNotExist.getImageLoadStatus() != MediaTracker.ERRORED) { throw new RuntimeException("Got unexpected status from non-existing GIF"); } Thanks to everyone. Kind regards, Vlad -----Original Message----- From: Sergey Bylokhov Sent: Dienstag, 21. Januar 2020 22:26 To: Volodin, Vladislav Cc: Jason Mehrens ; swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage On 1/21/20 1:14 pm, Volodin, Vladislav wrote: > Hi all, > > If I am not mistaken, this method is called from the constructor and other methods. How long should we try loading the icon using the unmanaged (by any thread pool, but I am not sure about this statement) thread? > > We don?t even have the flag ?interrupted?. So technically this icon has to be loaded. I think it is necessary to save the "interrupted" state in the catch block and try to call waitForID() again. It will be necessary to set "interrupted" flag for the Thread after that(when the waitForID will return without exception). > Sent from myFone > >> On 21. Jan 2020, at 21:55, Sergey Bylokhov wrote: >> >> ?On 1/21/20 12:26 pm, Jason Mehrens wrote: >>> +1 for Sergey suggestion. >> >> Or probably we need to try to load the image again because of the spec of the method state this: >> "Loads the image, returning only when the image is loaded." >> >>> ________________________________________ >>> From: Sergey Bylokhov >>> Sent: Sunday, January 19, 2020 9:31 PM >>> To: Volodin, Vladislav; Jason Mehrens >>> Cc: swing-dev at openjdk.java.net >>> Subject: Re: Remove System.out.println from ImageIcon.loadImage >>> I guess there are no objections, probably the best way to fix >>> it is to drop the System.out.println and set interrupted flag. >>> On 1/16/20 7:05 am, Volodin, Vladislav wrote: >>>> If people in this distribution list agree, I can start working on a simple fix and either remove the logging (System.out.println), or replace it with PlatformLogger. I guess the second solution sounds better, but I don't know what is the better way to write a test-case for it. >>> -- >>> Best regards, Sergey. >> >> >> -- >> Best regards, Sergey. -- Best regards, Sergey. -------------- next part -------------- A non-text attachment was scrubbed... Name: imageIconBug-diff.patch Type: application/octet-stream Size: 3606 bytes Desc: imageIconBug-diff.patch URL: From jason_mehrens at hotmail.com Tue Jan 28 20:33:46 2020 From: jason_mehrens at hotmail.com (Jason Mehrens) Date: Tue, 28 Jan 2020 20:33:46 +0000 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: References: <2310F0FD-DAA6-4E24-85AD-776D6F979CC0@sap.com> <549622d0-fe72-f267-c105-53b1399471dc@oracle.com>, Message-ID: Vlad, I assume you would want to wait in a loop and reassert the interrupt at the end. === protected void loadImage(Image image) { MediaTracker mTracker = getTracker(); synchronized(mTracker) { int id = getNextID(); mTracker.addImage(image, id); boolean wasInterrupted = false; try { do { try { mTracker.waitForID(id, 0); } catch (InterruptedException e) { wasInterrupted = true; } loadStatus = mTracker.statusID(id, false); } while (loadStatus == MediaTracker.LOADING); mTracker.removeImage(image, id); width = image.getWidth(imageObserver); height = image.getHeight(imageObserver); } finally { if (wasInterrupted) { Thread.currentThread().interrupt(); } } } } === Jason ________________________________________ From: swing-dev on behalf of Volodin, Vladislav Sent: Monday, January 27, 2020 11:11 AM To: Sergey Bylokhov Cc: swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage Hello Sergey, and others, here is the patch (made with "git diff") in the attachment. I have read that sometimes the attachments are lost. So here is my version with few comments regarding my code. I decided to use your approach with a small improvement. There is an excerpt of my patch. The idea is pretty simple: 1. I create an empty gif 1x1; 2. Initialize DefaultToolkit (I plan to interrupt the main thread, and if I do not initialize the toolkit in advance, my test will fail at the beginning 3. Interrupt the main thread 4. Try to load the icon: import javax.swing.*; import java.awt.*; public class imageIconInterrupted { static byte[] EMPTY_GIF = new byte[]{ (byte) 0x47, (byte) 0x49, (byte) 0x46, (byte) 0x38, (byte) 0x39, (byte) 0x61, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x21, (byte) 0xF9, (byte) 0x04, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2C, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x02 }; public static void main(String[] args) throws Exception { Toolkit ignoreToolkit = Toolkit.getDefaultToolkit(); Thread.currentThread().interrupt(); ImageIcon iconInterrupt = new ImageIcon(EMPTY_GIF); if (iconInterrupt.getImageLoadStatus() != MediaTracker.COMPLETE) { throw new RuntimeException("Couldn't load GIF from bytes after interruption"); } } } The code of loadImage I have changed as follows: 1. I clear loadStatus for "finally" part; 2. Check the interruption according to your comments; 3. Change the status to ABORTED, if the interruption happened again (this part I cannot test, because I cannot properly interrupt the thread whenever I want. Multithreading is quite fragile there :( ) 4. update the status "interrupted" again; 5. and then - finally block. protected void loadImage(Image image) { ... try { loadStatus = 0; mTracker.addImage(image, id); mTracker.waitForID(id, 0); } catch (InterruptedException e1) { try { mTracker.waitForID(id, 0); } catch (InterruptedException e2) { loadStatus = MediaTracker.ABORTED; Thread.currentThread().interrupt(); } } finally { if (loadStatus == 0) { loadStatus = mTracker.statusID(id, false); } mTracker.removeImage(image, id); } P.S. if you think that my patch sounds fine, I will find a sponsor for the bug report and the patch preparation, so you can review it later. After the second attempt, my EMPTY_GIF was loaded successfully. The ABORTED part it seems that I don't know if it has ever worked. My patch (in the attachment) checks also the state ERROR for the URL that doesn't exist. Something like: ImageIcon iconNotExist = new ImageIcon(new URL("http://doesnt.exist.anywhere/1.gif")); // I am not sure if I spelled this URL grammatically correct if (iconNotExist.getImageLoadStatus() != MediaTracker.ERRORED) { throw new RuntimeException("Got unexpected status from non-existing GIF"); } Thanks to everyone. Kind regards, Vlad -----Original Message----- From: Sergey Bylokhov Sent: Dienstag, 21. Januar 2020 22:26 To: Volodin, Vladislav Cc: Jason Mehrens ; swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage On 1/21/20 1:14 pm, Volodin, Vladislav wrote: > Hi all, > > If I am not mistaken, this method is called from the constructor and other methods. How long should we try loading the icon using the unmanaged (by any thread pool, but I am not sure about this statement) thread? > > We don?t even have the flag ?interrupted?. So technically this icon has to be loaded. I think it is necessary to save the "interrupted" state in the catch block and try to call waitForID() again. It will be necessary to set "interrupted" flag for the Thread after that(when the waitForID will return without exception). > Sent from myFone > >> On 21. Jan 2020, at 21:55, Sergey Bylokhov wrote: >> >> ?On 1/21/20 12:26 pm, Jason Mehrens wrote: >>> +1 for Sergey suggestion. >> >> Or probably we need to try to load the image again because of the spec of the method state this: >> "Loads the image, returning only when the image is loaded." >> >>> ________________________________________ >>> From: Sergey Bylokhov >>> Sent: Sunday, January 19, 2020 9:31 PM >>> To: Volodin, Vladislav; Jason Mehrens >>> Cc: swing-dev at openjdk.java.net >>> Subject: Re: Remove System.out.println from ImageIcon.loadImage >>> I guess there are no objections, probably the best way to fix >>> it is to drop the System.out.println and set interrupted flag. >>> On 1/16/20 7:05 am, Volodin, Vladislav wrote: >>>> If people in this distribution list agree, I can start working on a simple fix and either remove the logging (System.out.println), or replace it with PlatformLogger. I guess the second solution sounds better, but I don't know what is the better way to write a test-case for it. >>> -- >>> Best regards, Sergey. >> >> >> -- >> Best regards, Sergey. -- Best regards, Sergey. From vladislav.volodin at sap.com Tue Jan 28 20:54:03 2020 From: vladislav.volodin at sap.com (Volodin, Vladislav) Date: Tue, 28 Jan 2020 20:54:03 +0000 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: References: <2310F0FD-DAA6-4E24-85AD-776D6F979CC0@sap.com> <549622d0-fe72-f267-c105-53b1399471dc@oracle.com>, , Message-ID: <6CA1C9A2-3FE1-445D-93B7-57DC8818F0FB@sap.com> Hi Jason, I am not sure about the loop, because I don?t know if we can trust results from mTracker.statusID at the moment when an exceptional case occurs. For example, I was experimenting with the code and found out that the MediaTracker can spawn a thread to load the image, or might use the current thread, and the ABORTED state is never returned (I don?t even know how to raise this state). That is why I don?t even know if your loop will ever stop. In my solution, I give the second chance only, and in case if the execution was interrupted the second time, I explicitly assign the ABORTED state to loadStatus. If the user wants to load this image once again, he can create ImageIcon again (or even do this in a loop), or reinitialize it with a single method (I don?t remember its name). What do you think? Kind regards, Vlad Sent from myPad > On 28. Jan 2020, at 21:34, Jason Mehrens wrote: > > ?Vlad, > > I assume you would want to wait in a loop and reassert the interrupt at the end. > > === > protected void loadImage(Image image) { > MediaTracker mTracker = getTracker(); > synchronized(mTracker) { > int id = getNextID(); > > mTracker.addImage(image, id); > boolean wasInterrupted = false; > try { > do { > try { > mTracker.waitForID(id, 0); > } catch (InterruptedException e) { > wasInterrupted = true; > } > loadStatus = mTracker.statusID(id, false); > } while (loadStatus == MediaTracker.LOADING); > mTracker.removeImage(image, id); > > width = image.getWidth(imageObserver); > height = image.getHeight(imageObserver); > } finally { > if (wasInterrupted) { > Thread.currentThread().interrupt(); > } > } > } > } > === > > Jason > ________________________________________ > From: swing-dev on behalf of Volodin, Vladislav > Sent: Monday, January 27, 2020 11:11 AM > To: Sergey Bylokhov > Cc: swing-dev at openjdk.java.net > Subject: Re: Remove System.out.println from ImageIcon.loadImage > > Hello Sergey, and others, > > here is the patch (made with "git diff") in the attachment. I have read that sometimes the attachments are lost. So here is my version with few comments regarding my code. I decided to use your approach with a small improvement. There is an excerpt of my patch. > > The idea is pretty simple: > 1. I create an empty gif 1x1; > 2. Initialize DefaultToolkit (I plan to interrupt the main thread, and if I do not initialize the toolkit in advance, my test will fail at the beginning > 3. Interrupt the main thread > 4. Try to load the icon: > > import javax.swing.*; > import java.awt.*; > > public class imageIconInterrupted { > static byte[] EMPTY_GIF = new byte[]{ > (byte) 0x47, (byte) 0x49, (byte) 0x46, (byte) 0x38, (byte) 0x39, (byte) 0x61, (byte) 0x01, (byte) 0x00, > (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x21, (byte) 0xF9, (byte) 0x04, > (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2C, (byte) 0x00, (byte) 0x00, > (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x02 > }; > > public static void main(String[] args) throws Exception { > Toolkit ignoreToolkit = Toolkit.getDefaultToolkit(); > > Thread.currentThread().interrupt(); > ImageIcon iconInterrupt = new ImageIcon(EMPTY_GIF); > if (iconInterrupt.getImageLoadStatus() != MediaTracker.COMPLETE) { > throw new RuntimeException("Couldn't load GIF from bytes after interruption"); > } > } > } > > The code of loadImage I have changed as follows: > 1. I clear loadStatus for "finally" part; > 2. Check the interruption according to your comments; > 3. Change the status to ABORTED, if the interruption happened again (this part I cannot test, because I cannot properly interrupt the thread whenever I want. Multithreading is quite fragile there :( ) > 4. update the status "interrupted" again; > 5. and then - finally block. > > protected void loadImage(Image image) { > ... > try { > loadStatus = 0; > mTracker.addImage(image, id); > mTracker.waitForID(id, 0); > } catch (InterruptedException e1) { > try { > mTracker.waitForID(id, 0); > } catch (InterruptedException e2) { > loadStatus = MediaTracker.ABORTED; > Thread.currentThread().interrupt(); > } > } finally { > if (loadStatus == 0) { > loadStatus = mTracker.statusID(id, false); > } > mTracker.removeImage(image, id); > } > > P.S. if you think that my patch sounds fine, I will find a sponsor for the bug report and the patch preparation, so you can review it later. > After the second attempt, my EMPTY_GIF was loaded successfully. The ABORTED part it seems that I don't know if it has ever worked. My patch (in the attachment) checks also the state ERROR for the URL that doesn't exist. Something like: > > ImageIcon iconNotExist = new ImageIcon(new URL("http://doesnt.exist.anywhere/1.gif")); // I am not sure if I spelled this URL grammatically correct > if (iconNotExist.getImageLoadStatus() != MediaTracker.ERRORED) { > throw new RuntimeException("Got unexpected status from non-existing GIF"); > } > > Thanks to everyone. > > Kind regards, > Vlad > > -----Original Message----- > From: Sergey Bylokhov > Sent: Dienstag, 21. Januar 2020 22:26 > To: Volodin, Vladislav > Cc: Jason Mehrens ; swing-dev at openjdk.java.net > Subject: Re: Remove System.out.println from ImageIcon.loadImage > >> On 1/21/20 1:14 pm, Volodin, Vladislav wrote: >> Hi all, >> >> If I am not mistaken, this method is called from the constructor and other methods. How long should we try loading the icon using the unmanaged (by any thread pool, but I am not sure about this statement) thread? >> >> We don?t even have the flag ?interrupted?. So technically this icon has to be loaded. > > I think it is necessary to save the "interrupted" state in the catch > block and try to call waitForID() again. It will be necessary to set > "interrupted" flag for the Thread after that(when the waitForID will > return without exception). > > >> Sent from myFone >> >>>> On 21. Jan 2020, at 21:55, Sergey Bylokhov wrote: >>> >>> ?On 1/21/20 12:26 pm, Jason Mehrens wrote: >>>> +1 for Sergey suggestion. >>> >>> Or probably we need to try to load the image again because of the spec of the method state this: >>> "Loads the image, returning only when the image is loaded." >>> >>>> ________________________________________ >>>> From: Sergey Bylokhov >>>> Sent: Sunday, January 19, 2020 9:31 PM >>>> To: Volodin, Vladislav; Jason Mehrens >>>> Cc: swing-dev at openjdk.java.net >>>> Subject: Re: Remove System.out.println from ImageIcon.loadImage >>>> I guess there are no objections, probably the best way to fix >>>> it is to drop the System.out.println and set interrupted flag. >>>> On 1/16/20 7:05 am, Volodin, Vladislav wrote: >>>>> If people in this distribution list agree, I can start working on a simple fix and either remove the logging (System.out.println), or replace it with PlatformLogger. I guess the second solution sounds better, but I don't know what is the better way to write a test-case for it. >>>> -- >>>> Best regards, Sergey. >>> >>> >>> -- >>> Best regards, Sergey. > > > -- > Best regards, Sergey. From jason_mehrens at hotmail.com Tue Jan 28 21:26:28 2020 From: jason_mehrens at hotmail.com (Jason Mehrens) Date: Tue, 28 Jan 2020 21:26:28 +0000 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: <6CA1C9A2-3FE1-445D-93B7-57DC8818F0FB@sap.com> References: <2310F0FD-DAA6-4E24-85AD-776D6F979CC0@sap.com> <549622d0-fe72-f267-c105-53b1399471dc@oracle.com>, , , <6CA1C9A2-3FE1-445D-93B7-57DC8818F0FB@sap.com> Message-ID: I see. Well I would have to do some more digging and testing to make myself more knowledgeable on MediaTracker. Then the only bug in your current code is that you are not reasserting interrupted status of the current thread in the case e1 is raised and e2 is not. It is usually best to reassert the interrupted state at the end of the method. Jason ________________________________________ From: Volodin, Vladislav Sent: Tuesday, January 28, 2020 2:54 PM To: Jason Mehrens Cc: swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage Hi Jason, I am not sure about the loop, because I don?t know if we can trust results from mTracker.statusID at the moment when an exceptional case occurs. For example, I was experimenting with the code and found out that the MediaTracker can spawn a thread to load the image, or might use the current thread, and the ABORTED state is never returned (I don?t even know how to raise this state). That is why I don?t even know if your loop will ever stop. In my solution, I give the second chance only, and in case if the execution was interrupted the second time, I explicitly assign the ABORTED state to loadStatus. If the user wants to load this image once again, he can create ImageIcon again (or even do this in a loop), or reinitialize it with a single method (I don?t remember its name). What do you think? Kind regards, Vlad Sent from myPad > On 28. Jan 2020, at 21:34, Jason Mehrens wrote: > > ?Vlad, > > I assume you would want to wait in a loop and reassert the interrupt at the end. > > === > protected void loadImage(Image image) { > MediaTracker mTracker = getTracker(); > synchronized(mTracker) { > int id = getNextID(); > > mTracker.addImage(image, id); > boolean wasInterrupted = false; > try { > do { > try { > mTracker.waitForID(id, 0); > } catch (InterruptedException e) { > wasInterrupted = true; > } > loadStatus = mTracker.statusID(id, false); > } while (loadStatus == MediaTracker.LOADING); > mTracker.removeImage(image, id); > > width = image.getWidth(imageObserver); > height = image.getHeight(imageObserver); > } finally { > if (wasInterrupted) { > Thread.currentThread().interrupt(); > } > } > } > } > === > > Jason > ________________________________________ > From: swing-dev on behalf of Volodin, Vladislav > Sent: Monday, January 27, 2020 11:11 AM > To: Sergey Bylokhov > Cc: swing-dev at openjdk.java.net > Subject: Re: Remove System.out.println from ImageIcon.loadImage > > Hello Sergey, and others, > > here is the patch (made with "git diff") in the attachment. I have read that sometimes the attachments are lost. So here is my version with few comments regarding my code. I decided to use your approach with a small improvement. There is an excerpt of my patch. > > The idea is pretty simple: > 1. I create an empty gif 1x1; > 2. Initialize DefaultToolkit (I plan to interrupt the main thread, and if I do not initialize the toolkit in advance, my test will fail at the beginning > 3. Interrupt the main thread > 4. Try to load the icon: > > import javax.swing.*; > import java.awt.*; > > public class imageIconInterrupted { > static byte[] EMPTY_GIF = new byte[]{ > (byte) 0x47, (byte) 0x49, (byte) 0x46, (byte) 0x38, (byte) 0x39, (byte) 0x61, (byte) 0x01, (byte) 0x00, > (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x21, (byte) 0xF9, (byte) 0x04, > (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2C, (byte) 0x00, (byte) 0x00, > (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x02 > }; > > public static void main(String[] args) throws Exception { > Toolkit ignoreToolkit = Toolkit.getDefaultToolkit(); > > Thread.currentThread().interrupt(); > ImageIcon iconInterrupt = new ImageIcon(EMPTY_GIF); > if (iconInterrupt.getImageLoadStatus() != MediaTracker.COMPLETE) { > throw new RuntimeException("Couldn't load GIF from bytes after interruption"); > } > } > } > > The code of loadImage I have changed as follows: > 1. I clear loadStatus for "finally" part; > 2. Check the interruption according to your comments; > 3. Change the status to ABORTED, if the interruption happened again (this part I cannot test, because I cannot properly interrupt the thread whenever I want. Multithreading is quite fragile there :( ) > 4. update the status "interrupted" again; > 5. and then - finally block. > > protected void loadImage(Image image) { > ... > try { > loadStatus = 0; > mTracker.addImage(image, id); > mTracker.waitForID(id, 0); > } catch (InterruptedException e1) { > try { > mTracker.waitForID(id, 0); > } catch (InterruptedException e2) { > loadStatus = MediaTracker.ABORTED; > Thread.currentThread().interrupt(); > } > } finally { > if (loadStatus == 0) { > loadStatus = mTracker.statusID(id, false); > } > mTracker.removeImage(image, id); > } > > P.S. if you think that my patch sounds fine, I will find a sponsor for the bug report and the patch preparation, so you can review it later. > After the second attempt, my EMPTY_GIF was loaded successfully. The ABORTED part it seems that I don't know if it has ever worked. My patch (in the attachment) checks also the state ERROR for the URL that doesn't exist. Something like: > > ImageIcon iconNotExist = new ImageIcon(new URL("http://doesnt.exist.anywhere/1.gif")); // I am not sure if I spelled this URL grammatically correct > if (iconNotExist.getImageLoadStatus() != MediaTracker.ERRORED) { > throw new RuntimeException("Got unexpected status from non-existing GIF"); > } > > Thanks to everyone. > > Kind regards, > Vlad > > -----Original Message----- > From: Sergey Bylokhov > Sent: Dienstag, 21. Januar 2020 22:26 > To: Volodin, Vladislav > Cc: Jason Mehrens ; swing-dev at openjdk.java.net > Subject: Re: Remove System.out.println from ImageIcon.loadImage > >> On 1/21/20 1:14 pm, Volodin, Vladislav wrote: >> Hi all, >> >> If I am not mistaken, this method is called from the constructor and other methods. How long should we try loading the icon using the unmanaged (by any thread pool, but I am not sure about this statement) thread? >> >> We don?t even have the flag ?interrupted?. So technically this icon has to be loaded. > > I think it is necessary to save the "interrupted" state in the catch > block and try to call waitForID() again. It will be necessary to set > "interrupted" flag for the Thread after that(when the waitForID will > return without exception). > > >> Sent from myFone >> >>>> On 21. Jan 2020, at 21:55, Sergey Bylokhov wrote: >>> >>> ?On 1/21/20 12:26 pm, Jason Mehrens wrote: >>>> +1 for Sergey suggestion. >>> >>> Or probably we need to try to load the image again because of the spec of the method state this: >>> "Loads the image, returning only when the image is loaded." >>> >>>> ________________________________________ >>>> From: Sergey Bylokhov >>>> Sent: Sunday, January 19, 2020 9:31 PM >>>> To: Volodin, Vladislav; Jason Mehrens >>>> Cc: swing-dev at openjdk.java.net >>>> Subject: Re: Remove System.out.println from ImageIcon.loadImage >>>> I guess there are no objections, probably the best way to fix >>>> it is to drop the System.out.println and set interrupted flag. >>>> On 1/16/20 7:05 am, Volodin, Vladislav wrote: >>>>> If people in this distribution list agree, I can start working on a simple fix and either remove the logging (System.out.println), or replace it with PlatformLogger. I guess the second solution sounds better, but I don't know what is the better way to write a test-case for it. >>>> -- >>>> Best regards, Sergey. >>> >>> >>> -- >>> Best regards, Sergey. > > > -- > Best regards, Sergey. From vladislav.volodin at sap.com Tue Jan 28 22:02:49 2020 From: vladislav.volodin at sap.com (Volodin, Vladislav) Date: Tue, 28 Jan 2020 22:02:49 +0000 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: References: <2310F0FD-DAA6-4E24-85AD-776D6F979CC0@sap.com> <549622d0-fe72-f267-c105-53b1399471dc@oracle.com>, , , <6CA1C9A2-3FE1-445D-93B7-57DC8818F0FB@sap.com>, Message-ID: This is a valid point, because I wasn?t sure that when the thread is interrupted, I handled the first exception, and my thought was that all other ?wait? calls (maybe in other threads) should get the same exception as well. And since I handled this exceptional case, I am restoring the interrupted status in case if I don?t know how to handle this exception the second time. } catch (InterruptedException e1) { try { mTracker.waitForID(id, 0); } catch (InterruptedException e2) { loadStatus = MediaTracker.ABORTED; Thread.currentThread().interrupt(); } If I restore the interrupted status BEFORE waitForID call, then this thread will immoderately fail. Should I restore it AFTER, e.g. } catch (InterruptedException e1) { try { mTracker.waitForID(id, 0); Thread.currentThread().interrupt(); // On 28. Jan 2020, at 22:27, Jason Mehrens wrote: > > ?I see. Well I would have to do some more digging and testing to make myself more knowledgeable on MediaTracker. > > Then the only bug in your current code is that you are not reasserting interrupted status of the current thread in the case e1 is raised and e2 is not. It is usually best to reassert the interrupted state at the end of the method. > > Jason > > ________________________________________ > From: Volodin, Vladislav > Sent: Tuesday, January 28, 2020 2:54 PM > To: Jason Mehrens > Cc: swing-dev at openjdk.java.net > Subject: Re: Remove System.out.println from ImageIcon.loadImage > > Hi Jason, > > I am not sure about the loop, because I don?t know if we can trust results from mTracker.statusID at the moment when an exceptional case occurs. For example, I was experimenting with the code and found out that the MediaTracker can spawn a thread to load the image, or might use the current thread, and the ABORTED state is never returned (I don?t even know how to raise this state). That is why I don?t even know if your loop will ever stop. > > In my solution, I give the second chance only, and in case if the execution was interrupted the second time, I explicitly assign the ABORTED state to loadStatus. If the user wants to load this image once again, he can create ImageIcon again (or even do this in a loop), or reinitialize it with a single method (I don?t remember its name). > > What do you think? > > Kind regards, > Vlad > > Sent from myPad > >> On 28. Jan 2020, at 21:34, Jason Mehrens wrote: >> >> ?Vlad, >> >> I assume you would want to wait in a loop and reassert the interrupt at the end. >> >> === >> protected void loadImage(Image image) { >> MediaTracker mTracker = getTracker(); >> synchronized(mTracker) { >> int id = getNextID(); >> >> mTracker.addImage(image, id); >> boolean wasInterrupted = false; >> try { >> do { >> try { >> mTracker.waitForID(id, 0); >> } catch (InterruptedException e) { >> wasInterrupted = true; >> } >> loadStatus = mTracker.statusID(id, false); >> } while (loadStatus == MediaTracker.LOADING); >> mTracker.removeImage(image, id); >> >> width = image.getWidth(imageObserver); >> height = image.getHeight(imageObserver); >> } finally { >> if (wasInterrupted) { >> Thread.currentThread().interrupt(); >> } >> } >> } >> } >> === >> >> Jason >> ________________________________________ >> From: swing-dev on behalf of Volodin, Vladislav >> Sent: Monday, January 27, 2020 11:11 AM >> To: Sergey Bylokhov >> Cc: swing-dev at openjdk.java.net >> Subject: Re: Remove System.out.println from ImageIcon.loadImage >> >> Hello Sergey, and others, >> >> here is the patch (made with "git diff") in the attachment. I have read that sometimes the attachments are lost. So here is my version with few comments regarding my code. I decided to use your approach with a small improvement. There is an excerpt of my patch. >> >> The idea is pretty simple: >> 1. I create an empty gif 1x1; >> 2. Initialize DefaultToolkit (I plan to interrupt the main thread, and if I do not initialize the toolkit in advance, my test will fail at the beginning >> 3. Interrupt the main thread >> 4. Try to load the icon: >> >> import javax.swing.*; >> import java.awt.*; >> >> public class imageIconInterrupted { >> static byte[] EMPTY_GIF = new byte[]{ >> (byte) 0x47, (byte) 0x49, (byte) 0x46, (byte) 0x38, (byte) 0x39, (byte) 0x61, (byte) 0x01, (byte) 0x00, >> (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x21, (byte) 0xF9, (byte) 0x04, >> (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2C, (byte) 0x00, (byte) 0x00, >> (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x02 >> }; >> >> public static void main(String[] args) throws Exception { >> Toolkit ignoreToolkit = Toolkit.getDefaultToolkit(); >> >> Thread.currentThread().interrupt(); >> ImageIcon iconInterrupt = new ImageIcon(EMPTY_GIF); >> if (iconInterrupt.getImageLoadStatus() != MediaTracker.COMPLETE) { >> throw new RuntimeException("Couldn't load GIF from bytes after interruption"); >> } >> } >> } >> >> The code of loadImage I have changed as follows: >> 1. I clear loadStatus for "finally" part; >> 2. Check the interruption according to your comments; >> 3. Change the status to ABORTED, if the interruption happened again (this part I cannot test, because I cannot properly interrupt the thread whenever I want. Multithreading is quite fragile there :( ) >> 4. update the status "interrupted" again; >> 5. and then - finally block. >> >> protected void loadImage(Image image) { >> ... >> try { >> loadStatus = 0; >> mTracker.addImage(image, id); >> mTracker.waitForID(id, 0); >> } catch (InterruptedException e1) { >> try { >> mTracker.waitForID(id, 0); >> } catch (InterruptedException e2) { >> loadStatus = MediaTracker.ABORTED; >> Thread.currentThread().interrupt(); >> } >> } finally { >> if (loadStatus == 0) { >> loadStatus = mTracker.statusID(id, false); >> } >> mTracker.removeImage(image, id); >> } >> >> P.S. if you think that my patch sounds fine, I will find a sponsor for the bug report and the patch preparation, so you can review it later. >> After the second attempt, my EMPTY_GIF was loaded successfully. The ABORTED part it seems that I don't know if it has ever worked. My patch (in the attachment) checks also the state ERROR for the URL that doesn't exist. Something like: >> >> ImageIcon iconNotExist = new ImageIcon(new URL("http://doesnt.exist.anywhere/1.gif")); // I am not sure if I spelled this URL grammatically correct >> if (iconNotExist.getImageLoadStatus() != MediaTracker.ERRORED) { >> throw new RuntimeException("Got unexpected status from non-existing GIF"); >> } >> >> Thanks to everyone. >> >> Kind regards, >> Vlad >> >> -----Original Message----- >> From: Sergey Bylokhov >> Sent: Dienstag, 21. Januar 2020 22:26 >> To: Volodin, Vladislav >> Cc: Jason Mehrens ; swing-dev at openjdk.java.net >> Subject: Re: Remove System.out.println from ImageIcon.loadImage >> >>>> On 1/21/20 1:14 pm, Volodin, Vladislav wrote: >>> Hi all, >>> >>> If I am not mistaken, this method is called from the constructor and other methods. How long should we try loading the icon using the unmanaged (by any thread pool, but I am not sure about this statement) thread? >>> >>> We don?t even have the flag ?interrupted?. So technically this icon has to be loaded. >> >> I think it is necessary to save the "interrupted" state in the catch >> block and try to call waitForID() again. It will be necessary to set >> "interrupted" flag for the Thread after that(when the waitForID will >> return without exception). >> >> >>> Sent from myFone >>> >>>>> On 21. Jan 2020, at 21:55, Sergey Bylokhov wrote: >>>> >>>> ?On 1/21/20 12:26 pm, Jason Mehrens wrote: >>>>> +1 for Sergey suggestion. >>>> >>>> Or probably we need to try to load the image again because of the spec of the method state this: >>>> "Loads the image, returning only when the image is loaded." >>>> >>>>> ________________________________________ >>>>> From: Sergey Bylokhov >>>>> Sent: Sunday, January 19, 2020 9:31 PM >>>>> To: Volodin, Vladislav; Jason Mehrens >>>>> Cc: swing-dev at openjdk.java.net >>>>> Subject: Re: Remove System.out.println from ImageIcon.loadImage >>>>> I guess there are no objections, probably the best way to fix >>>>> it is to drop the System.out.println and set interrupted flag. >>>>> On 1/16/20 7:05 am, Volodin, Vladislav wrote: >>>>>> If people in this distribution list agree, I can start working on a simple fix and either remove the logging (System.out.println), or replace it with PlatformLogger. I guess the second solution sounds better, but I don't know what is the better way to write a test-case for it. >>>>> -- >>>>> Best regards, Sergey. >>>> >>>> >>>> -- >>>> Best regards, Sergey. >> >> >> -- >> Best regards, Sergey. From Sergey.Bylokhov at oracle.com Wed Jan 29 00:33:57 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Tue, 28 Jan 2020 16:33:57 -0800 Subject: [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition In-Reply-To: <479e09b7-ea1b-4156-b127-4a57414cb4f0@default> References: <90cea53e-117d-4252-86d7-7d7b2163d6f3@default> <37805088-6e0e-5b39-44fd-3fdc6d5f89b0@oracle.com> <03c19198-abc0-4b5d-8430-147d6c2b0e11@default> <479e09b7-ea1b-4156-b127-4a57414cb4f0@default> Message-ID: On 1/27/20 7:15 am, Pankaj Bansal wrote: > << It is not a big issue, but for such a fix we will need a proper specification and CSR, it is like adding a new method to the public class. It is preferable to try to fix it in some other way first. > I did not realize earlier that this can be done by making changes in WindowsMenuItemUI without calling the updateCheckIcon by moving the code in updateCheckIcon method in WindowsMenuItemUI class. I have made the changes for the same and all works fine. Also, I have removed the updateCheckIcon method from BasicMenuItemUI class as it is not needed. Can you please double check that it is not possible to reproduce JDK-8152981 even if the test is modified in some way? -- Best regards, Sergey. From Sergey.Bylokhov at oracle.com Wed Jan 29 07:46:56 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Tue, 28 Jan 2020 23:46:56 -0800 Subject: [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition In-Reply-To: References: <90cea53e-117d-4252-86d7-7d7b2163d6f3@default> <37805088-6e0e-5b39-44fd-3fdc6d5f89b0@oracle.com> <03c19198-abc0-4b5d-8430-147d6c2b0e11@default> <479e09b7-ea1b-4156-b127-4a57414cb4f0@default> Message-ID: <6f2da1e0-ce0c-169b-2c9a-15776b656a69@oracle.com> On 1/28/20 4:33 pm, Sergey Bylokhov wrote: > On 1/27/20 7:15 am, Pankaj Bansal wrote: >> << It is not a big issue, but for such a fix we will need a proper specification and CSR, it is like adding a new method to the public class. It is preferable to try to fix it in some other way first. >> I did not realize earlier that this can be done by making changes in WindowsMenuItemUI without calling the updateCheckIcon by moving the code in updateCheckIcon method in WindowsMenuItemUI class. I have made the changes for the same and all works fine. Also, I have removed the updateCheckIcon method from BasicMenuItemUI class as it is not needed. > > Can you please double check that it is not possible to reproduce JDK-8152981 even if the test is modified in some way? For example if some other "basic" L&F will be used(Motif, Aqua)? -- Best regards, Sergey. From pankaj.b.bansal at oracle.com Wed Jan 29 09:48:33 2020 From: pankaj.b.bansal at oracle.com (Pankaj Bansal) Date: Wed, 29 Jan 2020 01:48:33 -0800 (PST) Subject: [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition In-Reply-To: <6f2da1e0-ce0c-169b-2c9a-15776b656a69@oracle.com> References: <90cea53e-117d-4252-86d7-7d7b2163d6f3@default> <37805088-6e0e-5b39-44fd-3fdc6d5f89b0@oracle.com> <03c19198-abc0-4b5d-8430-147d6c2b0e11@default> <479e09b7-ea1b-4156-b127-4a57414cb4f0@default> <6f2da1e0-ce0c-169b-2c9a-15776b656a69@oracle.com> Message-ID: Hello Sergey, << Can you please double check that it is not possible to reproduce JDK-8152981 even if the test is modified in some way? < [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition On 1/28/20 4:33 pm, Sergey Bylokhov wrote: > On 1/27/20 7:15 am, Pankaj Bansal wrote: >> << It is not a big issue, but for such a fix we will need a proper specification and CSR, it is like adding a new method to the public class. It is preferable to try to fix it in some other way first. >> I did not realize earlier that this can be done by making changes in WindowsMenuItemUI without calling the updateCheckIcon by moving the code in updateCheckIcon method in WindowsMenuItemUI class. I have made the changes for the same and all works fine. Also, I have removed the updateCheckIcon method from BasicMenuItemUI class as it is not needed. > > Can you please double check that it is not possible to reproduce JDK-8152981 even if the test is modified in some way? For example if some other "basic" L&F will be used(Motif, Aqua)? -- Best regards, Sergey. From pankaj.b.bansal at oracle.com Wed Jan 29 10:25:33 2020 From: pankaj.b.bansal at oracle.com (Pankaj Bansal) Date: Wed, 29 Jan 2020 02:25:33 -0800 (PST) Subject: [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition In-Reply-To: References: <90cea53e-117d-4252-86d7-7d7b2163d6f3@default> <37805088-6e0e-5b39-44fd-3fdc6d5f89b0@oracle.com> <03c19198-abc0-4b5d-8430-147d6c2b0e11@default> <479e09b7-ea1b-4156-b127-4a57414cb4f0@default> <6f2da1e0-ce0c-169b-2c9a-15776b656a69@oracle.com> Message-ID: << Can you please double check that it is not possible to reproduce JDK-8152981 even if the test is modified in some way? < [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition Hello Sergey, << Can you please double check that it is not possible to reproduce JDK-8152981 even if the test is modified in some way? < [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition On 1/28/20 4:33 pm, Sergey Bylokhov wrote: > On 1/27/20 7:15 am, Pankaj Bansal wrote: >> << It is not a big issue, but for such a fix we will need a proper specification and CSR, it is like adding a new method to the public class. It is preferable to try to fix it in some other way first. >> I did not realize earlier that this can be done by making changes in WindowsMenuItemUI without calling the updateCheckIcon by moving the code in updateCheckIcon method in WindowsMenuItemUI class. I have made the changes for the same and all works fine. Also, I have removed the updateCheckIcon method from BasicMenuItemUI class as it is not needed. > > Can you please double check that it is not possible to reproduce JDK-8152981 even if the test is modified in some way? For example if some other "basic" L&F will be used(Motif, Aqua)? -- Best regards, Sergey. From jason_mehrens at hotmail.com Wed Jan 29 15:33:00 2020 From: jason_mehrens at hotmail.com (Jason Mehrens) Date: Wed, 29 Jan 2020 15:33:00 +0000 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: References: <2310F0FD-DAA6-4E24-85AD-776D6F979CC0@sap.com> <549622d0-fe72-f267-c105-53b1399471dc@oracle.com>, , , <6CA1C9A2-3FE1-445D-93B7-57DC8818F0FB@sap.com>, , Message-ID: A shorter version is just to reassert at the end of catch e1. It is safer to just reassert as the last statement in the finally. === protected void loadImage(Image image) { MediaTracker mTracker = getTracker(); synchronized (mTracker) { int id = getNextID(); boolean wasInterrupted = false; mTracker.addImage(image, id); try { loadStatus = 0; mTracker.addImage(image, id); mTracker.waitForID(id, 0); } catch (InterruptedException e1) { wasInterrupted = true; try { mTracker.waitForID(id, 0); } catch (InterruptedException e2) { loadStatus = MediaTracker.ABORTED; } } finally { if (loadStatus == 0) { loadStatus = mTracker.statusID(id, false); } mTracker.removeImage(image, id); if (wasInterrupted) { Thread.currentThread().isInterrupted(); } } } } === Jason ________________________________________ From: Volodin, Vladislav Sent: Tuesday, January 28, 2020 4:02 PM To: Jason Mehrens Cc: swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage This is a valid point, because I wasn?t sure that when the thread is interrupted, I handled the first exception, and my thought was that all other ?wait? calls (maybe in other threads) should get the same exception as well. And since I handled this exceptional case, I am restoring the interrupted status in case if I don?t know how to handle this exception the second time. } catch (InterruptedException e1) { try { mTracker.waitForID(id, 0); } catch (InterruptedException e2) { loadStatus = MediaTracker.ABORTED; Thread.currentThread().interrupt(); } If I restore the interrupted status BEFORE waitForID call, then this thread will immoderately fail. Should I restore it AFTER, e.g. } catch (InterruptedException e1) { try { mTracker.waitForID(id, 0); Thread.currentThread().interrupt(); // On 28. Jan 2020, at 22:27, Jason Mehrens wrote: > > ?I see. Well I would have to do some more digging and testing to make myself more knowledgeable on MediaTracker. > > Then the only bug in your current code is that you are not reasserting interrupted status of the current thread in the case e1 is raised and e2 is not. It is usually best to reassert the interrupted state at the end of the method. > > Jason > > ________________________________________ > From: Volodin, Vladislav > Sent: Tuesday, January 28, 2020 2:54 PM > To: Jason Mehrens > Cc: swing-dev at openjdk.java.net > Subject: Re: Remove System.out.println from ImageIcon.loadImage > > Hi Jason, > > I am not sure about the loop, because I don?t know if we can trust results from mTracker.statusID at the moment when an exceptional case occurs. For example, I was experimenting with the code and found out that the MediaTracker can spawn a thread to load the image, or might use the current thread, and the ABORTED state is never returned (I don?t even know how to raise this state). That is why I don?t even know if your loop will ever stop. > > In my solution, I give the second chance only, and in case if the execution was interrupted the second time, I explicitly assign the ABORTED state to loadStatus. If the user wants to load this image once again, he can create ImageIcon again (or even do this in a loop), or reinitialize it with a single method (I don?t remember its name). > > What do you think? > > Kind regards, > Vlad > > Sent from myPad > >> On 28. Jan 2020, at 21:34, Jason Mehrens wrote: >> >> ?Vlad, >> >> I assume you would want to wait in a loop and reassert the interrupt at the end. >> >> === >> protected void loadImage(Image image) { >> MediaTracker mTracker = getTracker(); >> synchronized(mTracker) { >> int id = getNextID(); >> >> mTracker.addImage(image, id); >> boolean wasInterrupted = false; >> try { >> do { >> try { >> mTracker.waitForID(id, 0); >> } catch (InterruptedException e) { >> wasInterrupted = true; >> } >> loadStatus = mTracker.statusID(id, false); >> } while (loadStatus == MediaTracker.LOADING); >> mTracker.removeImage(image, id); >> >> width = image.getWidth(imageObserver); >> height = image.getHeight(imageObserver); >> } finally { >> if (wasInterrupted) { >> Thread.currentThread().interrupt(); >> } >> } >> } >> } >> === >> >> Jason >> ________________________________________ >> From: swing-dev on behalf of Volodin, Vladislav >> Sent: Monday, January 27, 2020 11:11 AM >> To: Sergey Bylokhov >> Cc: swing-dev at openjdk.java.net >> Subject: Re: Remove System.out.println from ImageIcon.loadImage >> >> Hello Sergey, and others, >> >> here is the patch (made with "git diff") in the attachment. I have read that sometimes the attachments are lost. So here is my version with few comments regarding my code. I decided to use your approach with a small improvement. There is an excerpt of my patch. >> >> The idea is pretty simple: >> 1. I create an empty gif 1x1; >> 2. Initialize DefaultToolkit (I plan to interrupt the main thread, and if I do not initialize the toolkit in advance, my test will fail at the beginning >> 3. Interrupt the main thread >> 4. Try to load the icon: >> >> import javax.swing.*; >> import java.awt.*; >> >> public class imageIconInterrupted { >> static byte[] EMPTY_GIF = new byte[]{ >> (byte) 0x47, (byte) 0x49, (byte) 0x46, (byte) 0x38, (byte) 0x39, (byte) 0x61, (byte) 0x01, (byte) 0x00, >> (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x21, (byte) 0xF9, (byte) 0x04, >> (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2C, (byte) 0x00, (byte) 0x00, >> (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x02 >> }; >> >> public static void main(String[] args) throws Exception { >> Toolkit ignoreToolkit = Toolkit.getDefaultToolkit(); >> >> Thread.currentThread().interrupt(); >> ImageIcon iconInterrupt = new ImageIcon(EMPTY_GIF); >> if (iconInterrupt.getImageLoadStatus() != MediaTracker.COMPLETE) { >> throw new RuntimeException("Couldn't load GIF from bytes after interruption"); >> } >> } >> } >> >> The code of loadImage I have changed as follows: >> 1. I clear loadStatus for "finally" part; >> 2. Check the interruption according to your comments; >> 3. Change the status to ABORTED, if the interruption happened again (this part I cannot test, because I cannot properly interrupt the thread whenever I want. Multithreading is quite fragile there :( ) >> 4. update the status "interrupted" again; >> 5. and then - finally block. >> >> protected void loadImage(Image image) { >> ... >> try { >> loadStatus = 0; >> mTracker.addImage(image, id); >> mTracker.waitForID(id, 0); >> } catch (InterruptedException e1) { >> try { >> mTracker.waitForID(id, 0); >> } catch (InterruptedException e2) { >> loadStatus = MediaTracker.ABORTED; >> Thread.currentThread().interrupt(); >> } >> } finally { >> if (loadStatus == 0) { >> loadStatus = mTracker.statusID(id, false); >> } >> mTracker.removeImage(image, id); >> } >> >> P.S. if you think that my patch sounds fine, I will find a sponsor for the bug report and the patch preparation, so you can review it later. >> After the second attempt, my EMPTY_GIF was loaded successfully. The ABORTED part it seems that I don't know if it has ever worked. My patch (in the attachment) checks also the state ERROR for the URL that doesn't exist. Something like: >> >> ImageIcon iconNotExist = new ImageIcon(new URL("http://doesnt.exist.anywhere/1.gif")); // I am not sure if I spelled this URL grammatically correct >> if (iconNotExist.getImageLoadStatus() != MediaTracker.ERRORED) { >> throw new RuntimeException("Got unexpected status from non-existing GIF"); >> } >> >> Thanks to everyone. >> >> Kind regards, >> Vlad >> >> -----Original Message----- >> From: Sergey Bylokhov >> Sent: Dienstag, 21. Januar 2020 22:26 >> To: Volodin, Vladislav >> Cc: Jason Mehrens ; swing-dev at openjdk.java.net >> Subject: Re: Remove System.out.println from ImageIcon.loadImage >> >>>> On 1/21/20 1:14 pm, Volodin, Vladislav wrote: >>> Hi all, >>> >>> If I am not mistaken, this method is called from the constructor and other methods. How long should we try loading the icon using the unmanaged (by any thread pool, but I am not sure about this statement) thread? >>> >>> We don?t even have the flag ?interrupted?. So technically this icon has to be loaded. >> >> I think it is necessary to save the "interrupted" state in the catch >> block and try to call waitForID() again. It will be necessary to set >> "interrupted" flag for the Thread after that(when the waitForID will >> return without exception). >> >> >>> Sent from myFone >>> >>>>> On 21. Jan 2020, at 21:55, Sergey Bylokhov wrote: >>>> >>>> ?On 1/21/20 12:26 pm, Jason Mehrens wrote: >>>>> +1 for Sergey suggestion. >>>> >>>> Or probably we need to try to load the image again because of the spec of the method state this: >>>> "Loads the image, returning only when the image is loaded." >>>> >>>>> ________________________________________ >>>>> From: Sergey Bylokhov >>>>> Sent: Sunday, January 19, 2020 9:31 PM >>>>> To: Volodin, Vladislav; Jason Mehrens >>>>> Cc: swing-dev at openjdk.java.net >>>>> Subject: Re: Remove System.out.println from ImageIcon.loadImage >>>>> I guess there are no objections, probably the best way to fix >>>>> it is to drop the System.out.println and set interrupted flag. >>>>> On 1/16/20 7:05 am, Volodin, Vladislav wrote: >>>>>> If people in this distribution list agree, I can start working on a simple fix and either remove the logging (System.out.println), or replace it with PlatformLogger. I guess the second solution sounds better, but I don't know what is the better way to write a test-case for it. >>>>> -- >>>>> Best regards, Sergey. >>>> >>>> >>>> -- >>>> Best regards, Sergey. >> >> >> -- >> Best regards, Sergey. From jason_mehrens at hotmail.com Wed Jan 29 15:34:48 2020 From: jason_mehrens at hotmail.com (Jason Mehrens) Date: Wed, 29 Jan 2020 15:34:48 +0000 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: References: <2310F0FD-DAA6-4E24-85AD-776D6F979CC0@sap.com> <549622d0-fe72-f267-c105-53b1399471dc@oracle.com>, , , <6CA1C9A2-3FE1-445D-93B7-57DC8818F0FB@sap.com>, , , Message-ID: Bug in that last version: Thread.currentThread().isInterrupted(); -> Thread.currentThread().interrupt(); === protected void loadImage(Image image) { MediaTracker mTracker = getTracker(); synchronized (mTracker) { int id = getNextID(); boolean wasInterrupted = false; mTracker.addImage(image, id); try { loadStatus = 0; mTracker.addImage(image, id); mTracker.waitForID(id, 0); } catch (InterruptedException e1) { wasInterrupted = true; try { mTracker.waitForID(id, 0); } catch (InterruptedException e2) { loadStatus = MediaTracker.ABORTED; wasInterrupted = true; } } finally { if (loadStatus == 0) { loadStatus = mTracker.statusID(id, false); } mTracker.removeImage(image, id); if (wasInterrupted) { Thread.currentThread().interrupt(); } } } } === ________________________________________ From: swing-dev on behalf of Jason Mehrens Sent: Wednesday, January 29, 2020 9:33 AM To: Volodin, Vladislav Cc: swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage A shorter version is just to reassert at the end of catch e1. It is safer to just reassert as the last statement in the finally. === protected void loadImage(Image image) { MediaTracker mTracker = getTracker(); synchronized (mTracker) { int id = getNextID(); boolean wasInterrupted = false; mTracker.addImage(image, id); try { loadStatus = 0; mTracker.addImage(image, id); mTracker.waitForID(id, 0); } catch (InterruptedException e1) { wasInterrupted = true; try { mTracker.waitForID(id, 0); } catch (InterruptedException e2) { loadStatus = MediaTracker.ABORTED; } } finally { if (loadStatus == 0) { loadStatus = mTracker.statusID(id, false); } mTracker.removeImage(image, id); if (wasInterrupted) { Thread.currentThread().isInterrupted(); } } } } === Jason ________________________________________ From: Volodin, Vladislav Sent: Tuesday, January 28, 2020 4:02 PM To: Jason Mehrens Cc: swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage This is a valid point, because I wasn?t sure that when the thread is interrupted, I handled the first exception, and my thought was that all other ?wait? calls (maybe in other threads) should get the same exception as well. And since I handled this exceptional case, I am restoring the interrupted status in case if I don?t know how to handle this exception the second time. } catch (InterruptedException e1) { try { mTracker.waitForID(id, 0); } catch (InterruptedException e2) { loadStatus = MediaTracker.ABORTED; Thread.currentThread().interrupt(); } If I restore the interrupted status BEFORE waitForID call, then this thread will immoderately fail. Should I restore it AFTER, e.g. } catch (InterruptedException e1) { try { mTracker.waitForID(id, 0); Thread.currentThread().interrupt(); // On 28. Jan 2020, at 22:27, Jason Mehrens wrote: > > ?I see. Well I would have to do some more digging and testing to make myself more knowledgeable on MediaTracker. > > Then the only bug in your current code is that you are not reasserting interrupted status of the current thread in the case e1 is raised and e2 is not. It is usually best to reassert the interrupted state at the end of the method. > > Jason > > ________________________________________ > From: Volodin, Vladislav > Sent: Tuesday, January 28, 2020 2:54 PM > To: Jason Mehrens > Cc: swing-dev at openjdk.java.net > Subject: Re: Remove System.out.println from ImageIcon.loadImage > > Hi Jason, > > I am not sure about the loop, because I don?t know if we can trust results from mTracker.statusID at the moment when an exceptional case occurs. For example, I was experimenting with the code and found out that the MediaTracker can spawn a thread to load the image, or might use the current thread, and the ABORTED state is never returned (I don?t even know how to raise this state). That is why I don?t even know if your loop will ever stop. > > In my solution, I give the second chance only, and in case if the execution was interrupted the second time, I explicitly assign the ABORTED state to loadStatus. If the user wants to load this image once again, he can create ImageIcon again (or even do this in a loop), or reinitialize it with a single method (I don?t remember its name). > > What do you think? > > Kind regards, > Vlad > > Sent from myPad > >> On 28. Jan 2020, at 21:34, Jason Mehrens wrote: >> >> ?Vlad, >> >> I assume you would want to wait in a loop and reassert the interrupt at the end. >> >> === >> protected void loadImage(Image image) { >> MediaTracker mTracker = getTracker(); >> synchronized(mTracker) { >> int id = getNextID(); >> >> mTracker.addImage(image, id); >> boolean wasInterrupted = false; >> try { >> do { >> try { >> mTracker.waitForID(id, 0); >> } catch (InterruptedException e) { >> wasInterrupted = true; >> } >> loadStatus = mTracker.statusID(id, false); >> } while (loadStatus == MediaTracker.LOADING); >> mTracker.removeImage(image, id); >> >> width = image.getWidth(imageObserver); >> height = image.getHeight(imageObserver); >> } finally { >> if (wasInterrupted) { >> Thread.currentThread().interrupt(); >> } >> } >> } >> } >> === >> >> Jason >> ________________________________________ >> From: swing-dev on behalf of Volodin, Vladislav >> Sent: Monday, January 27, 2020 11:11 AM >> To: Sergey Bylokhov >> Cc: swing-dev at openjdk.java.net >> Subject: Re: Remove System.out.println from ImageIcon.loadImage >> >> Hello Sergey, and others, >> >> here is the patch (made with "git diff") in the attachment. I have read that sometimes the attachments are lost. So here is my version with few comments regarding my code. I decided to use your approach with a small improvement. There is an excerpt of my patch. >> >> The idea is pretty simple: >> 1. I create an empty gif 1x1; >> 2. Initialize DefaultToolkit (I plan to interrupt the main thread, and if I do not initialize the toolkit in advance, my test will fail at the beginning >> 3. Interrupt the main thread >> 4. Try to load the icon: >> >> import javax.swing.*; >> import java.awt.*; >> >> public class imageIconInterrupted { >> static byte[] EMPTY_GIF = new byte[]{ >> (byte) 0x47, (byte) 0x49, (byte) 0x46, (byte) 0x38, (byte) 0x39, (byte) 0x61, (byte) 0x01, (byte) 0x00, >> (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x21, (byte) 0xF9, (byte) 0x04, >> (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2C, (byte) 0x00, (byte) 0x00, >> (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x02 >> }; >> >> public static void main(String[] args) throws Exception { >> Toolkit ignoreToolkit = Toolkit.getDefaultToolkit(); >> >> Thread.currentThread().interrupt(); >> ImageIcon iconInterrupt = new ImageIcon(EMPTY_GIF); >> if (iconInterrupt.getImageLoadStatus() != MediaTracker.COMPLETE) { >> throw new RuntimeException("Couldn't load GIF from bytes after interruption"); >> } >> } >> } >> >> The code of loadImage I have changed as follows: >> 1. I clear loadStatus for "finally" part; >> 2. Check the interruption according to your comments; >> 3. Change the status to ABORTED, if the interruption happened again (this part I cannot test, because I cannot properly interrupt the thread whenever I want. Multithreading is quite fragile there :( ) >> 4. update the status "interrupted" again; >> 5. and then - finally block. >> >> protected void loadImage(Image image) { >> ... >> try { >> loadStatus = 0; >> mTracker.addImage(image, id); >> mTracker.waitForID(id, 0); >> } catch (InterruptedException e1) { >> try { >> mTracker.waitForID(id, 0); >> } catch (InterruptedException e2) { >> loadStatus = MediaTracker.ABORTED; >> Thread.currentThread().interrupt(); >> } >> } finally { >> if (loadStatus == 0) { >> loadStatus = mTracker.statusID(id, false); >> } >> mTracker.removeImage(image, id); >> } >> >> P.S. if you think that my patch sounds fine, I will find a sponsor for the bug report and the patch preparation, so you can review it later. >> After the second attempt, my EMPTY_GIF was loaded successfully. The ABORTED part it seems that I don't know if it has ever worked. My patch (in the attachment) checks also the state ERROR for the URL that doesn't exist. Something like: >> >> ImageIcon iconNotExist = new ImageIcon(new URL("http://doesnt.exist.anywhere/1.gif")); // I am not sure if I spelled this URL grammatically correct >> if (iconNotExist.getImageLoadStatus() != MediaTracker.ERRORED) { >> throw new RuntimeException("Got unexpected status from non-existing GIF"); >> } >> >> Thanks to everyone. >> >> Kind regards, >> Vlad >> >> -----Original Message----- >> From: Sergey Bylokhov >> Sent: Dienstag, 21. Januar 2020 22:26 >> To: Volodin, Vladislav >> Cc: Jason Mehrens ; swing-dev at openjdk.java.net >> Subject: Re: Remove System.out.println from ImageIcon.loadImage >> >>>> On 1/21/20 1:14 pm, Volodin, Vladislav wrote: >>> Hi all, >>> >>> If I am not mistaken, this method is called from the constructor and other methods. How long should we try loading the icon using the unmanaged (by any thread pool, but I am not sure about this statement) thread? >>> >>> We don?t even have the flag ?interrupted?. So technically this icon has to be loaded. >> >> I think it is necessary to save the "interrupted" state in the catch >> block and try to call waitForID() again. It will be necessary to set >> "interrupted" flag for the Thread after that(when the waitForID will >> return without exception). >> >> >>> Sent from myFone >>> >>>>> On 21. Jan 2020, at 21:55, Sergey Bylokhov wrote: >>>> >>>> ?On 1/21/20 12:26 pm, Jason Mehrens wrote: >>>>> +1 for Sergey suggestion. >>>> >>>> Or probably we need to try to load the image again because of the spec of the method state this: >>>> "Loads the image, returning only when the image is loaded." >>>> >>>>> ________________________________________ >>>>> From: Sergey Bylokhov >>>>> Sent: Sunday, January 19, 2020 9:31 PM >>>>> To: Volodin, Vladislav; Jason Mehrens >>>>> Cc: swing-dev at openjdk.java.net >>>>> Subject: Re: Remove System.out.println from ImageIcon.loadImage >>>>> I guess there are no objections, probably the best way to fix >>>>> it is to drop the System.out.println and set interrupted flag. >>>>> On 1/16/20 7:05 am, Volodin, Vladislav wrote: >>>>>> If people in this distribution list agree, I can start working on a simple fix and either remove the logging (System.out.println), or replace it with PlatformLogger. I guess the second solution sounds better, but I don't know what is the better way to write a test-case for it. >>>>> -- >>>>> Best regards, Sergey. >>>> >>>> >>>> -- >>>> Best regards, Sergey. >> >> >> -- >> Best regards, Sergey. From vladislav.volodin at sap.com Wed Jan 29 15:52:12 2020 From: vladislav.volodin at sap.com (Volodin, Vladislav) Date: Wed, 29 Jan 2020 15:52:12 +0000 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: References: <2310F0FD-DAA6-4E24-85AD-776D6F979CC0@sap.com> <549622d0-fe72-f267-c105-53b1399471dc@oracle.com>, , , <6CA1C9A2-3FE1-445D-93B7-57DC8818F0FB@sap.com>, , , Message-ID: Hi Jason, I have few questions: 1. The second assignment is probably redundant: } catch (InterruptedException e1) { wasInterrupted = true; // line #2, see comment below try { mTracker.waitForID(id, 0); } catch (InterruptedException e2) { loadStatus = MediaTracker.ABORTED; wasInterrupted = true; // <-- this is redundant, because of the line #2 } } finally { 2. I think the first call of "addImage" is not necessary: boolean wasInterrupted = false; mTracker.addImage(image, id); // maybe I should remove this, because of another comment down below. try { loadStatus = 0; mTracker.addImage(image, id); // because of that May I also ask you a question? What is the purpose of interrupting the current thread in the finally block, instead of doing it in the second catch block (where e2 is created)? I assume that since we were able to handle the exception properly, and plus the entire block is in the synchronization area, in theory we have only one importer at the time. Kind regards, Vlad -----Original Message----- From: Jason Mehrens Sent: Mittwoch, 29. Januar 2020 16:35 To: Volodin, Vladislav Cc: swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage Bug in that last version: Thread.currentThread().isInterrupted(); -> Thread.currentThread().interrupt(); === protected void loadImage(Image image) { MediaTracker mTracker = getTracker(); synchronized (mTracker) { int id = getNextID(); boolean wasInterrupted = false; mTracker.addImage(image, id); try { loadStatus = 0; mTracker.addImage(image, id); mTracker.waitForID(id, 0); } catch (InterruptedException e1) { wasInterrupted = true; try { mTracker.waitForID(id, 0); } catch (InterruptedException e2) { loadStatus = MediaTracker.ABORTED; wasInterrupted = true; } } finally { if (loadStatus == 0) { loadStatus = mTracker.statusID(id, false); } mTracker.removeImage(image, id); if (wasInterrupted) { Thread.currentThread().interrupt(); } } } } === ________________________________________ From: swing-dev on behalf of Jason Mehrens Sent: Wednesday, January 29, 2020 9:33 AM To: Volodin, Vladislav Cc: swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage A shorter version is just to reassert at the end of catch e1. It is safer to just reassert as the last statement in the finally. === protected void loadImage(Image image) { MediaTracker mTracker = getTracker(); synchronized (mTracker) { int id = getNextID(); boolean wasInterrupted = false; mTracker.addImage(image, id); try { loadStatus = 0; mTracker.addImage(image, id); mTracker.waitForID(id, 0); } catch (InterruptedException e1) { wasInterrupted = true; try { mTracker.waitForID(id, 0); } catch (InterruptedException e2) { loadStatus = MediaTracker.ABORTED; } } finally { if (loadStatus == 0) { loadStatus = mTracker.statusID(id, false); } mTracker.removeImage(image, id); if (wasInterrupted) { Thread.currentThread().isInterrupted(); } } } } === Jason ________________________________________ From: Volodin, Vladislav Sent: Tuesday, January 28, 2020 4:02 PM To: Jason Mehrens Cc: swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage This is a valid point, because I wasn?t sure that when the thread is interrupted, I handled the first exception, and my thought was that all other ?wait? calls (maybe in other threads) should get the same exception as well. And since I handled this exceptional case, I am restoring the interrupted status in case if I don?t know how to handle this exception the second time. } catch (InterruptedException e1) { try { mTracker.waitForID(id, 0); } catch (InterruptedException e2) { loadStatus = MediaTracker.ABORTED; Thread.currentThread().interrupt(); } If I restore the interrupted status BEFORE waitForID call, then this thread will immoderately fail. Should I restore it AFTER, e.g. } catch (InterruptedException e1) { try { mTracker.waitForID(id, 0); Thread.currentThread().interrupt(); // On 28. Jan 2020, at 22:27, Jason Mehrens wrote: > > ?I see. Well I would have to do some more digging and testing to make myself more knowledgeable on MediaTracker. > > Then the only bug in your current code is that you are not reasserting interrupted status of the current thread in the case e1 is raised and e2 is not. It is usually best to reassert the interrupted state at the end of the method. > > Jason > > ________________________________________ > From: Volodin, Vladislav > Sent: Tuesday, January 28, 2020 2:54 PM > To: Jason Mehrens > Cc: swing-dev at openjdk.java.net > Subject: Re: Remove System.out.println from ImageIcon.loadImage > > Hi Jason, > > I am not sure about the loop, because I don?t know if we can trust results from mTracker.statusID at the moment when an exceptional case occurs. For example, I was experimenting with the code and found out that the MediaTracker can spawn a thread to load the image, or might use the current thread, and the ABORTED state is never returned (I don?t even know how to raise this state). That is why I don?t even know if your loop will ever stop. > > In my solution, I give the second chance only, and in case if the execution was interrupted the second time, I explicitly assign the ABORTED state to loadStatus. If the user wants to load this image once again, he can create ImageIcon again (or even do this in a loop), or reinitialize it with a single method (I don?t remember its name). > > What do you think? > > Kind regards, > Vlad > > Sent from myPad > >> On 28. Jan 2020, at 21:34, Jason Mehrens wrote: >> >> ?Vlad, >> >> I assume you would want to wait in a loop and reassert the interrupt at the end. >> >> === >> protected void loadImage(Image image) { >> MediaTracker mTracker = getTracker(); >> synchronized(mTracker) { >> int id = getNextID(); >> >> mTracker.addImage(image, id); >> boolean wasInterrupted = false; >> try { >> do { >> try { >> mTracker.waitForID(id, 0); >> } catch (InterruptedException e) { >> wasInterrupted = true; >> } >> loadStatus = mTracker.statusID(id, false); >> } while (loadStatus == MediaTracker.LOADING); >> mTracker.removeImage(image, id); >> >> width = image.getWidth(imageObserver); >> height = image.getHeight(imageObserver); >> } finally { >> if (wasInterrupted) { >> Thread.currentThread().interrupt(); >> } >> } >> } >> } >> === >> >> Jason >> ________________________________________ >> From: swing-dev on behalf of Volodin, Vladislav >> Sent: Monday, January 27, 2020 11:11 AM >> To: Sergey Bylokhov >> Cc: swing-dev at openjdk.java.net >> Subject: Re: Remove System.out.println from ImageIcon.loadImage >> >> Hello Sergey, and others, >> >> here is the patch (made with "git diff") in the attachment. I have read that sometimes the attachments are lost. So here is my version with few comments regarding my code. I decided to use your approach with a small improvement. There is an excerpt of my patch. >> >> The idea is pretty simple: >> 1. I create an empty gif 1x1; >> 2. Initialize DefaultToolkit (I plan to interrupt the main thread, and if I do not initialize the toolkit in advance, my test will fail at the beginning >> 3. Interrupt the main thread >> 4. Try to load the icon: >> >> import javax.swing.*; >> import java.awt.*; >> >> public class imageIconInterrupted { >> static byte[] EMPTY_GIF = new byte[]{ >> (byte) 0x47, (byte) 0x49, (byte) 0x46, (byte) 0x38, (byte) 0x39, (byte) 0x61, (byte) 0x01, (byte) 0x00, >> (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x21, (byte) 0xF9, (byte) 0x04, >> (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2C, (byte) 0x00, (byte) 0x00, >> (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x02 >> }; >> >> public static void main(String[] args) throws Exception { >> Toolkit ignoreToolkit = Toolkit.getDefaultToolkit(); >> >> Thread.currentThread().interrupt(); >> ImageIcon iconInterrupt = new ImageIcon(EMPTY_GIF); >> if (iconInterrupt.getImageLoadStatus() != MediaTracker.COMPLETE) { >> throw new RuntimeException("Couldn't load GIF from bytes after interruption"); >> } >> } >> } >> >> The code of loadImage I have changed as follows: >> 1. I clear loadStatus for "finally" part; >> 2. Check the interruption according to your comments; >> 3. Change the status to ABORTED, if the interruption happened again (this part I cannot test, because I cannot properly interrupt the thread whenever I want. Multithreading is quite fragile there :( ) >> 4. update the status "interrupted" again; >> 5. and then - finally block. >> >> protected void loadImage(Image image) { >> ... >> try { >> loadStatus = 0; >> mTracker.addImage(image, id); >> mTracker.waitForID(id, 0); >> } catch (InterruptedException e1) { >> try { >> mTracker.waitForID(id, 0); >> } catch (InterruptedException e2) { >> loadStatus = MediaTracker.ABORTED; >> Thread.currentThread().interrupt(); >> } >> } finally { >> if (loadStatus == 0) { >> loadStatus = mTracker.statusID(id, false); >> } >> mTracker.removeImage(image, id); >> } >> >> P.S. if you think that my patch sounds fine, I will find a sponsor for the bug report and the patch preparation, so you can review it later. >> After the second attempt, my EMPTY_GIF was loaded successfully. The ABORTED part it seems that I don't know if it has ever worked. My patch (in the attachment) checks also the state ERROR for the URL that doesn't exist. Something like: >> >> ImageIcon iconNotExist = new ImageIcon(new URL("http://doesnt.exist.anywhere/1.gif")); // I am not sure if I spelled this URL grammatically correct >> if (iconNotExist.getImageLoadStatus() != MediaTracker.ERRORED) { >> throw new RuntimeException("Got unexpected status from non-existing GIF"); >> } >> >> Thanks to everyone. >> >> Kind regards, >> Vlad >> >> -----Original Message----- >> From: Sergey Bylokhov >> Sent: Dienstag, 21. Januar 2020 22:26 >> To: Volodin, Vladislav >> Cc: Jason Mehrens ; swing-dev at openjdk.java.net >> Subject: Re: Remove System.out.println from ImageIcon.loadImage >> >>>> On 1/21/20 1:14 pm, Volodin, Vladislav wrote: >>> Hi all, >>> >>> If I am not mistaken, this method is called from the constructor and other methods. How long should we try loading the icon using the unmanaged (by any thread pool, but I am not sure about this statement) thread? >>> >>> We don?t even have the flag ?interrupted?. So technically this icon has to be loaded. >> >> I think it is necessary to save the "interrupted" state in the catch >> block and try to call waitForID() again. It will be necessary to set >> "interrupted" flag for the Thread after that(when the waitForID will >> return without exception). >> >> >>> Sent from myFone >>> >>>>> On 21. Jan 2020, at 21:55, Sergey Bylokhov wrote: >>>> >>>> ?On 1/21/20 12:26 pm, Jason Mehrens wrote: >>>>> +1 for Sergey suggestion. >>>> >>>> Or probably we need to try to load the image again because of the spec of the method state this: >>>> "Loads the image, returning only when the image is loaded." >>>> >>>>> ________________________________________ >>>>> From: Sergey Bylokhov >>>>> Sent: Sunday, January 19, 2020 9:31 PM >>>>> To: Volodin, Vladislav; Jason Mehrens >>>>> Cc: swing-dev at openjdk.java.net >>>>> Subject: Re: Remove System.out.println from ImageIcon.loadImage >>>>> I guess there are no objections, probably the best way to fix >>>>> it is to drop the System.out.println and set interrupted flag. >>>>> On 1/16/20 7:05 am, Volodin, Vladislav wrote: >>>>>> If people in this distribution list agree, I can start working on a simple fix and either remove the logging (System.out.println), or replace it with PlatformLogger. I guess the second solution sounds better, but I don't know what is the better way to write a test-case for it. >>>>> -- >>>>> Best regards, Sergey. >>>> >>>> >>>> -- >>>> Best regards, Sergey. >> >> >> -- >> Best regards, Sergey. From jason_mehrens at hotmail.com Wed Jan 29 16:55:08 2020 From: jason_mehrens at hotmail.com (Jason Mehrens) Date: Wed, 29 Jan 2020 16:55:08 +0000 Subject: Remove System.out.println from ImageIcon.loadImage In-Reply-To: References: <2310F0FD-DAA6-4E24-85AD-776D6F979CC0@sap.com> <549622d0-fe72-f267-c105-53b1399471dc@oracle.com>, , , <6CA1C9A2-3FE1-445D-93B7-57DC8818F0FB@sap.com>, , , , Message-ID: 1. Agreed. 2. I was just pulling from the jdk8 source (because I'm lazy) to express the idea. Feel free to adjust. 3. Reasserting in the finally ensure we are not forcefully setting the interrupted status on the current thread and calling 'statusID' and 'removeImage'. It also ensures that the interrupt is set even if an unexpected exception is thrown. Reasserting at the end of 'e1' and never in 'e2' should work too. The main issue that I'm trying to convey to you is that your test is incomplete in that it does check that the interrupt was swallowed. Swallowing interrupts is bad practice. Reasserting in e2 only means that we swallow interrupts from e1. Change your test to this and retest: === public static void main(String[] args) throws Exception { Toolkit ignoreToolkit = Toolkit.getDefaultToolkit(); Thread.currentThread().interrupt(); ImageIcon iconInterrupt = new ImageIcon(EMPTY_GIF); if (iconInterrupt.getImageLoadStatus() != MediaTracker.COMPLETE) { throw new RuntimeException("Couldn't load GIF from bytes after interruption"); } if (!Thread.currentThread().isInterrupted()) { throw new RuntimeException("Interrupt was swallowed"); } } } === ________________________________________ From: Volodin, Vladislav Sent: Wednesday, January 29, 2020 9:52 AM To: Jason Mehrens Cc: swing-dev at openjdk.java.net Subject: RE: Remove System.out.println from ImageIcon.loadImage Hi Jason, I have few questions: 1. The second assignment is probably redundant: } catch (InterruptedException e1) { wasInterrupted = true; // line #2, see comment below try { mTracker.waitForID(id, 0); } catch (InterruptedException e2) { loadStatus = MediaTracker.ABORTED; wasInterrupted = true; // <-- this is redundant, because of the line #2 } } finally { 2. I think the first call of "addImage" is not necessary: boolean wasInterrupted = false; mTracker.addImage(image, id); // maybe I should remove this, because of another comment down below. try { loadStatus = 0; mTracker.addImage(image, id); // because of that May I also ask you a question? What is the purpose of interrupting the current thread in the finally block, instead of doing it in the second catch block (where e2 is created)? I assume that since we were able to handle the exception properly, and plus the entire block is in the synchronization area, in theory we have only one importer at the time. Kind regards, Vlad -----Original Message----- From: Jason Mehrens Sent: Mittwoch, 29. Januar 2020 16:35 To: Volodin, Vladislav Cc: swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage Bug in that last version: Thread.currentThread().isInterrupted(); -> Thread.currentThread().interrupt(); === protected void loadImage(Image image) { MediaTracker mTracker = getTracker(); synchronized (mTracker) { int id = getNextID(); boolean wasInterrupted = false; mTracker.addImage(image, id); try { loadStatus = 0; mTracker.addImage(image, id); mTracker.waitForID(id, 0); } catch (InterruptedException e1) { wasInterrupted = true; try { mTracker.waitForID(id, 0); } catch (InterruptedException e2) { loadStatus = MediaTracker.ABORTED; wasInterrupted = true; } } finally { if (loadStatus == 0) { loadStatus = mTracker.statusID(id, false); } mTracker.removeImage(image, id); if (wasInterrupted) { Thread.currentThread().interrupt(); } } } } === ________________________________________ From: swing-dev on behalf of Jason Mehrens Sent: Wednesday, January 29, 2020 9:33 AM To: Volodin, Vladislav Cc: swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage A shorter version is just to reassert at the end of catch e1. It is safer to just reassert as the last statement in the finally. === protected void loadImage(Image image) { MediaTracker mTracker = getTracker(); synchronized (mTracker) { int id = getNextID(); boolean wasInterrupted = false; mTracker.addImage(image, id); try { loadStatus = 0; mTracker.addImage(image, id); mTracker.waitForID(id, 0); } catch (InterruptedException e1) { wasInterrupted = true; try { mTracker.waitForID(id, 0); } catch (InterruptedException e2) { loadStatus = MediaTracker.ABORTED; } } finally { if (loadStatus == 0) { loadStatus = mTracker.statusID(id, false); } mTracker.removeImage(image, id); if (wasInterrupted) { Thread.currentThread().isInterrupted(); } } } } === Jason ________________________________________ From: Volodin, Vladislav Sent: Tuesday, January 28, 2020 4:02 PM To: Jason Mehrens Cc: swing-dev at openjdk.java.net Subject: Re: Remove System.out.println from ImageIcon.loadImage This is a valid point, because I wasn?t sure that when the thread is interrupted, I handled the first exception, and my thought was that all other ?wait? calls (maybe in other threads) should get the same exception as well. And since I handled this exceptional case, I am restoring the interrupted status in case if I don?t know how to handle this exception the second time. } catch (InterruptedException e1) { try { mTracker.waitForID(id, 0); } catch (InterruptedException e2) { loadStatus = MediaTracker.ABORTED; Thread.currentThread().interrupt(); } If I restore the interrupted status BEFORE waitForID call, then this thread will immoderately fail. Should I restore it AFTER, e.g. } catch (InterruptedException e1) { try { mTracker.waitForID(id, 0); Thread.currentThread().interrupt(); // On 28. Jan 2020, at 22:27, Jason Mehrens wrote: > > ?I see. Well I would have to do some more digging and testing to make myself more knowledgeable on MediaTracker. > > Then the only bug in your current code is that you are not reasserting interrupted status of the current thread in the case e1 is raised and e2 is not. It is usually best to reassert the interrupted state at the end of the method. > > Jason > > ________________________________________ > From: Volodin, Vladislav > Sent: Tuesday, January 28, 2020 2:54 PM > To: Jason Mehrens > Cc: swing-dev at openjdk.java.net > Subject: Re: Remove System.out.println from ImageIcon.loadImage > > Hi Jason, > > I am not sure about the loop, because I don?t know if we can trust results from mTracker.statusID at the moment when an exceptional case occurs. For example, I was experimenting with the code and found out that the MediaTracker can spawn a thread to load the image, or might use the current thread, and the ABORTED state is never returned (I don?t even know how to raise this state). That is why I don?t even know if your loop will ever stop. > > In my solution, I give the second chance only, and in case if the execution was interrupted the second time, I explicitly assign the ABORTED state to loadStatus. If the user wants to load this image once again, he can create ImageIcon again (or even do this in a loop), or reinitialize it with a single method (I don?t remember its name). > > What do you think? > > Kind regards, > Vlad > > Sent from myPad > >> On 28. Jan 2020, at 21:34, Jason Mehrens wrote: >> >> ?Vlad, >> >> I assume you would want to wait in a loop and reassert the interrupt at the end. >> >> === >> protected void loadImage(Image image) { >> MediaTracker mTracker = getTracker(); >> synchronized(mTracker) { >> int id = getNextID(); >> >> mTracker.addImage(image, id); >> boolean wasInterrupted = false; >> try { >> do { >> try { >> mTracker.waitForID(id, 0); >> } catch (InterruptedException e) { >> wasInterrupted = true; >> } >> loadStatus = mTracker.statusID(id, false); >> } while (loadStatus == MediaTracker.LOADING); >> mTracker.removeImage(image, id); >> >> width = image.getWidth(imageObserver); >> height = image.getHeight(imageObserver); >> } finally { >> if (wasInterrupted) { >> Thread.currentThread().interrupt(); >> } >> } >> } >> } >> === >> >> Jason >> ________________________________________ >> From: swing-dev on behalf of Volodin, Vladislav >> Sent: Monday, January 27, 2020 11:11 AM >> To: Sergey Bylokhov >> Cc: swing-dev at openjdk.java.net >> Subject: Re: Remove System.out.println from ImageIcon.loadImage >> >> Hello Sergey, and others, >> >> here is the patch (made with "git diff") in the attachment. I have read that sometimes the attachments are lost. So here is my version with few comments regarding my code. I decided to use your approach with a small improvement. There is an excerpt of my patch. >> >> The idea is pretty simple: >> 1. I create an empty gif 1x1; >> 2. Initialize DefaultToolkit (I plan to interrupt the main thread, and if I do not initialize the toolkit in advance, my test will fail at the beginning >> 3. Interrupt the main thread >> 4. Try to load the icon: >> >> import javax.swing.*; >> import java.awt.*; >> >> public class imageIconInterrupted { >> static byte[] EMPTY_GIF = new byte[]{ >> (byte) 0x47, (byte) 0x49, (byte) 0x46, (byte) 0x38, (byte) 0x39, (byte) 0x61, (byte) 0x01, (byte) 0x00, >> (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x21, (byte) 0xF9, (byte) 0x04, >> (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x2C, (byte) 0x00, (byte) 0x00, >> (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x02 >> }; >> >> public static void main(String[] args) throws Exception { >> Toolkit ignoreToolkit = Toolkit.getDefaultToolkit(); >> >> Thread.currentThread().interrupt(); >> ImageIcon iconInterrupt = new ImageIcon(EMPTY_GIF); >> if (iconInterrupt.getImageLoadStatus() != MediaTracker.COMPLETE) { >> throw new RuntimeException("Couldn't load GIF from bytes after interruption"); >> } >> } >> } >> >> The code of loadImage I have changed as follows: >> 1. I clear loadStatus for "finally" part; >> 2. Check the interruption according to your comments; >> 3. Change the status to ABORTED, if the interruption happened again (this part I cannot test, because I cannot properly interrupt the thread whenever I want. Multithreading is quite fragile there :( ) >> 4. update the status "interrupted" again; >> 5. and then - finally block. >> >> protected void loadImage(Image image) { >> ... >> try { >> loadStatus = 0; >> mTracker.addImage(image, id); >> mTracker.waitForID(id, 0); >> } catch (InterruptedException e1) { >> try { >> mTracker.waitForID(id, 0); >> } catch (InterruptedException e2) { >> loadStatus = MediaTracker.ABORTED; >> Thread.currentThread().interrupt(); >> } >> } finally { >> if (loadStatus == 0) { >> loadStatus = mTracker.statusID(id, false); >> } >> mTracker.removeImage(image, id); >> } >> >> P.S. if you think that my patch sounds fine, I will find a sponsor for the bug report and the patch preparation, so you can review it later. >> After the second attempt, my EMPTY_GIF was loaded successfully. The ABORTED part it seems that I don't know if it has ever worked. My patch (in the attachment) checks also the state ERROR for the URL that doesn't exist. Something like: >> >> ImageIcon iconNotExist = new ImageIcon(new URL("http://doesnt.exist.anywhere/1.gif")); // I am not sure if I spelled this URL grammatically correct >> if (iconNotExist.getImageLoadStatus() != MediaTracker.ERRORED) { >> throw new RuntimeException("Got unexpected status from non-existing GIF"); >> } >> >> Thanks to everyone. >> >> Kind regards, >> Vlad >> >> -----Original Message----- >> From: Sergey Bylokhov >> Sent: Dienstag, 21. Januar 2020 22:26 >> To: Volodin, Vladislav >> Cc: Jason Mehrens ; swing-dev at openjdk.java.net >> Subject: Re: Remove System.out.println from ImageIcon.loadImage >> >>>> On 1/21/20 1:14 pm, Volodin, Vladislav wrote: >>> Hi all, >>> >>> If I am not mistaken, this method is called from the constructor and other methods. How long should we try loading the icon using the unmanaged (by any thread pool, but I am not sure about this statement) thread? >>> >>> We don?t even have the flag ?interrupted?. So technically this icon has to be loaded. >> >> I think it is necessary to save the "interrupted" state in the catch >> block and try to call waitForID() again. It will be necessary to set >> "interrupted" flag for the Thread after that(when the waitForID will >> return without exception). >> >> >>> Sent from myFone >>> >>>>> On 21. Jan 2020, at 21:55, Sergey Bylokhov wrote: >>>> >>>> ?On 1/21/20 12:26 pm, Jason Mehrens wrote: >>>>> +1 for Sergey suggestion. >>>> >>>> Or probably we need to try to load the image again because of the spec of the method state this: >>>> "Loads the image, returning only when the image is loaded." >>>> >>>>> ________________________________________ >>>>> From: Sergey Bylokhov >>>>> Sent: Sunday, January 19, 2020 9:31 PM >>>>> To: Volodin, Vladislav; Jason Mehrens >>>>> Cc: swing-dev at openjdk.java.net >>>>> Subject: Re: Remove System.out.println from ImageIcon.loadImage >>>>> I guess there are no objections, probably the best way to fix >>>>> it is to drop the System.out.println and set interrupted flag. >>>>> On 1/16/20 7:05 am, Volodin, Vladislav wrote: >>>>>> If people in this distribution list agree, I can start working on a simple fix and either remove the logging (System.out.println), or replace it with PlatformLogger. I guess the second solution sounds better, but I don't know what is the better way to write a test-case for it. >>>>> -- >>>>> Best regards, Sergey. >>>> >>>> >>>> -- >>>> Best regards, Sergey. >> >> >> -- >> Best regards, Sergey. From Sergey.Bylokhov at oracle.com Thu Jan 30 00:29:24 2020 From: Sergey.Bylokhov at oracle.com (Sergey Bylokhov) Date: Wed, 29 Jan 2020 16:29:24 -0800 Subject: [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition In-Reply-To: References: <90cea53e-117d-4252-86d7-7d7b2163d6f3@default> <37805088-6e0e-5b39-44fd-3fdc6d5f89b0@oracle.com> <03c19198-abc0-4b5d-8430-147d6c2b0e11@default> <479e09b7-ea1b-4156-b127-4a57414cb4f0@default> <6f2da1e0-ce0c-169b-2c9a-15776b656a69@oracle.com> Message-ID: <0a4ed98d-6af8-86cd-f9d5-6b2b2d5930c5@oracle.com> On 1/29/20 2:25 am, Pankaj Bansal wrote: > One more point, I am able to reproduce the current issue with Synth LookAndFeel in all platforms without fix and it works fine with the fix. ok. Do we need to remove the listener added to the menuItem? I guess it will be added every time we change L&F to the windows and will never be removed. > > Regards, > Pankaj > > -----Original Message----- > From: Pankaj Bansal > Sent: Wednesday, January 29, 2020 3:19 PM > To: Sergey Bylokhov; swing-dev at openjdk.java.net > Subject: Re: [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition > > Hello Sergey, > > << Can you please double check that it is not possible to reproduce JDK-8152981 even if the test is modified in some way? > < I changed the test in JDK-8152981 to run on all installed LookAndFeels on windows, linux and Mac after removing the windows only condition. The tests passes on all platforms with all LookAndFeels with the current fix. > I can check in this change in JDK-8152981 test along with the current fix if needed, though I feel it is not required as the issue was originally only in WindowsLookAndFeel. > > Regards, > Pankaj Bansal > > -----Original Message----- > From: Sergey Bylokhov > Sent: Wednesday, January 29, 2020 1:17 PM > To: Pankaj Bansal; swing-dev at openjdk.java.net > Subject: Re: [15] RFR JDK-8216329: Cannot resize CheckBoxItemMenu in Synth L&F with setHorizontalTextPosition > > On 1/28/20 4:33 pm, Sergey Bylokhov wrote: >> On 1/27/20 7:15 am, Pankaj Bansal wrote: >>> << It is not a big issue, but for such a fix we will need a proper specification and CSR, it is like adding a new method to the public class. It is preferable to try to fix it in some other way first. >>> I did not realize earlier that this can be done by making changes in WindowsMenuItemUI without calling the updateCheckIcon by moving the code in updateCheckIcon method in WindowsMenuItemUI class. I have made the changes for the same and all works fine. Also, I have removed the updateCheckIcon method from BasicMenuItemUI class as it is not needed. >> >> Can you please double check that it is not possible to reproduce JDK-8152981 even if the test is modified in some way? > > For example if some other "basic" L&F will be used(Motif, Aqua)? > > -- Best regards, Sergey.