Re: how do I switch class loaders

2020-05-12 Thread Jonathan Yom-Tov
It was actually one of mine. I put a jar file under lib/ that I forgot had
the offending class packaged into it.



On Tue, May 12, 2020 at 5:13 PM Christopher Schultz <
ch...@christopherschultz.net> wrote:

> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA256
>
> Jonathan,
>
> On 5/8/20 15:03, Jonathan Yom-Tov wrote:
> > Got it! Using http://jhades.github.io/ it was quick and easy to
> > find out that the offending class was indeed loaded from two
> > different jar files. After I removed one of them casting worked
> > with no issues. I didn't know jar hell could result in
> > ClassCastException, but you learn something new every day.
>
> So what were the two libraries that were conflicting? Logging
> libraries should be REALLY obvious since they have a very good chance
> of colliding. Did some other library "helpfully" package log4j inside
> its own JAR file?
>
> - -chris
>
> > On Fri, May 8, 2020 at 9:29 PM Olaf Kock 
> > wrote:
> >
> >>
> >> On 08.05.20 19:50, Christopher Schultz wrote:
> >>> Olaf,
> >>>
> >>> On 5/8/20 13:19, Olaf Kock wrote:
> >>>
>  You might want to hunt down duplicate classes in the JAR
>  files on your classpath. Worst case: unpack them all in
>  temporary directories and check for occurrences of the
>  filename. Make sure that one doesn't overwrite the other when
>  unzipping.
> >>>
> >>> Or unpack them all and let the unzipper tell you if there are
> >>> any filename collisions.
> >>>
> >>> Someone has probably written a "classpath scanner" that will
> >>> just unzip everything and look for conflicts.
> >>
> >>
> >> I've gotten follow up questions on how to use those tools in the
> >> past. Key is to identify all the jars, less the options of the
> >> tool, but since then I've just reverted to mention the low-tech
> >> version, and am not even ashamed ;)
> >>
> >> That's not to say that I don't trust Jonathan to use a classpath
> >> scanner - it's just a low-tech-preference out of habit.
> >>
> >> Plus, due to this habit, I currently can't come up with a tool's
> >> name to look for :D
> >>
> >> Olaf
> >>
> >>
> >>
> >> -
> >>
> >>
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> >> For additional commands, e-mail: users-h...@tomcat.apache.org
> >>
> >>
> >
> -BEGIN PGP SIGNATURE-
> Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/
>
> iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl66rREACgkQHPApP6U8
> pFhqOBAApsaappSGDrveTxgVU4X2x0VKtZxCzMX8yZ4rSPaFvRi0rMp1bLlaV/sw
> ZaRAQLZbAF5dBgahU4AqKmEkPNw2SlncuykX1JZs//lCDqzaFrJ4Dbsw4YJ7cq+3
> 3jwV6LTS7XzFXOoCHShvvbbwsK2qTWE870TQwOSN+yCN0mTbZz3ah2qnKXoLWZvn
> qUOfYmtTRJTN8vBsR0BpRq2QXZ+uL565A4WLeX9j5jTWiZ5zDNsjN4h9/GHcKChM
> lKIwR8VVfGI+le4JHiW9kz0gukbe/gcvFNPnf5UpvpVZf4VYOQyuTV0gNYAO1QZ8
> CoZ9qNuAjO6aE4BW6PGeFCnDZ55/i6lVe8ZM69Z6WFum8jYOCi2wbuPyUmZqzTbX
> aXAe7OWHXrDgdGUIUFaOvvpMjbEbG/6TBH+VMAbLN3i4uFEQwmjP+9JFn3PSeyok
> ca/5ev99ExfqEOqpQgRddxjo8TBczZdchsUazvR0pcoEWzbQUPvZKN/lRnaCTkxn
> Gvx7co1mw9sGVHkYhktJNLvZE6KP48xaRZISWhCVsVX0LgpUwOyD37N1+wUYgqJT
> Zao62Za5GVVZrbD6+9HYBD3WhKwJwxvxICQ42diEitSxgdvRSTbuUbrREVfkiYgu
> 7OmlWx6y7aXEDgDS7DSBOiMW3/N93uGzOPL0gECQnBmKHLDKfU4=
> =ANY3
> -END PGP SIGNATURE-
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>


Re: how do I switch class loaders

2020-05-12 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Jonathan,

On 5/8/20 15:03, Jonathan Yom-Tov wrote:
> Got it! Using http://jhades.github.io/ it was quick and easy to
> find out that the offending class was indeed loaded from two
> different jar files. After I removed one of them casting worked
> with no issues. I didn't know jar hell could result in
> ClassCastException, but you learn something new every day.

So what were the two libraries that were conflicting? Logging
libraries should be REALLY obvious since they have a very good chance
of colliding. Did some other library "helpfully" package log4j inside
its own JAR file?

- -chris

> On Fri, May 8, 2020 at 9:29 PM Olaf Kock 
> wrote:
>
>>
>> On 08.05.20 19:50, Christopher Schultz wrote:
>>> Olaf,
>>>
>>> On 5/8/20 13:19, Olaf Kock wrote:
>>>
 You might want to hunt down duplicate classes in the JAR
 files on your classpath. Worst case: unpack them all in
 temporary directories and check for occurrences of the
 filename. Make sure that one doesn't overwrite the other when
 unzipping.
>>>
>>> Or unpack them all and let the unzipper tell you if there are
>>> any filename collisions.
>>>
>>> Someone has probably written a "classpath scanner" that will
>>> just unzip everything and look for conflicts.
>>
>>
>> I've gotten follow up questions on how to use those tools in the
>> past. Key is to identify all the jars, less the options of the
>> tool, but since then I've just reverted to mention the low-tech
>> version, and am not even ashamed ;)
>>
>> That's not to say that I don't trust Jonathan to use a classpath
>> scanner - it's just a low-tech-preference out of habit.
>>
>> Plus, due to this habit, I currently can't come up with a tool's
>> name to look for :D
>>
>> Olaf
>>
>>
>>
>> -
>>
>>
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>
>>
>
-BEGIN PGP SIGNATURE-
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAl66rREACgkQHPApP6U8
pFhqOBAApsaappSGDrveTxgVU4X2x0VKtZxCzMX8yZ4rSPaFvRi0rMp1bLlaV/sw
ZaRAQLZbAF5dBgahU4AqKmEkPNw2SlncuykX1JZs//lCDqzaFrJ4Dbsw4YJ7cq+3
3jwV6LTS7XzFXOoCHShvvbbwsK2qTWE870TQwOSN+yCN0mTbZz3ah2qnKXoLWZvn
qUOfYmtTRJTN8vBsR0BpRq2QXZ+uL565A4WLeX9j5jTWiZ5zDNsjN4h9/GHcKChM
lKIwR8VVfGI+le4JHiW9kz0gukbe/gcvFNPnf5UpvpVZf4VYOQyuTV0gNYAO1QZ8
CoZ9qNuAjO6aE4BW6PGeFCnDZ55/i6lVe8ZM69Z6WFum8jYOCi2wbuPyUmZqzTbX
aXAe7OWHXrDgdGUIUFaOvvpMjbEbG/6TBH+VMAbLN3i4uFEQwmjP+9JFn3PSeyok
ca/5ev99ExfqEOqpQgRddxjo8TBczZdchsUazvR0pcoEWzbQUPvZKN/lRnaCTkxn
Gvx7co1mw9sGVHkYhktJNLvZE6KP48xaRZISWhCVsVX0LgpUwOyD37N1+wUYgqJT
Zao62Za5GVVZrbD6+9HYBD3WhKwJwxvxICQ42diEitSxgdvRSTbuUbrREVfkiYgu
7OmlWx6y7aXEDgDS7DSBOiMW3/N93uGzOPL0gECQnBmKHLDKfU4=
=ANY3
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: how do I switch class loaders

2020-05-08 Thread Jonathan Yom-Tov
Got it! Using http://jhades.github.io/ it was quick and easy to find out
that the offending class was indeed loaded from two different jar files.
After I removed one of them casting worked with no issues. I didn't know
jar hell could result in ClassCastException, but you learn something new
every day.

Thanks everyone for your help. Olaf I found your suggestion especially
helpful. Have a good weekend :-)



On Fri, May 8, 2020 at 9:29 PM Olaf Kock  wrote:

>
> On 08.05.20 19:50, Christopher Schultz wrote:
> > Olaf,
> >
> > On 5/8/20 13:19, Olaf Kock wrote:
> >
> > > You might want to hunt down duplicate classes in the JAR files on
> > > your classpath. Worst case: unpack them all in temporary
> > > directories and check for occurrences of the filename. Make sure
> > > that one doesn't overwrite the other when unzipping.
> >
> > Or unpack them all and let the unzipper tell you if there are any
> > filename collisions.
> >
> > Someone has probably written a "classpath scanner" that will just
> > unzip everything and look for conflicts.
>
>
> I've gotten follow up questions on how to use those tools in the past.
> Key is to identify all the jars, less the options of the tool, but since
> then I've just reverted to mention the low-tech version, and am not even
> ashamed ;)
>
> That's not to say that I don't trust Jonathan to use a classpath scanner
> - it's just a low-tech-preference out of habit.
>
> Plus, due to this habit, I currently can't come up with a tool's name to
> look for :D
>
> Olaf
>
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

-- 
[image: SysAid Technologies]

Jonathan Yom-Tov
Senior Architect
jonathan.yom...@sysaid.com
Phone (IL): +972 (3) 533-3675 Ext. 932
[image: SysAid Technologies]

  [image: SysAid on Facebook]    [image:
SysAid on Twitter]    [image: SysAid on
Linked-in]    [image:
SysAid on YouTube]    [image: SysAid
on Instagram] 
[image: Banner] 


Re: how do I switch class loaders

2020-05-08 Thread Olaf Kock


