Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"cannot find symbol" issue in camel-k releases v1.4.0 #2317

Closed
liurui-1 opened this issue May 22, 2021 · 15 comments
Closed

"cannot find symbol" issue in camel-k releases v1.4.0 #2317

liurui-1 opened this issue May 22, 2021 · 15 comments

Comments

@liurui-1
Copy link
Contributor

Our Camel integration code cannot run on new camel-k releases v1.4.0. There are a number of Java files in our camel integration app. So, we are using some Java files to share some public symbols for example constants and static methods. The Java Integrations are working very well on previous camel-k releases v1.3.x. While with the new camel-k releases v1.4.0, it is failed because symbols from different Java files are isolated.

For example, we have two Java files: Test1.java and Test2.java.

//Test1.java

// camel-k: language=java

import org.apache.camel.builder.RouteBuilder;

public class Test1 extends RouteBuilder {

public static final String info = "from Test1";

@Override
public void configure() throws Exception {
  from("timer:tm1?period=1000")
    .setBody().constant("test1")
    .to("direct:test2");
}

}

Test2.java

// camel-k: language=java

import org.apache.camel.builder.RouteBuilder;

public class Test2 extends RouteBuilder {

public void configure() throws Exception {

  from("direct:test2")
    .log("${body}")
    .process(exchange -> {
      System.out.println(Test1.info);
    });
}

}

When you run the Camel integration with following command:
kamel run --dev --name mytest Test1.java Test2.java

You can find following error messages:

