Return-Path: X-Original-To: apmail-felix-dev-archive@www.apache.org Delivered-To: apmail-felix-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 05DCB673B for ; Sat, 14 May 2011 12:14:29 +0000 (UTC) Received: (qmail 17828 invoked by uid 500); 14 May 2011 12:14:28 -0000 Delivered-To: apmail-felix-dev-archive@felix.apache.org Received: (qmail 17754 invoked by uid 500); 14 May 2011 12:14:28 -0000 Mailing-List: contact dev-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list dev@felix.apache.org Received: (qmail 17745 invoked by uid 99); 14 May 2011 12:14:27 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 14 May 2011 12:14:27 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 14 May 2011 12:14:26 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 5319EB22A6 for ; Sat, 14 May 2011 12:13:47 +0000 (UTC) Date: Sat, 14 May 2011 12:13:47 +0000 (UTC) From: "Andrei Pozolotin (JIRA)" To: dev@felix.apache.org Message-ID: <226963211.12892.1305375227321.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <1357725628.12369.1305346247607.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Commented] (FELIX-2951) guidelines: felix osgi bundle class load vs Thread.currentThread().getContextClassLoader().getResource("") MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/FELIX-2951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13033515#comment-13033515 ] Andrei Pozolotin commented on FELIX-2951: ----------------------------------------- the dreaded workaround which we are trying to avoid in osgi bundle code: http://stackoverflow.com/questions/2198928/better-handling-of-thread-context-classloader-in-osgi ClassLoader tccl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); /* * Start threads, or establish connections, here, now */ } finally { Thread.currentThread().setContextClassLoader(tccl); } > guidelines: felix osgi bundle class load vs Thread.currentThread().getContextClassLoader().getResource("") > ------------------------------------------------------------------------------------------------------------------ > > Key: FELIX-2951 > URL: https://issues.apache.org/jira/browse/FELIX-2951 > Project: Felix > Issue Type: Improvement > Components: Framework > Affects Versions: framework-3.2.1 > Reporter: Andrei Pozolotin > > Richard, hello; > 1) here you say > http://old.nabble.com/Can-the-thread-context-classloader-issue-be-solved-at-all--td28260809.html > that "There is no reliable way to do this since..." > 2) this project > http://pivot.apache.org/index.html > is using this kind of pattern quite often: > ImageView :: > /** > * Sets the image view's image by {@linkplain ClassLoader#getResource(String) > * resource name}. > * > * @param imageName > * The resource name of the image to set. > * > * @see #setImage(URL) > */ > public final void setImage(String imageName) { > if (imageName == null) { > throw new IllegalArgumentException("imageName is null."); > } > ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); > setImage(classLoader.getResource(imageName.substring(1))); > } > 3) instead of trying to work around this inside of felix, can you please provide > a set of guidelines for developers of projects such as apache pivot, > so the issue is gone? > thank you; > Andrei -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira