CDV ❯ Conflicting class adapter definitions should cause an error
-
Bug
-
Status: Open
-
2 Major
-
Resolution:
-
Byte Code Transform
-
-
interfaces
-
Reporter: wharley
-
May 07, 2009
-
0
-
Watchers: 2
-
December 16, 2011
-
Description
The user in FORGE-460 declared both tim-ehcache-1.4.1 and tim-hibernate-3.2.5 in his tc-config, in version 3.0. Since tim-hibernate-3.2.5 has a POM dependency on tim-ehcache-1.3, both tim-ehcache versions got resolved. However, both tim-ehcaches define adapters for net.sf.ehcache.Cache, and they replace that class with different versions of TCCache. So which won? No way to know, but evidence suggests it was the wrong one. It would have been better for this to be an error or at the very least a warning in the log.
Comments
Puneet Bhardwaj 2009-05-29
Alex Miller 2009-06-25
Puneet, I believe your comment belongs with the more specific FORGE-460 instead of here - this jira is a more generic problem with class adapters that is being exposed by FORGE-460.
Geert Bevin 2009-06-25
I can understand that conflicting replacements should create an error, however I would actually be in favor of adding support for multiple adapters. At the moment only the adapter of the last registered TIM will be used for a class. Imho it would be better to build up a chain of adapters.
Geert Bevin 2009-07-08
I implemented support for multiple custom class adapters for the same class in r13051, this should solve this issue. However, QA would do well to test that the intended behavior is achieved now.
Alex Miller 2009-07-08
Actually, the original problem was an *undesired* conflict when having both tim-ehcache-1.3 and tim-ehcache-1.4 both loaded and adapting some of the same classes. So the original problem should not be expected to work. Really need a separate use case to test this.
Tim Eck 2009-07-08
Yep. I think the spirit of this JIRA was specifically to make this an error condition somehow, not to just allow it to happen. Of course it seems we have times when we want more than one adapter so generating an error at that level doesn’t seem appropriate for this scenario. The ehcache TIMs will need to detect each other through some other means
Walter Harley 2009-07-09
Tim is correct: I was looking for a way to ensure that when two conflicting adapters are loaded, the customer can discover the situation.
If “the ehcache TIMs will need to detect each other through some other means”, then the same will be true for practically all other versioned TIMs, and we should provide an API that TIMs can call to discover this, rather than have each TIM reinvent the wheel (or, worse, forget to reinvent the wheel).
Perhaps the right solution is to support cumulative class adapters (per Geert’s fix) but warn or error on multiple TIM versions (i.e., same artifact ID but different version number)?
Geert Bevin 2009-07-13
I think we should indeed warn when for the same TIM artifact ID different versions are loaded, that seems like a logical and intuitive approach.
Walter Harley 2009-07-13
Although, that wouldn’t have helped in this case; tim-ehcache-1.3 and tim-ehcache-1.4 have different artifact IDs.
It is hard to tell when a second class adapter is intended to supplement an existing adapter, versus when that is a sign of a violated assumption. Another possibility would be to have class adapters be more proactive about verifying that the bytecode being modified corresponds to what is expected. This is tied to the question of how flexible one wants to be about instrumenting slightly different versions of a class.
Geert Bevin 2009-07-14
Yeah, I was wondering about that too. Initially it actually occurred to me that we should maybe introduce ‘features’ that TIMs expose. These would be independent from the naming. It would then only be possible to install one TIM for a particular feature.
Liferay is facing a similar issue. They need support for tim-ehcache-1.4.1 and tim-hibernate-3.2.5. This results in the following error on starting a second liferay instance -
The current workaround that they are using, is to change the dependency of tim-ehcache in the pom.xml for tim-hibernate-3.2.5-1.3.1.