[1] 2021-05-22 15:34:14,256 ERROR [org.apa.cam.qua.mai.CamelMainRuntime] (main) Failed to start application: org.apache.camel.RuntimeCamelException: org.joor.ReflectException: Compilation error: warning: unknown enum constant XmlAccessType.PROPERTY
[1]   reason: class file for javax.xml.bind.annotation.XmlAccessType not found
[1] warning: unknown enum constant XmlAccessType.NONE
[1] warning: unknown enum constant XmlAccessType.FIELD
[1] warning: unknown enum constant XmlAccessType.PROPERTY
[1] /Test2.java:12: error: cannot find symbol
[1]       System.out.println(Test1.info);
[1]                          ^
[1]   symbol:   variable Test1
[1]   location: class Test2
[1] 1 error
[1] 4 warnings
[1]
[1]     at org.apache.camel.RuntimeCamelException.wrapRuntimeCamelException(RuntimeCamelException.java:51)
[1]     at org.apache.camel.k.support.SourcesSupport.load(SourcesSupport.java:172)
[1]     at org.apache.camel.k.support.SourcesSupport.loadSources(SourcesSupport.java:86)
[1]     at org.apache.camel.k.listener.SourcesConfigurer.accept(SourcesConfigurer.java:79)
[1]     at org.apache.camel.k.listener.AbstractPhaseListener.accept(AbstractPhaseListener.java:32)
[1]     at org.apache.camel.k.quarkus.Application$ListenerAdapter.invokeListeners(Application.java:135)
[1]     at org.apache.camel.k.quarkus.Application$ListenerAdapter.beforeConfigure(Application.java:97)
[1]     at org.apache.camel.main.BaseMainSupport.postProcessCamelContext(BaseMainSupport.java:533)
[1]     at org.apache.camel.quarkus.main.CamelMain.initCamelContext(CamelMain.java:116)
[1]     at org.apache.camel.quarkus.main.CamelMain.doInit(CamelMain.java:86)
[1]     at org.apache.camel.support.service.BaseService.init(BaseService.java:83)
[1]     at org.apache.camel.quarkus.main.CamelMain.startEngine(CamelMain.java:137)
[1]     at org.apache.camel.quarkus.main.CamelMainRuntime.start(CamelMainRuntime.java:49)
[1]     at org.apache.camel.quarkus.core.CamelBootstrapRecorder.start(CamelBootstrapRecorder.java:45)
[1]     at io.quarkus.deployment.steps.CamelBootstrapProcessor$boot-173480958.deploy_0(CamelBootstrapProcessor$boot-173480958.zig:101)
[1]     at io.quarkus.deployment.steps.CamelBootstrapProcessor$boot-173480958.deploy(CamelBootstrapProcessor$boot-173480958.zig:40)
[1]     at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:523)
[1]     at io.quarkus.runtime.Application.start(Application.java:90)
[1]     at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:100)
[1]     at io.quarkus.runtime.Quarkus.run(Quarkus.java:66)
[1]     at io.quarkus.runtime.Quarkus.run(Quarkus.java:42)
[1]     at io.quarkus.runtime.Quarkus.run(Quarkus.java:119)
[1]     at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
[1]     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[1]     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[1]     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[1]     at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[1]     at io.quarkus.bootstrap.runner.QuarkusEntryPoint.doRun(QuarkusEntryPoint.java:48)
[1]     at io.quarkus.bootstrap.runner.QuarkusEntryPoint.main(QuarkusEntryPoint.java:25)
[1] Caused by: org.joor.ReflectException: Compilation error: warning: unknown enum constant XmlAccessType.PROPERTY
[1]   reason: class file for javax.xml.bind.annotation.XmlAccessType not found
[1] warning: unknown enum constant XmlAccessType.NONE
[1] warning: unknown enum constant XmlAccessType.FIELD
[1] warning: unknown enum constant XmlAccessType.PROPERTY
[1] /Test2.java:12: error: cannot find symbol
[1]       System.out.println(Test1.info);
[1]                          ^
[1]   symbol:   variable Test1
[1]   location: class Test2
[1] 1 error
[1] 4 warnings
[1]
[1]     at org.joor.Compile.compile(Compile.java:102)
[1]     at org.joor.Reflect.compile(Reflect.java:104)
[1]     at org.joor.Reflect.compile(Reflect.java:79)
[1]     at org.apache.camel.dsl.java.joor.JavaRoutesBuilderLoader.loadRoutesBuilder(JavaRoutesBuilderLoader.java:69)
[1]     at org.apache.camel.impl.engine.DefaultRoutesLoader.findRoutesBuilders(DefaultRoutesLoader.java:100)
[1]     at org.apache.camel.spi.RoutesLoader.findRoutesBuilders(RoutesLoader.java:66)
[1]     at org.apache.camel.k.support.SourcesSupport.load(SourcesSupport.java:165)
[1]     ... 27 more
[1]
[1] 2021-05-22 15:34:14,267 ERROR [io.qua.run.Application] (main) Failed to start application (with profile prod): org.joor.ReflectException: Compilation error: warning: unknown enum constant XmlAccessType.PROPERTY
[1]   reason: class file for javax.xml.bind.annotation.XmlAccessType not found
[1] warning: unknown enum constant XmlAccessType.NONE
[1] warning: unknown enum constant XmlAccessType.FIELD
[1] warning: unknown enum constant XmlAccessType.PROPERTY
[1] /Test2.java:12: error: cannot find symbol
[1]       System.out.println(Test1.info);
[1]                          ^
[1]   symbol:   variable Test1
[1]   location: class Test2
[1] 1 error
[1] 4 warnings
[1]
[1]     at org.joor.Compile.compile(Compile.java:102)
[1]     at org.joor.Reflect.compile(Reflect.java:104)
[1]     at org.joor.Reflect.compile(Reflect.java:79)
[1]     at org.apache.camel.dsl.java.joor.JavaRoutesBuilderLoader.loadRoutesBuilder(JavaRoutesBuilderLoader.java:69)
[1]     at org.apache.camel.impl.engine.DefaultRoutesLoader.findRoutesBuilders(DefaultRoutesLoader.java:100)
[1]     at org.apache.camel.spi.RoutesLoader.findRoutesBuilders(RoutesLoader.java:66)
[1]     at org.apache.camel.k.support.SourcesSupport.load(SourcesSupport.java:165)
[1]     at org.apache.camel.k.support.SourcesSupport.loadSources(SourcesSupport.java:86)
[1]     at org.apache.camel.k.listener.SourcesConfigurer.accept(SourcesConfigurer.java:79)
[1]     at org.apache.camel.k.listener.AbstractPhaseListener.accept(AbstractPhaseListener.java:32)
[1]     at org.apache.camel.k.quarkus.Application$ListenerAdapter.invokeListeners(Application.java:135)
[1]     at org.apache.camel.k.quarkus.Application$ListenerAdapter.beforeConfigure(Application.java:97)
[1]     at org.apache.camel.main.BaseMainSupport.postProcessCamelContext(BaseMainSupport.java:533)
[1]     at org.apache.camel.quarkus.main.CamelMain.initCamelContext(CamelMain.java:116)
[1]     at org.apache.camel.quarkus.main.CamelMain.doInit(CamelMain.java:86)
[1]     at org.apache.camel.support.service.BaseService.init(BaseService.java:83)
[1]     at org.apache.camel.quarkus.main.CamelMain.startEngine(CamelMain.java:137)
[1]     at org.apache.camel.quarkus.main.CamelMainRuntime.start(CamelMainRuntime.java:49)
[1]     at org.apache.camel.quarkus.core.CamelBootstrapRecorder.start(CamelBootstrapRecorder.java:45)
[1]     at io.quarkus.deployment.steps.CamelBootstrapProcessor$boot-173480958.deploy_0(CamelBootstrapProcessor$boot-173480958.zig:101)
[1]     at io.quarkus.deployment.steps.CamelBootstrapProcessor$boot-173480958.deploy(CamelBootstrapProcessor$boot-173480958.zig:40)
[1]     at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:523)
[1]     at io.quarkus.runtime.Application.start(Application.java:90)
[1]     at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:100)
[1]     at io.quarkus.runtime.Quarkus.run(Quarkus.java:66)
[1]     at io.quarkus.runtime.Quarkus.run(Quarkus.java:42)
[1]     at io.quarkus.runtime.Quarkus.run(Quarkus.java:119)
[1]     at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
[1]     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[1]     at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[1]     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[1]     at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[1]     at io.quarkus.bootstrap.runner.QuarkusEntryPoint.doRun(QuarkusEntryPoint.java:48)
[1]     at io.quarkus.bootstrap.runner.QuarkusEntryPoint.main(QuarkusEntryPoint.java:25)
[1]
Condition "Ready" is "False" for Integration mytest

