Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9EC7910952 for ; Fri, 25 Oct 2013 08:12:16 +0000 (UTC) Received: (qmail 13429 invoked by uid 500); 25 Oct 2013 08:12:14 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 12924 invoked by uid 500); 25 Oct 2013 08:12:09 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 12909 invoked by uid 99); 25 Oct 2013 08:12:08 -0000 Received: from minotaur.apache.org (HELO minotaur.apache.org) (140.211.11.9) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Oct 2013 08:12:08 +0000 Received: from localhost (HELO mail-wg0-f53.google.com) (127.0.0.1) (smtp-auth username britter, mechanism plain) by minotaur.apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Oct 2013 08:12:08 +0000 Received: by mail-wg0-f53.google.com with SMTP id y10so3506813wgg.32 for ; Fri, 25 Oct 2013 01:12:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=SjJ+Tvzd3jviud0k05isuU3/yFtbiK0gmMG4w+UbfWE=; b=i3sZ8U7IzzHTaPXqYbMqZlrjPxW+4pj2m/deksIOCIDBlJsMNIhzD9Wcqt2VlJOOEO r2Um0FSQ5vViFZbwlXQjr06ALpNMQUczmbkJJ5bT9L36BwHyEu6KbviSzydz35lX/XZU 8dSU+A8mgTlfBzUBca90Q9/212+lSKSyjbrdNBwAJUkgGPQt3nbGP1AjYd/8dlwrhW+g n7v4i4r5bd9kzDsX4XGuedjP1UJ2lWqKMdzV4vgapFiE01+q4hg1X+2/BpB9ONh33lqm GtwBPr4YuhOXtowzh+h9hvv67VG0IYeiydnoodNmhrqwDxM1men9UiiQAFzp/vXAad3R dh/w== MIME-Version: 1.0 X-Received: by 10.180.160.212 with SMTP id xm20mr1317428wib.23.1382688726447; Fri, 25 Oct 2013 01:12:06 -0700 (PDT) Received: by 10.194.190.136 with HTTP; Fri, 25 Oct 2013 01:12:06 -0700 (PDT) In-Reply-To: References: Date: Fri, 25 Oct 2013 10:12:06 +0200 Message-ID: Subject: Re: [beanutils] BeanUtilsBean.getInstance() pseudo-singleton implications in a Java 7 parallel class loading environment From: Benedikt Ritter To: Commons Users List Content-Type: multipart/alternative; boundary=047d7b624d3460001804e98c4e76 --047d7b624d3460001804e98c4e76 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Hello Matt, about the mailing lists: the separation is a bit fuzzy :-) The user list usually is concerned about problems and question around using components while we discuss the development of the components on the dev list. What you have described is on the one hand a problem while using beanutils. On the other hand it indicates a decent problem in the overall architecture of BeanUtils (which we would normally discuss on the dev ML). Now back to your problem: To be honest I can not comment about this at all, since I don't have the required test environment. But since I know BeanUtils is implemented, I think it is possible that your assumptions are correct. You should definitely file an Issue in JIRA [1] that describes the problem. If you're able to create a test that reproduces it, this would be awesome. That said: BeanUtils is a very old component and we have already started work on a refurbished version of it, that doesn't have the problems BeanUtils has [2]. The problem you're describing is deeply rooted in the architecture of BeanUtils, so I don't expect it to be fixed in a binary compatible release. Sadly I don't have the time to push BeanUtils2 out atm, but I expect it to be released in early 2014 maybe, if I find some time to work on it again (any help is welcome here ;-) HTH at least a little bit. Feel free to join the dev ML and bring this discussion up again, there. Welcome to commons! Benedikt [1] https://issues.apache.org/jira/browse/BEANUTILS [2] http://commons.apache.org/sandbox/commons-beanutils2/ 2013/10/24 Matthew Hall > Hello everyone, > > First off, I=92m not sure that the user list is the right place for this, > but I figured I=92d try before sending it right to the dev list. > > We recently tracked a bug in our software that started showing up with > Java 7 back to an incompatibility between BeanUtilsBean.getInstance() > pseudo-singleton instance model, Java 7=92s parallelized class loader, an= d > the fact that we were registering Converters with ConvertUtils inside of = a > static class-level block. As far as I=92m able to tell, this wasn=92t a p= roblem > in previous versions of Java because the class loader was not parallelize= d, > meaning that the class loader that handled the registration of our > converters was the same class loader that was in use when > ConvertUtilsBean.getInstance() was invoked. Now, with Java 7, it seems th= at > there is no guarantee that the class loader that executes the static bloc= k > containing the Converter registration is the same one in use when > ConvertUtilsBean.getInstance() is invoked, meaning that our custom > Converters are not necessarily available everywhere they used to be. > > I=92m writing to the list today to ask three things about this situation: > > 1. First off, is this the correct explanation for the reason that it > seems we=92re not guaranteed to have our custom Converters loaded in Java= 7. > 2. In order to ensure that a different class loader thread is not in > use when the Converters are registered with ConvertUtils, we=92ve moved t= his > registration from a static class-level block into a user interface setup > method that is executed before the Converters are used. > 3. Given that Java 7 introduced parallelized class loading in the base > ClassLoader and that BeanUtilsBean builds instances on a per-classloader > basis, should this issue be raised to the BeanUtils developers? > > Below you=92ll find some pseudocode that illustrates our situation: > > public class UtilitiesClass { > ... > static { > ConvertUtils.register(new OurCustomColorConverter(), > java.awt.Color.class); > } > ... > } > > public class MainGUIClass { > ... > public static void main(String[] args) { > MainGUIClass mainGui =3D new MainGUIClass(); > mainGui.setup(); > mainGui.show(); > } > > public void setup() { > UIManager.setLookAndFeel(new LookAndFeelClass()); > } > > public void show() { > ((OurLookAndFeelClass) UIManager.getLookAndFeel()).getColor(); > } > ... > } > > public class LookAndFeelClass extends LookAndFeel { > ... > public java.awt.Color getColor(String colorString) { > return (java.awt.Color) > ConvertUtils.convert("someValidColorString", java.awt.Color.class); > } > ... > } > > In the above example, the cast of the results of ConvertUtils.convert to > Color in LookAndFeelClass.getColor(String) sometimes results in a runtime > exception with the message =93java.lang.String cannot be cast to > java.awt.Color.=94. This appears to be due to the fact that > ConvertUtils.convert() fails over to the built-in String.class Converter = if > it cannot find a Converter for the specified class. In production > environments, it was completely unpredictable as to when this would happe= n > and what would make the problem go away. > > The fix we implemented was to move the registration of > OurCustomColorConverter() from the static block inside of UtilitiesClass = to > the first line of MainGUIClass.setup(), before the LookAndFeel is loaded. > Will this fix be sufficient, or does it still suffer from the thread issu= e, > if that is indeed the root cause of the problem? > > --Matt > > Matthew Hall > Enterprise Application Developer || | Intervolve, Inc.< > http://www.intervolve.com/> > mhall@intervolve.com | +1-919-865-4400 ext. > 701 > > --=20 http://people.apache.org/~britter/ http://www.systemoutprintln.de/ http://twitter.com/BenediktRitter http://github.com/britter --047d7b624d3460001804e98c4e76--