On 08.05.20 19:50, Christopher Schultz wrote:
> Olaf,
>
> On 5/8/20 13:19, Olaf Kock wrote:
>
> > You might want to hunt down duplicate classes in the JAR files on
> > your classpath. Worst case: unpack them all in temporary
> > directories and check for occurrences of the filename. Make sure
> > that one doesn't overwrite the other when unzipping.
>
> Or unpack them all and let the unzipper tell you if there are any
> filename collisions.
>
> Someone has probably written a "classpath scanner" that will just
> unzip everything and look for conflicts.


I've gotten follow up questions on how to use those tools in the past.
Key is to identify all the jars, less the options of the tool, but since
then I've just reverted to mention the low-tech version, and am not even
ashamed ;)

That's not to say that I don't trust Jonathan to use a classpath scanner
- it's just a low-tech-preference out of habit.

Plus, due to this habit, I currently can't come up with a tool's name to
look for :D

Olaf



-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: how do I switch class loaders

2020-05-08 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Olaf,

On 5/8/20 13:19, Olaf Kock wrote:
>
> On 08.05.20 18:23, Jonathan Yom-Tov wrote:
>> Oops, my bad  But that still leaves my original issue: why do I
>> get a ClassCastException casting RedissonSessionManager to
>> RedissonSessionManager?
>
> The *only* reason that I've ever seen this happens (e.g. a class
> can't be typecast to a legitimate superclass or interface): When
> the superclass or interface is available through two different
> classloaders.
>
> The error message omits the classloader, and instead of
>
> A cannot be cast to B
>
> /should/ read
>
> A (from classloader X) cannot be cast to B (from classloader Y)
>
> You might want to hunt down duplicate classes in the JAR files on
> your classpath. Worst case: unpack them all in temporary
> directories and check for occurrences of the filename. Make sure
> that one doesn't overwrite the other when unzipping.

Or unpack them all and let the unzipper tell you if there are any
filename collisions.

Someone has probably written a "classpath scanner" that will just
unzip everything and look for conflicts.

- -chris

>> On Fri, 8 May 2020, 16:56 Luis Rodríguez Fernández,
>>  wrote:
>>
>>> Hello Jonathan,
>>>
>>> It is not exactly the same :), look at the "$2" appended at the
>>> end.This is an "anonymous inner class" [1]
>>>
>>> Cheers,
>>>
>>> Luis
>>>
>>> [1]
>>>
>>> https://stackoverflow.com/questions/11388840/java-compiled-classes-c
ontain-dollar-signs
>>>
>>>
>>>
>>>
El vie., 8 may. 2020 a las 11:52, Jonathan Yom-Tov (<
>>> jonathan.yom...@sysaid.com>) escribió:
>>>
 This is very odd. I ran Tomcat with -verbose:class (see
 relevant output below). The class is being loaded twice from
 the same location, I'm guessing by two different class
 loaders. How can that be?

 [Loaded org.redisson.tomcat.RedissonSessionManager from
 file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
 [Loaded org.redisson.tomcat.RedissonSessionManager$2 from
 file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]

 On Fri, May 8, 2020 at 11:04 AM Olaf Kock
  wrote:

> On 08.05.20 09:37, Jonathan Yom-Tov wrote:
>> Thanks Mark. Just tried that. I put the redisson-tomcat
>> jar outside
>>> of
>> WEB-INF/lib and added it with scope provided. I get the
>> exact same
 issue.
>> What am I doing wrong?
> Make sure, it's actually gone from your webapp. Depending
> on the deployment technique I've seen removed files to
> persist from previous deployments.
>
> You might need to fully undeploy, then deploy the new
> version without the jar in question. But inspect the
> runtime environment to make sure you only have a single
> library accessible. Having the same class available two
> different ways is a recipe for disaster, don't fix it my
> messing with the classloader: Fix it by eliminating one of
> them.
>
> You might also check if you're not accessing any wrapped
> object, e.g.
>>> by
> inspecting getManager(session).getClass().getName().
>
> Olaf
>
>
>
>> Here's my code:
>>
>> HttpSession session =
>> httpServletRequest.getSession(false); try {
>> RedissonSessionManager rsm = (RedissonSessionManager)
> getManager(session);
>> } catch (Exception e) { e.printStackTrace(); }
>>
>> private Manager getManager(HttpSession session) throws
>> Exception {
>>
>> Field facadeSessionField =
>> StandardSessionFacade.class.getDeclaredField("session");
>> facadeSessionField.setAccessible(true); StandardSession
>> stdSession = (StandardSession)
>> facadeSessionField.get(session);
>>
>> return stdSession.getManager(); }
>>
>>
>>
>> On Thu, May 7, 2020 at 11:52 PM Mark Thomas
>> 
>>> wrote:
>>> On 07/05/2020 21:36, Jonathan Yom-Tov wrote:
 My application uses Redisson (a client which persists
 the session
>>> to
 Redis). There are two Redisson jar files located in
 $CATALINA_HOME/lib,
>>> so
 if I understand the docs correctly they're loaded by
 the common
>>> class
 loader.

 I want to access the RedissonSessionManager class
 during a request.
 The
 problem is that if I do something like
 RedissonSessionManager
 manager =
 (RedissonSessionManager) session.getManager() I get
 a
> ClassCastException,
 presumably because they were loaded by different
 class loaders.

 Will it help if I somehow access the common class
 loader for this?
>>> If
> so
 how can I do that? If not is there some other way I
 can achieve
>>> this?
>>> Make sure you don't have those JARs in your
>>> application's
>>> WEB-INF/lib
 as
>>> well as $CATALINA_BASE/lib.
>>>
>>> In any recent version of Tomcat 

Re: how do I switch class loaders

2020-05-08 Thread Olaf Kock


On 08.05.20 18:23, Jonathan Yom-Tov wrote:
> Oops, my bad  But that still leaves my original issue: why do I get a
> ClassCastException casting RedissonSessionManager to
> RedissonSessionManager?

The *only* reason that I've ever seen this happens (e.g. a class can't
be typecast to a legitimate superclass or interface): When the
superclass or interface is available through two different classloaders.

