ClassCastException when hot-deploying a controller with a simple modification

Hi,

Since I use 6.9 cuba version (not sure if it’s due to that but that gives a hint), I meet this issue very often. Even by doing a small modification in a very simple controller, I have the below message.

ClassCastException: com.haulmont.charts.web.gui.components.charts.amcharts.WebSerialChart cannot be cast to com.haulmont.charts.gui.amcharts.model.charts.SerialChart

It’s not all the time, it depends on the modification I guess, but I’m now restarting the server much more often than I was used to when editing controllers. which reduce usefulness of hot deploying.

For instance with the small project in attachment, I just changed the injected variable from “serialChart” to “chart” while the server was running, and I had the message.

It seems to me that this kind of error was not happening before or much less. Maybe someone else noticed that ?

testchart.zip (78.8 KB)

Hi Michael,

This problem can be solved by the type-safe injection with a concrete chart subtype:

import com.haulmont.charts.gui.components.charts.SerialChart;
. . .

public class Screen extends AbstractWindow {

    @Inject
    private SerialChart chart;

    @Override
    public void init(Map<String, Object> params) {
        super.init(params);
        CategoryAxis ca = chart.getCategoryAxis();
        ca.addDateFormats(new DateFormat().setPeriod(DatePeriod.DAYS).setFormat("D-MMM"));
    }
}

Hi Olga,

Actually I did try that at first, but injection did not work (null pointer exception). As a complement, you can see below that if I declare SerialChart instead of Chart, there is no “<>” marker on the left side, meaning that it is not recognized.

image

image

Pay attention at the imported class above in my example:
import com.haulmont.charts.gui.components.charts.SerialChart. That’s the correct one.

The error cause is that you imported not a component class: com.haulmont.charts.gui.amcharts.model.charts.SerialChart, and with such import the problem will persist despite the class cast.
Honestly, I haven’t even noticed that before.

Indeed, my bad then.

On the core topic, let me know If I understand correctly.

If for instance i declare @Inject Field field and inject a TextField, then later change by a LookupField, hot-deploy wlil not work and I will meet the issue right ?

While Field, TextField and LookupField are all Components, hot-deploy will work. It will not work only if you import something which is not a visual component.

Understood, thank you Olga