knockknock10 opened a new issue, #7003:
URL: https://github.com/apache/camel-k/issues/7003

   ### Bug description
   
   ## Description
   
   The Java source inspector generates invalid Java code when replacing a 
`fromF()` endpoint URI.
   
   In `pkg/util/source/inspector_java_source.go`, the 
`replaceURIDoubleQuotedFromF` regular expression matches Java `fromF()` calls 
with double-quoted URI arguments. However, the replacement in 
`replaceFromURIDoubleQuotesOnly()` generates the replacement call using single 
quotes:
   
   ```go
   source.Content = replaceURIDoubleQuotedFromF.ReplaceAllString(
       source.Content,
       fmt.Sprintf(`fromF('%s')`, newFromURI),
   )
   ```
   
   Java uses double quotes for String literals. Single quotes represent 
character literals, so the generated source is invalid.
   
   ## Steps to reproduce
   
   1. Start with a Java route containing:
   
   ```java
   fromF("timer:tick?period=60000").to("log:info");
   ```
   
   2. Invoke the Java source inspector's `ReplaceFromURI()` method with a 
replacement URI such as:
   
   ```text
   direct:cron-trigger
   ```
   
   3. Inspect the generated Java source.
   
   ## Actual behavior
   
   The inspector generates:
   
   ```java
   fromF('direct:cron-trigger').to("log:info");
   ```
   
   This is invalid Java. Compiling an equivalent Java source with `javac` 
produces errors such as `unclosed character literal`.
   
   ## Expected behavior
   
   The inspector should preserve valid Java String literal syntax and generate:
   
   ```java
   fromF("direct:cron-trigger").to("log:info");
   ```
   
   The corrected equivalent compiles successfully with `javac`.
   
   ## Impact
   
   Java integrations using `fromF()` with supported timer, cron, or quartz 
source URIs can receive invalid Java source when the Cron trait rewrites their 
endpoints.
   
   The issue appears to be localized to the Java source inspector's `fromF()` 
replacement logic.
   
   ## Suggested fix
   
   Change the replacement to use double quotes:
   
   ```go
   source.Content = replaceURIDoubleQuotedFromF.ReplaceAllString(
       source.Content,
       fmt.Sprintf(`fromF("%s")`, newFromURI),
   )
   ```
   
   Add a regression test covering `fromF()` URI replacement in 
`inspector_java_source_test.go`.
   
   ### Camel K or runtime version
   
   Apache Camel K: 2.5.0-nightly-1303-g2e20c093e Commit: 
2e20c093eba75942ce032780ba2275a07a9bf817


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to