Opened 5 years ago

Last modified 5 years ago

#20456 closed defect

[Patch] Classloader problem with loading look and feel from plugin (FlatLaf) — at Version 4

Reported by: DevCharly Owned by: team
Priority: normal Milestone: 21.02
Component: Core Version:
Keywords: Cc:

Description (last modified by Don-vip)

There is a problem with classloaders and look and feel plugins.
JOSM uses two different classloaders for same laf plugin:

  • PluginClassLoader to load laf plugin
  • DynamicURLClassLoader for laf initialization

Both classloaders include the laf plugin jar (flatlaf.jar in my case).
So it seems to work, but FlatLaf can not find the properties files in the plugin and JOSM specific colors and UI delegates are missing.

The necessary information to load plugin properties files is stored in a static variable in class FlatLaf.
Because class FlatLaf is loaded into two classloaders, there are two instances of the static variable.

The static variable is set in FlatLafPlugin constructor by invoking FlatLaf.registerCustomDefaultsSource().
This is done with a PluginClassLoader.

Later when the laf is initialized with UIManager.setLookAndFeel(), this static variable is null because this is done in DynamicURLClassLoader.

Tried to workaround this without success.

The reason for the different classloaders is that PluginHandler.getResourceClassLoaders() is used in MainApplication.setupUIManager() to find/load the laf class from a plugin.

See:
https://josm.openstreetmap.de/browser/josm/trunk/src/org/openstreetmap/josm/gui/MainApplication.java#L1075

IMO PluginHandler.getPluginClassLoaders() should be used instead.
This fixes the issue.
Can we change this?

Change History (7)

by DevCharly, 5 years ago

comment:1 by DevCharly, 5 years ago

Color preferences without/with fix:


Plugin preferences without/with fix:


comment:2 by stoecker, 5 years ago

Milestone: 21.0121.02

Milestone renamed

comment:3 by skyper, 5 years ago

Summary: Classloader problem with loading look and feel from plugin (FlatLaf)[Patch] Classloader problem with loading look and feel from plugin (FlatLaf)

comment:4 by Don-vip, 5 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.