The error message omits the classloader, and instead of

  A cannot be cast to B

/should/ read

   A (from classloader X) cannot be cast to B (from classloader Y)

You might want to hunt down duplicate classes in the JAR files on your
classpath. Worst case: unpack them all in temporary directories and
check for occurrences of the filename. Make sure that one doesn't
overwrite the other when unzipping.

Olaf



> On Fri, 8 May 2020, 16:56 Luis Rodríguez Fernández, 
> wrote:
>
>> Hello Jonathan,
>>
>> It is not exactly the same :), look at the "$2" appended at the end.This is
>> an "anonymous inner class" [1]
>>
>> Cheers,
>>
>> Luis
>>
>> [1]
>>
>> https://stackoverflow.com/questions/11388840/java-compiled-classes-contain-dollar-signs
>>
>>
>> El vie., 8 may. 2020 a las 11:52, Jonathan Yom-Tov (<
>> jonathan.yom...@sysaid.com>) escribió:
>>
>>> This is very odd. I ran Tomcat with -verbose:class (see relevant output
>>> below). The class is being loaded twice from the same location, I'm
>>> guessing by two different class loaders. How can that be?
>>>
>>> [Loaded org.redisson.tomcat.RedissonSessionManager from
>>> file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
>>> [Loaded org.redisson.tomcat.RedissonSessionManager$2 from
>>> file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
>>>
>>> On Fri, May 8, 2020 at 11:04 AM Olaf Kock  wrote:
>>>
 On 08.05.20 09:37, Jonathan Yom-Tov wrote:
> Thanks Mark. Just tried that. I put the redisson-tomcat jar outside
>> of
> WEB-INF/lib and added it with scope provided. I get the exact same
>>> issue.
> What am I doing wrong?
 Make sure, it's actually gone from your webapp. Depending on the
 deployment technique I've seen removed files to persist from previous
 deployments.

 You might need to fully undeploy, then deploy the new version without
 the jar in question. But inspect the runtime environment to make sure
 you only have a single library accessible. Having the same class
 available two different ways is a recipe for disaster, don't fix it my
 messing with the classloader: Fix it by eliminating one of them.

 You might also check if you're not accessing any wrapped object, e.g.
>> by
 inspecting getManager(session).getClass().getName().

 Olaf



> Here's my code:
>
> HttpSession session = httpServletRequest.getSession(false);
> try {
> RedissonSessionManager rsm = (RedissonSessionManager)
 getManager(session);
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> private Manager getManager(HttpSession session) throws Exception {
>
> Field facadeSessionField =
> StandardSessionFacade.class.getDeclaredField("session");
> facadeSessionField.setAccessible(true);
> StandardSession stdSession = (StandardSession)
> facadeSessionField.get(session);
>
> return stdSession.getManager();
> }
>
>
>
> On Thu, May 7, 2020 at 11:52 PM Mark Thomas 
>> wrote:
>> On 07/05/2020 21:36, Jonathan Yom-Tov wrote:
>>> My application uses Redisson (a client which persists the session
>> to
>>> Redis). There are two Redisson jar files located in
>>> $CATALINA_HOME/lib,
>> so
>>> if I understand the docs correctly they're loaded by the common
>> class
>>> loader.
>>>
>>> I want to access the RedissonSessionManager class during a request.
>>> The
>>> problem is that if I do something like RedissonSessionManager
>>> manager =
>>> (RedissonSessionManager) session.getManager() I get a
 ClassCastException,
>>> presumably because they were loaded by different class loaders.
>>>
>>> Will it help if I somehow access the common class loader for this?
>> If
 so
>>> how can I do that? If not is there some other way I can achieve
>> this?
>> Make sure you don't have those JARs in your application's
>> WEB-INF/lib
>>> as
>> well as $CATALINA_BASE/lib.
>>
>> In any recent version of Tomcat any JAR in $CATALINA_BASE/lib will
>> be
>> visible to your application.
>>
>> Mark
>>
>>
>> -
>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>
>>
 -
 To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
 For additional commands, e-mail: 

Re: how do I switch class loaders

2020-05-08 Thread Jonathan Yom-Tov
Oops, my bad  But that still leaves my original issue: why do I get a
ClassCastException casting RedissonSessionManager to
RedissonSessionManager?

On Fri, 8 May 2020, 16:56 Luis Rodríguez Fernández, 
wrote:

> Hello Jonathan,
>
> It is not exactly the same :), look at the "$2" appended at the end.This is
> an "anonymous inner class" [1]
>
> Cheers,
>
> Luis
>
> [1]
>
> https://stackoverflow.com/questions/11388840/java-compiled-classes-contain-dollar-signs
>
>
> El vie., 8 may. 2020 a las 11:52, Jonathan Yom-Tov (<
> jonathan.yom...@sysaid.com>) escribió:
>
> > This is very odd. I ran Tomcat with -verbose:class (see relevant output
> > below). The class is being loaded twice from the same location, I'm
> > guessing by two different class loaders. How can that be?
> >
> > [Loaded org.redisson.tomcat.RedissonSessionManager from
> > file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
> > [Loaded org.redisson.tomcat.RedissonSessionManager$2 from
> > file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
> >
> > On Fri, May 8, 2020 at 11:04 AM Olaf Kock  wrote:
> >
> > >
> > > On 08.05.20 09:37, Jonathan Yom-Tov wrote:
> > > > Thanks Mark. Just tried that. I put the redisson-tomcat jar outside
> of
> > > > WEB-INF/lib and added it with scope provided. I get the exact same
> > issue.
> > > > What am I doing wrong?
> > >
> > > Make sure, it's actually gone from your webapp. Depending on the
> > > deployment technique I've seen removed files to persist from previous
> > > deployments.
> > >
> > > You might need to fully undeploy, then deploy the new version without
> > > the jar in question. But inspect the runtime environment to make sure
> > > you only have a single library accessible. Having the same class
> > > available two different ways is a recipe for disaster, don't fix it my
> > > messing with the classloader: Fix it by eliminating one of them.
> > >
> > > You might also check if you're not accessing any wrapped object, e.g.
> by
> > > inspecting getManager(session).getClass().getName().
> > >
> > > Olaf
> > >
> > >
> > >
> > > > Here's my code:
> > > >
> > > > HttpSession session = httpServletRequest.getSession(false);
> > > > try {
> > > > RedissonSessionManager rsm = (RedissonSessionManager)
> > > getManager(session);
> > > > } catch (Exception e) {
> > > > e.printStackTrace();
> > > > }
> > > >
> > > > private Manager getManager(HttpSession session) throws Exception {
> > > >
> > > > Field facadeSessionField =
> > > > StandardSessionFacade.class.getDeclaredField("session");
> > > > facadeSessionField.setAccessible(true);
> > > > StandardSession stdSession = (StandardSession)
> > > > facadeSessionField.get(session);
> > > >
> > > > return stdSession.getManager();
> > > > }
> > > >
> > > >
> > > >
> > > > On Thu, May 7, 2020 at 11:52 PM Mark Thomas 
> wrote:
> > > >
> > > >> On 07/05/2020 21:36, Jonathan Yom-Tov wrote:
> > > >>> My application uses Redisson (a client which persists the session
> to
> > > >>> Redis). There are two Redisson jar files located in
> > $CATALINA_HOME/lib,
> > > >> so
> > > >>> if I understand the docs correctly they're loaded by the common
> class
> > > >>> loader.
> > > >>>
> > > >>> I want to access the RedissonSessionManager class during a request.
> > The
> > > >>> problem is that if I do something like RedissonSessionManager
> > manager =
> > > >>> (RedissonSessionManager) session.getManager() I get a
> > > ClassCastException,
> > > >>> presumably because they were loaded by different class loaders.
> > > >>>
> > > >>> Will it help if I somehow access the common class loader for this?
> If
> > > so
> > > >>> how can I do that? If not is there some other way I can achieve
> this?
> > > >> Make sure you don't have those JARs in your application's
> WEB-INF/lib
> > as
> > > >> well as $CATALINA_BASE/lib.
> > > >>
> > > >> In any recent version of Tomcat any JAR in $CATALINA_BASE/lib will
> be
> > > >> visible to your application.
> > > >>
> > > >> Mark
> > > >>
> > > >>
> -
> > > >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> > > >> For additional commands, e-mail: users-h...@tomcat.apache.org
> > > >>
> > > >>
> > >
> > > -
> > > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> > > For additional commands, e-mail: users-h...@tomcat.apache.org
> > >
> > >
> >
> > --
> > [image: SysAid Technologies]
> > <
> >
> http://www.sysaid.com/?utm_source=signature_medium=email_campaign=sysaid-logo
> > >
> > Jonathan Yom-Tov
> > Senior Architect
> > jonathan.yom...@sysaid.com
> > Phone (IL): +972 (3) 533-3675 Ext. 932
> > [image: SysAid Technologies]
> > <
> >
> https://www.sysaid.com/?utm_source=signature_medium=email_campaign=sysaid-logo-icon
> > >
> >   [image: SysAid on Facebook] 
> >  [image:
> > SysAid on Twitter] 

Re: how do I switch class loaders

2020-05-08 Thread Luis Rodríguez Fernández
Hello Jonathan,

It is not exactly the same :), look at the "$2" appended at the end.This is
an "anonymous inner class" [1]

Cheers,

Luis

[1]
https://stackoverflow.com/questions/11388840/java-compiled-classes-contain-dollar-signs


El vie., 8 may. 2020 a las 11:52, Jonathan Yom-Tov (<
jonathan.yom...@sysaid.com>) escribió:

> This is very odd. I ran Tomcat with -verbose:class (see relevant output
> below). The class is being loaded twice from the same location, I'm
> guessing by two different class loaders. How can that be?
>
> [Loaded org.redisson.tomcat.RedissonSessionManager from
> file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
> [Loaded org.redisson.tomcat.RedissonSessionManager$2 from
> file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
>
> On Fri, May 8, 2020 at 11:04 AM Olaf Kock  wrote:
>
> >
> > On 08.05.20 09:37, Jonathan Yom-Tov wrote:
> > > Thanks Mark. Just tried that. I put the redisson-tomcat jar outside of
> > > WEB-INF/lib and added it with scope provided. I get the exact same
> issue.
> > > What am I doing wrong?
> >
> > Make sure, it's actually gone from your webapp. Depending on the
> > deployment technique I've seen removed files to persist from previous
> > deployments.
> >
> > You might need to fully undeploy, then deploy the new version without
> > the jar in question. But inspect the runtime environment to make sure
> > you only have a single library accessible. Having the same class
> > available two different ways is a recipe for disaster, don't fix it my
> > messing with the classloader: Fix it by eliminating one of them.
> >
> > You might also check if you're not accessing any wrapped object, e.g. by
> > inspecting getManager(session).getClass().getName().
> >
> > Olaf
> >
> >
> >
> > > Here's my code:
> > >
> > > HttpSession session = httpServletRequest.getSession(false);
> > > try {
> > > RedissonSessionManager rsm = (RedissonSessionManager)
> > getManager(session);
> > > } catch (Exception e) {
> > > e.printStackTrace();
> > > }
> > >
> > > private Manager getManager(HttpSession session) throws Exception {
> > >
> > > Field facadeSessionField =
> > > StandardSessionFacade.class.getDeclaredField("session");
> > > facadeSessionField.setAccessible(true);
> > > StandardSession stdSession = (StandardSession)
> > > facadeSessionField.get(session);
> > >
> > > return stdSession.getManager();
> > > }
> > >
> > >
> > >
> > > On Thu, May 7, 2020 at 11:52 PM Mark Thomas  wrote:
> > >
> > >> On 07/05/2020 21:36, Jonathan Yom-Tov wrote:
> > >>> My application uses Redisson (a client which persists the session to
> > >>> Redis). There are two Redisson jar files located in
> $CATALINA_HOME/lib,
> > >> so
> > >>> if I understand the docs correctly they're loaded by the common class
> > >>> loader.
> > >>>
> > >>> I want to access the RedissonSessionManager class during a request.
> The
> > >>> problem is that if I do something like RedissonSessionManager
> manager =
> > >>> (RedissonSessionManager) session.getManager() I get a
> > ClassCastException,
> > >>> presumably because they were loaded by different class loaders.
> > >>>
> > >>> Will it help if I somehow access the common class loader for this? If
> > so
> > >>> how can I do that? If not is there some other way I can achieve this?
> > >> Make sure you don't have those JARs in your application's WEB-INF/lib
> as
> > >> well as $CATALINA_BASE/lib.
> > >>
> > >> In any recent version of Tomcat any JAR in $CATALINA_BASE/lib will be
> > >> visible to your application.
> > >>
> > >> Mark
> > >>
> > >> -
> > >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> > >> For additional commands, e-mail: users-h...@tomcat.apache.org
> > >>
> > >>
> >
> > -
> > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> > For additional commands, e-mail: users-h...@tomcat.apache.org
> >
> >
>
> --
> [image: SysAid Technologies]
> <
> http://www.sysaid.com/?utm_source=signature_medium=email_campaign=sysaid-logo
> >
> Jonathan Yom-Tov
> Senior Architect
> jonathan.yom...@sysaid.com
> Phone (IL): +972 (3) 533-3675 Ext. 932
> [image: SysAid Technologies]
> <
> https://www.sysaid.com/?utm_source=signature_medium=email_campaign=sysaid-logo-icon
> >
>   [image: SysAid on Facebook] 
>  [image:
> SysAid on Twitter]    [image: SysAid on
> Linked-in] 
>  [image:
> SysAid on YouTube]    [image:
> SysAid
> on Instagram] 
> [image: Banner] 
>


-- 

"Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better."

- Samuel Beckett


Re: how do I switch class loaders

2020-05-08 Thread Jonathan Yom-Tov
This is very odd. I ran Tomcat with -verbose:class (see relevant output
below). The class is being loaded twice from the same location, I'm
guessing by two different class loaders. How can that be?

[Loaded org.redisson.tomcat.RedissonSessionManager from
file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]
[Loaded org.redisson.tomcat.RedissonSessionManager$2 from
file:/C:/dev/tomcat.9.0.19/lib/redisson-tomcat-9-3.12.2.jar]

On Fri, May 8, 2020 at 11:04 AM Olaf Kock  wrote:

>
> On 08.05.20 09:37, Jonathan Yom-Tov wrote:
> > Thanks Mark. Just tried that. I put the redisson-tomcat jar outside of
> > WEB-INF/lib and added it with scope provided. I get the exact same issue.
> > What am I doing wrong?
>
> Make sure, it's actually gone from your webapp. Depending on the
> deployment technique I've seen removed files to persist from previous
> deployments.
>
> You might need to fully undeploy, then deploy the new version without
> the jar in question. But inspect the runtime environment to make sure
> you only have a single library accessible. Having the same class
> available two different ways is a recipe for disaster, don't fix it my
> messing with the classloader: Fix it by eliminating one of them.
>
> You might also check if you're not accessing any wrapped object, e.g. by
> inspecting getManager(session).getClass().getName().
>
> Olaf
>
>
>
> > Here's my code:
> >
> > HttpSession session = httpServletRequest.getSession(false);
> > try {
> > RedissonSessionManager rsm = (RedissonSessionManager)
> getManager(session);
> > } catch (Exception e) {
> > e.printStackTrace();
> > }
> >
> > private Manager getManager(HttpSession session) throws Exception {
> >
> > Field facadeSessionField =
> > StandardSessionFacade.class.getDeclaredField("session");
> > facadeSessionField.setAccessible(true);
> > StandardSession stdSession = (StandardSession)
> > facadeSessionField.get(session);
> >
> > return stdSession.getManager();
> > }
> >
> >
> >
> > On Thu, May 7, 2020 at 11:52 PM Mark Thomas  wrote:
> >
> >> On 07/05/2020 21:36, Jonathan Yom-Tov wrote:
> >>> My application uses Redisson (a client which persists the session to
> >>> Redis). There are two Redisson jar files located in $CATALINA_HOME/lib,
> >> so
> >>> if I understand the docs correctly they're loaded by the common class
> >>> loader.
> >>>
> >>> I want to access the RedissonSessionManager class during a request. The
> >>> problem is that if I do something like RedissonSessionManager manager =
> >>> (RedissonSessionManager) session.getManager() I get a
> ClassCastException,
> >>> presumably because they were loaded by different class loaders.
> >>>
> >>> Will it help if I somehow access the common class loader for this? If
> so
> >>> how can I do that? If not is there some other way I can achieve this?
> >> Make sure you don't have those JARs in your application's WEB-INF/lib as
> >> well as $CATALINA_BASE/lib.
> >>
> >> In any recent version of Tomcat any JAR in $CATALINA_BASE/lib will be
> >> visible to your application.
> >>
> >> Mark
> >>
> >> -
> >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> >> For additional commands, e-mail: users-h...@tomcat.apache.org
> >>
> >>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

-- 
[image: SysAid Technologies]

Jonathan Yom-Tov
Senior Architect
jonathan.yom...@sysaid.com
Phone (IL): +972 (3) 533-3675 Ext. 932
[image: SysAid Technologies]

  [image: SysAid on Facebook]    [image:
SysAid on Twitter]    [image: SysAid on
Linked-in]    [image:
SysAid on YouTube]    [image: SysAid
on Instagram] 
[image: Banner] 


Re: how do I switch class loaders

2020-05-08 Thread Olaf Kock


On 08.05.20 09:37, Jonathan Yom-Tov wrote:
> Thanks Mark. Just tried that. I put the redisson-tomcat jar outside of
> WEB-INF/lib and added it with scope provided. I get the exact same issue.
> What am I doing wrong?

Make sure, it's actually gone from your webapp. Depending on the
deployment technique I've seen removed files to persist from previous
deployments.

You might need to fully undeploy, then deploy the new version without
the jar in question. But inspect the runtime environment to make sure
you only have a single library accessible. Having the same class
available two different ways is a recipe for disaster, don't fix it my
messing with the classloader: Fix it by eliminating one of them.

You might also check if you're not accessing any wrapped object, e.g. by
inspecting getManager(session).getClass().getName().

Olaf



> Here's my code:
>
> HttpSession session = httpServletRequest.getSession(false);
> try {
> RedissonSessionManager rsm = (RedissonSessionManager) getManager(session);
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> private Manager getManager(HttpSession session) throws Exception {
>
> Field facadeSessionField =
> StandardSessionFacade.class.getDeclaredField("session");
> facadeSessionField.setAccessible(true);
> StandardSession stdSession = (StandardSession)
> facadeSessionField.get(session);
>
> return stdSession.getManager();
> }
>
>
>
> On Thu, May 7, 2020 at 11:52 PM Mark Thomas  wrote:
>
>> On 07/05/2020 21:36, Jonathan Yom-Tov wrote:
>>> My application uses Redisson (a client which persists the session to
>>> Redis). There are two Redisson jar files located in $CATALINA_HOME/lib,
>> so
>>> if I understand the docs correctly they're loaded by the common class
>>> loader.
>>>
>>> I want to access the RedissonSessionManager class during a request. The
>>> problem is that if I do something like RedissonSessionManager manager =
>>> (RedissonSessionManager) session.getManager() I get a ClassCastException,
>>> presumably because they were loaded by different class loaders.
>>>
>>> Will it help if I somehow access the common class loader for this? If so
>>> how can I do that? If not is there some other way I can achieve this?
>> Make sure you don't have those JARs in your application's WEB-INF/lib as
>> well as $CATALINA_BASE/lib.
>>
>> In any recent version of Tomcat any JAR in $CATALINA_BASE/lib will be
>> visible to your application.
>>
>> Mark
>>
>> -
>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>
>>

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: how do I switch class loaders

2020-05-08 Thread Jonathan Yom-Tov
Thanks Mark. Just tried that. I put the redisson-tomcat jar outside of
WEB-INF/lib and added it with scope provided. I get the exact same issue.
What am I doing wrong?

Here's my code:

HttpSession session = httpServletRequest.getSession(false);
try {
RedissonSessionManager rsm = (RedissonSessionManager) getManager(session);
} catch (Exception e) {
e.printStackTrace();
}

private Manager getManager(HttpSession session) throws Exception {

Field facadeSessionField =
StandardSessionFacade.class.getDeclaredField("session");
facadeSessionField.setAccessible(true);
StandardSession stdSession = (StandardSession)
facadeSessionField.get(session);

return stdSession.getManager();
}



On Thu, May 7, 2020 at 11:52 PM Mark Thomas  wrote:

> On 07/05/2020 21:36, Jonathan Yom-Tov wrote:
> > My application uses Redisson (a client which persists the session to
> > Redis). There are two Redisson jar files located in $CATALINA_HOME/lib,
> so
> > if I understand the docs correctly they're loaded by the common class
> > loader.
> >
> > I want to access the RedissonSessionManager class during a request. The
> > problem is that if I do something like RedissonSessionManager manager =
> > (RedissonSessionManager) session.getManager() I get a ClassCastException,
> > presumably because they were loaded by different class loaders.
> >
> > Will it help if I somehow access the common class loader for this? If so
> > how can I do that? If not is there some other way I can achieve this?
>
> Make sure you don't have those JARs in your application's WEB-INF/lib as
> well as $CATALINA_BASE/lib.
>
> In any recent version of Tomcat any JAR in $CATALINA_BASE/lib will be
> visible to your application.
>
> Mark
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

-- 
[image: SysAid Technologies]

Jonathan Yom-Tov
Senior Architect
jonathan.yom...@sysaid.com
Phone (IL): +972 (3) 533-3675 Ext. 932
[image: SysAid Technologies]

  [image: SysAid on Facebook]    [image:
SysAid on Twitter]    [image: SysAid on
Linked-in]    [image:
SysAid on YouTube]    [image: SysAid
on Instagram] 
[image: Banner] 


Re: how do I switch class loaders

2020-05-07 Thread Mark Thomas
On 07/05/2020 21:36, Jonathan Yom-Tov wrote:
> My application uses Redisson (a client which persists the session to
> Redis). There are two Redisson jar files located in $CATALINA_HOME/lib, so
> if I understand the docs correctly they're loaded by the common class
> loader.
> 
> I want to access the RedissonSessionManager class during a request. The
> problem is that if I do something like RedissonSessionManager manager =
> (RedissonSessionManager) session.getManager() I get a ClassCastException,
> presumably because they were loaded by different class loaders.
> 
> Will it help if I somehow access the common class loader for this? If so
> how can I do that? If not is there some other way I can achieve this?

Make sure you don't have those JARs in your application's WEB-INF/lib as
well as $CATALINA_BASE/lib.

In any recent version of Tomcat any JAR in $CATALINA_BASE/lib will be
visible to your application.

Mark

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



how do I switch class loaders

2020-05-07 Thread Jonathan Yom-Tov
My application uses Redisson (a client which persists the session to
Redis). There are two Redisson jar files located in $CATALINA_HOME/lib, so
if I understand the docs correctly they're loaded by the common class
loader.

I want to access the RedissonSessionManager class during a request. The
problem is that if I do something like RedissonSessionManager manager =
(RedissonSessionManager) session.getManager() I get a ClassCastException,
presumably because they were loaded by different class loaders.

Will it help if I somehow access the common class loader for this? If so
how can I do that? If not is there some other way I can achieve this?

Jon.