@lburgazzoli
Copy link
Contributor

This support has been removed a while ago, see apache/camel-k-runtime#480.

Each java file is compiled in its own compilation unit and loaded by a dedicated classloader so there's no visibility between them.

@liurui-1
Copy link
Contributor Author

liurui-1 commented May 24, 2021

@lburgazzoli The problem of this change is to reduce code reusability. For example in our Camel-k integration, we have 3-10 routes sharing same group of constants and static methods/functions. With this change, we have to copy all those definitions to each Java file. It makes the Java file much longer, difficult to read and more error-pone with inconsistency issues.
And those constants and static methods/functions are only for our own system, we do not expect to expose them to public Maven repository.

@lburgazzoli
Copy link
Contributor

I understand but camel-k is not designed to be a generic build tool and when you start adding such inter-dependecies between classes, a lot of issues may happen i.e. camel-k does not have any clue about dependencies so you may end up with the same issue if the code is compiled in a different order. A CR is also not the best place where to store source code.

There is another issue related to this issue so we may introduce some sort of support for this in the future but I'd really recommend to avoid it and publish support code as an artifact.

@liurui-1
Copy link
Contributor Author

Thanks @lburgazzoli to mention #1821 .
I fully agree and suggest to support POJO again, maybe with some restrictions, especially when Camel v1.4.0 isolate all Java files. As I mentioned in previous posts, we badly need some features to reuse our code. We need to install our product into many customer environments, it is not a good solution to build those constants and utility functions into Maven artifacts.

@lburgazzoli
Copy link
Contributor

Can you give more info about why it is not a good solution to build those constants and utility functions into Maven artifacts. ?

@liurui-1
Copy link
Contributor Author

liurui-1 commented May 24, 2021

@lburgazzoli It is information (constants and utility functions) just for our own app. Our own app is under development with new requests every day. It means those constants and utility functions are changing frequently. I do not expect to post the utility into public maven because of security issues, license issue, and frequent changing. It also adds more complexity to install and update a private Maven repo in customer's environments, and we will have more resource cost.

@oscerd
Copy link
Contributor

oscerd commented May 24, 2021

If you are using this constants and utilities in multiple customer deployments, any change not centralized will cost updating the classes everywhere. I don't see so much differences into releasing a maven artifacts and update a version everywhere. It's more secure, more reliable and it will need to pass through a workflow. This won't happen with modification on classes.

@liurui-1
Copy link
Contributor Author

@oscerd
It requires a full process to upload the artifact to public Maven repo. I do not see any people upload their utility class into public Maven just for private use in their own app. If you have 100s versions of such Maven artifacts then you may get into trouble. And we have unique version for the whole bunch of code including Camel integration including the utilities (the Camel code is more important). We do not expect to separate them.
For private Maven repo, it is viable. But more cost and more efforts.

@oscerd
Copy link
Contributor

oscerd commented May 24, 2021

What you're saying is that you want to deploy snapshot code. We are discussing two different entities.

@oscerd
Copy link
Contributor

oscerd commented May 24, 2021

A released artifact on private or public nexus needs to deal with a sequence of steps and verification. Using snapshot code is a different story.

@liurui-1
Copy link
Contributor Author

liurui-1 commented May 24, 2021

@oscerd Yes the utility can be snapshot code. I cannot imagine if you upgrade utility class with Maven but do not upgrade the Camel code at the same time. So we have to have many versions of the utility class to be compatible with the Camel code.

Note, Camel-k is for micro services instead of some products with long time of well modeling. If you restrict us to use public Maven to post the utility class, we just lose the capability of Changing fast which is one of the most important factors for us to choose Camel-k.

@oscerd
Copy link
Contributor

oscerd commented May 24, 2021

There is jitpack support for snapshot code eventually.

@oscerd
Copy link
Contributor

oscerd commented May 24, 2021

There is no restrictions. You can use multiple ways of depending of snapshot code. There are different approaches to this.

But in my opinion if they are dependencies of the main camel code they should be provided as a separated artifact/package/tag etc.

@liurui-1
Copy link
Contributor Author

@oscerd I am sorry for late response. Yes it is a solution but not very convincing to me. It is not convenient. We can also use our own maven repository. While this changes a lot of the programming practice to build all your Java code other than those Camel DSL into separate Maven artifacts. I still expect if you can enable supporting POJO again maybe with some limits.

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale due to 90 days of inactivity.
It will be closed if no further activity occurs within 15 days.
If you think that’s incorrect or the issue should never stale, please simply write any comment.
Thanks for your contributions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants