V8: Reading Design files in Jetty 9.2.14 embedded wrong classpath
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.8k
- Forks
- 717
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 3
Description
@DALDEI commented on Mon May 21 2018
Vaadin V8, loading designer files (Design.read()) in jetty 9.2.14 uses the wrong classpath/classloader.
Perusing the history of code changes in vaadin-core it appears that the assumption for classloaders is that they will use the thead local context classloader. Jetty 9.2.14 does not do this. In Design.read the classloader is overridden with the thread local context loader. This is the System (or bootstrap) loader in jetty 9.2.14 and does not include the Vaadin runtime (atleast in my configuration).
A workaround is to swap in the current class's classloader into the thread context class loader for the duration of read(). To do so without changing the auto-generated constructor the following code works for me: (kotlin source, tested)
fun swapcls(cls: ClassLoader ) : ClassLoader =
Thread.currentThread().let {
val _cls = it.contextClassLoader
it.contextClassLoader = cls
_cls
}
Auto-generated Designer class
@DesignRoot
@AutoGenerated
@SuppressWarnings("serial")
public class CampaignInlineView extends HorizontalLayout
....
public CampaignInlineView()
{
Design.read(this);
}
...
Constructor of derived class
private class CampaignDetail(
val campaign: Campaign,
tls: ClassLoader = swapcls(CampaignDetail::class.java.getClassLoader())
) : CampaignInlineView() , View
In java this would be like this (untested)
class CampaignDetail : extends CampaignInlineView, implements View {
private CampaignDetail(Campaign impl, ClassLoader cls ) { super() ; swapcls(cls); }
public CampaignDetrail( Campaign impl ) {
this( impl ,
swapcls(CampaignDetail::class.getClassLoader() );
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at Design.read(), then reproduce the embedded Jetty 9.2.14 setup described in the issue and inspect how its classloader is selected. Done means designer files load with the Vaadin runtime available without requiring callers to swap the thread context classloader.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100