You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by ju...@apache.org on 2018/01/09 22:49:28 UTC

[kafka] branch trunk updated: KAFKA-4247; Prevent CLASSPATH from beginning with a single colon

This is an automated email from the ASF dual-hosted git repository.

junrao pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new abf4c54  KAFKA-4247; Prevent CLASSPATH from beginning with a single colon
abf4c54 is described below

commit abf4c547017304c9b1e743723bdcb0b8a4df1ad0
Author: Chris Egerton <ch...@confluent.io>
AuthorDate: Tue Jan 9 14:49:18 2018 -0800

    KAFKA-4247; Prevent CLASSPATH from beginning with a single colon
    
    Different fix for problem addressed by https://github.com/apache/kafka/pull/1953. Should prevent the CLASSPATH environment variable from being prefixed by a single colon before the JVM is invoked in the run-class script, which will then prevent the current working directory from being unintentionally included in the classpath when using the Reflections library.
    
    If the current working directory should still be included in the classpath, it just needs to be explicitly specified either with its fully-qualified pathname or as a single dot (".").
    
    Author: Chris Egerton <ch...@confluent.io>
    
    Reviewers: Randall Hauch <rh...@gmail.com>, Jun Rao <ju...@gmail.com>
    
    Closes #4406 from C0urante/fix-colon-prefixed-classpath
---
 bin/kafka-run-class.sh | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/bin/kafka-run-class.sh b/bin/kafka-run-class.sh
index fc89f25..6676d0d 100755
--- a/bin/kafka-run-class.sh
+++ b/bin/kafka-run-class.sh
@@ -59,11 +59,7 @@ fi
 shopt -s nullglob
 for dir in "$base_dir"/core/build/dependant-libs-${SCALA_VERSION}*;
 do
-  if [ -z "$CLASSPATH" ] ; then
-    CLASSPATH="$dir/*"
-  else
-    CLASSPATH="$CLASSPATH:$dir/*"
-  fi
+  CLASSPATH="$CLASSPATH:$dir/*"
 done
 
 for file in "$base_dir"/examples/build/libs/kafka-examples*.jar;
@@ -260,6 +256,11 @@ if [ "x$GC_LOG_ENABLED" = "xtrue" ]; then
   fi
 fi
 
+# Remove a possible colon prefix from the classpath (happens at lines like `CLASSPATH="$CLASSPATH:$file"` when CLASSPATH is blank)
+# Syntax used on the right side is native Bash string manipulation; for more details see
+# http://tldp.org/LDP/abs/html/string-manipulation.html, specifically the section titled "Substring Removal"
+CLASSPATH=${CLASSPATH#:}
+
 # If Cygwin is detected, classpath is converted to Windows format.
 (( CYGWIN )) && CLASSPATH=$(cygpath --path --mixed "${CLASSPATH}")
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@kafka.apache.org" <co...@kafka.apache.org>'].