nielifeng opened a new issue, #11463:
URL: https://github.com/apache/seatunnel/issues/11463

   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/seatunnel/issues?q=is%3Aissue+label%3A%22bug%22)
 and found no similar issues.
   
   ### What happened
   
   In `LogUtil.getLogPath` 
(`seatunnel-engine/seatunnel-engine-common/src/main/java/org/apache/seatunnel/engine/common/utils/LogUtil.java:49-56`):
   
   ```java
   if (logRef.equals(routingAppender)) {
       return routingLogFilePath.substring(0, 
routingLogFilePath.lastIndexOf("/"));
   } else if (logRef.equals(fileAppender)) {
       return fileLogPath.substring(0, routingLogFilePath.lastIndexOf("/"));   
// <-- wrong variable
   }
   ```
   
   The `fileAppender` branch substrings `fileLogPath`, but computes the cut 
index from `routingLogFilePath` — a copy-paste leftover from the 
`routingAppender` branch above. Since `getRoutingLogFilePath` returns `null` 
(`.orElse(null)`) when no `routingAppender` is configured, this breaks in the 
fileAppender-only case:
   
   - **Only `fileAppender` configured** → `routingLogFilePath` is `null` → 
`routingLogFilePath.lastIndexOf("/")` throws **`NullPointerException`**.
   - **Both configured, routing path longer than file path** → the index from 
the longer routing string exceeds `fileLogPath.length()` → 
**`StringIndexOutOfBoundsException`**.
   - **Both configured, routing path shorter** → returns a wrong/truncated 
directory.
   
   `getLogPath()` is reachable from the REST log endpoints 
(`AllNodeLogServlet`, `CurrentNodeLogServlet`, `LogService` / 
`BaseLogService`), so a fileAppender-only deployment hits this when any 
log-path REST API is called.
   
   <details>
   <summary>Standalone reproduction program (uses the exact branch 
logic)</summary>
   
   ```java
   public class LogUtilRepro {
       static String getLogPath(String logRef, String routingLogFilePath, 
String fileLogPath) {
           String routingAppender = "routingAppender";
           String fileAppender = "fileAppender";
           if (logRef.equals(routingAppender)) {
               return routingLogFilePath.substring(0, 
routingLogFilePath.lastIndexOf("/"));
           } else if (logRef.equals(fileAppender)) {
               // === verbatim from source: substrings fileLogPath but uses 
routingLogFilePath's index ===
               return fileLogPath.substring(0, 
routingLogFilePath.lastIndexOf("/"));
           } else {
               throw new IllegalArgumentException("empty logRef");
           }
       }
   
       public static void main(String[] args) {
           // Scenario A: only fileAppender configured -> routingLogFilePath == 
null
           try { getLogPath("fileAppender", null, 
"/opt/seatunnel/logs/seatunnel.log"); }
           catch (NullPointerException e) { System.out.println("A: 
NullPointerException"); }
   
           // Scenario B: both configured, routing longer than file
           try { getLogPath("fileAppender", 
"/very/long/routing/path/dir/app.log", "/short.log"); }
           catch (StringIndexOutOfBoundsException e) { System.out.println("B: 
StringIndexOutOfBoundsException: " + e.getMessage()); }
       }
   }
   ```
   
   Output on OpenJDK 1.8.0_462:
   
   ```
   A: NullPointerException
   B: StringIndexOutOfBoundsException: String index out of range: 27
   ```
   
   </details>
   
   **Suggested fix** (one line): use `fileLogPath`'s own index in the 
`fileAppender` branch:
   
   ```java
   } else if (logRef.equals(fileAppender)) {
       return fileLogPath.substring(0, fileLogPath.lastIndexOf("/"));
   }
   ```
   
   ### SeaTunnel Version
   
   dev (current HEAD). `LogUtil.java:49-56` is unchanged on the current branch.
   
   ### SeaTunnel Config
   
   N/A for the code path itself — this is a logic bug on the log-path 
resolution branch, reproduced with a standalone program using the exact branch 
logic (see collapsible section). In practice it is triggered by a log4j2 
configuration that defines only `fileAppender` (no `routingAppender`).
   
   ### Running Command
   
   N/A — in a real deployment, start a Zeta node with a fileAppender-only 
log4j2 config and call any log REST endpoint (e.g. the current-node log / 
all-node log APIs), which invokes `BaseLogService.getLogPath()` -> 
`LogUtil.getLogPath()`.
   
   ### Error Exception
   
   ```log
   java.lang.NullPointerException
       at 
org.apache.seatunnel.engine.common.utils.LogUtil.getLogPath(LogUtil.java:52)
   
   # or, when both appenders are configured and the routing path is longer:
   java.lang.StringIndexOutOfBoundsException: String index out of range: 27
       at java.lang.String.substring(String.java:1963)
       at 
org.apache.seatunnel.engine.common.utils.LogUtil.getLogPath(LogUtil.java:52)
   ```
   
   ### Zeta or Flink or Spark Version
   
   Zeta (SeaTunnel Engine).
   
   ### Java or Scala Version
   
   OpenJDK 1.8.0_462 (Temurin).
   
   ### Screenshots
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
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