Use public getter to retrieve name from JarFile
ZipFile provides a public getter 'getName()' hence there is no need to use reflection to access its private member 'name'. Change-Id: If622fce7f902cc65483d66b834aff2c585b645e2 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
@@ -22,7 +22,6 @@ import java.io.FileNotFoundException;
|
|||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
@@ -324,11 +323,8 @@ public final class GerritLauncher {
|
|||||||
// ZipFile may have the path of our JAR hiding within itself.
|
// ZipFile may have the path of our JAR hiding within itself.
|
||||||
//
|
//
|
||||||
try {
|
try {
|
||||||
Field nameField = ZipFile.class.getDeclaredField("name");
|
|
||||||
nameField.setAccessible(true);
|
|
||||||
|
|
||||||
JarFile jar = ((JarURLConnection) myClazz.openConnection()).getJarFile();
|
JarFile jar = ((JarURLConnection) myClazz.openConnection()).getJarFile();
|
||||||
File path = new File((String) nameField.get(jar));
|
File path = new File(jar.getName());
|
||||||
if (path.isFile()) {
|
if (path.isFile()) {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user