Skip to content

Commit 5a6d7da

Browse files
committed
Merge branch 'master' into graal
2 parents 5ab8fcc + 2e6154d commit 5a6d7da

File tree

26 files changed

+185
-92
lines changed

26 files changed

+185
-92
lines changed

visualvm/appui/src/org/graalvm/visualvm/modules/appui/AboutAction.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ private String getBuildNumber() {
9898
try {
9999
InputStream manifestStream = getClass().getResourceAsStream("/META-INF/MANIFEST.MF"); // NOI18N
100100
buildNumber = new Manifest(manifestStream).getMainAttributes().getValue("OpenIDE-Module-Implementation-Version"); // NOI18N
101+
manifestStream.close();
101102
} catch (IOException ex) {}
102103
}
103104

visualvm/charts/src/org/graalvm/visualvm/charts/xy/XYPainter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.awt.Polygon;
3333
import java.awt.Rectangle;
3434
import java.util.List;
35+
import java.util.Locale;
3536
import org.graalvm.visualvm.lib.charts.ChartContext;
3637
import org.graalvm.visualvm.lib.charts.ChartItem;
3738
import org.graalvm.visualvm.lib.charts.swing.LongRect;
@@ -57,7 +58,7 @@ public class XYPainter extends SynchronousXYItemPainter {
5758
// --- Initializer ---------------------------------------------------------
5859

5960
{
60-
String _mode = System.getProperty("visualvm.charts.defaultMode", "minmax").toLowerCase(); // NOI18N
61+
String _mode = System.getProperty("visualvm.charts.defaultMode", "minmax").toLowerCase(Locale.ENGLISH); // NOI18N
6162
if ("fast".equals(_mode)) { // NOI18N
6263
mode = 0;
6364
} else {

visualvm/core/manifest.mf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ OpenIDE-Module: org.graalvm.visualvm.core/0
55
OpenIDE-Module-Layer: org/graalvm/visualvm/core/layer.xml
66
OpenIDE-Module-Localizing-Bundle: org/graalvm/visualvm/core/Bundle.properties
77
OpenIDE-Module-Install: org/graalvm/visualvm/core/Install.class
8-
OpenIDE-Module-Specification-Version: 1.6
8+
OpenIDE-Module-Specification-Version: 1.7
99

visualvm/core/src/org/graalvm/visualvm/core/datasupport/Utils.java

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.io.FileOutputStream;
3636
import java.io.InputStream;
3737
import java.util.ArrayList;
38+
import java.util.Arrays;
3839
import java.util.Base64;
3940
import java.util.Collection;
4041
import java.util.Collections;
@@ -396,17 +397,24 @@ public static File extractArchive(File archive, File destination) {
396397
ZipFile zipFile = null;
397398

398399
try {
400+
String destinationPath = directory.getCanonicalPath();
399401
prepareDirectory(directory);
400402

401403
zipFile = new ZipFile(archive);
402404
Enumeration<? extends ZipEntry> entries = zipFile.entries();
403405
while (entries.hasMoreElements()) {
404406
ZipEntry entry = entries.nextElement();
407+
File entryFile = new File(directory, entry.getName());
408+
409+
String entryFilePath = entryFile.getCanonicalPath();
410+
if (!entryFilePath.startsWith(destinationPath))
411+
throw new IllegalStateException("Archive entry outside of destination directory: " + entryFilePath); // NOI18N
412+
405413
FileOutputStream fos = null;
406414
InputStream is = null;
407415
try {
408416
is = zipFile.getInputStream(entry);
409-
fos = new FileOutputStream(new File(directory, entry.getName()));
417+
fos = new FileOutputStream(entryFile);
410418
int bytes;
411419
byte[] packet = new byte[COPY_PACKET_SIZE];
412420
while ((bytes = is.read(packet, 0, COPY_PACKET_SIZE)) != -1) fos.write(packet, 0, bytes);
@@ -436,7 +444,28 @@ public static String encodePassword(String value) {
436444
}
437445

438446
/**
439-
* Decodes given string using the Base64 enconding.
447+
* Encodes given char[] using the Base64 encoding. The original parameter value is overwritten.
448+
*
449+
* @param value char[] to be encoded.
450+
* @return encoded char[].
451+
*
452+
* @since VisualVM 1.4.3
453+
*/
454+
public static char[] encodePassword(char[] value) {
455+
byte[] bytes = charsToBytes(value);
456+
Arrays.fill(value, (char)0);
457+
458+
byte[] bytes2 = Base64.getEncoder().encode(bytes);
459+
Arrays.fill(bytes, (byte)0);
460+
461+
char[] chars = bytesToChars(bytes2);
462+
Arrays.fill(bytes2, (byte)0);
463+
464+
return chars;
465+
}
466+
467+
/**
468+
* Decodes given string using the Base64 encoding.
440469
*
441470
* @param value String to be decoded.
442471
* @return decoded String.
@@ -445,6 +474,27 @@ public static String decodePassword(String value) {
445474
return new String(Base64.getDecoder().decode(value));
446475
}
447476

477+
/**
478+
* Decodes given char[] using the Base64 encoding. The original parameter value is overwritten.
479+
*
480+
* @param value char[] to be decoded.
481+
* @return decoded char[].
482+
*
483+
* @since VisualVM 1.4.3
484+
*/
485+
public static char[] decodePassword(char[] value) {
486+
byte[] bytes = charsToBytes(value);
487+
Arrays.fill(value, (char)0);
488+
489+
byte[] bytes2 = Base64.getDecoder().decode(bytes);
490+
Arrays.fill(bytes, (byte)0);
491+
492+
char[] chars = bytesToChars(bytes2);
493+
Arrays.fill(bytes2, (byte)0);
494+
495+
return chars;
496+
}
497+
448498
/**
449499
* Encodes given image to String using the Base64 encoding.
450500
* This is primarily intended to store small images (icons)
@@ -491,5 +541,24 @@ private static byte[] imageToBytes(Image image, String format) {
491541

492542
return outputStream.toByteArray();
493543
}
494-
544+
545+
private static byte[] charsToBytes(char[] chars) {
546+
byte[] bytes = new byte[chars.length * 2];
547+
for (int i = 0; i < chars.length; i++) {
548+
bytes[i * 2] = (byte)((chars[i] & 0xff00) >> 8);
549+
bytes[i * 2 + 1] = (byte)(chars[i] & 0x00ff);
550+
}
551+
return bytes;
552+
}
553+
554+
private static char[] bytesToChars(byte[] bytes) {
555+
char[] chars = new char[bytes.length / 2];
556+
for (int i = 0; i < chars.length; i++) {
557+
char ch = (char)(((bytes[i * 2] & 0x00ff) << 8) +
558+
(bytes[i * 2 + 1] & 0x00ff));
559+
chars[i] = ch;
560+
}
561+
return chars;
562+
}
563+
495564
}

visualvm/core/src/org/graalvm/visualvm/core/scheduler/SchedulingPipe.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ final class SchedulingPipe {
6868
}
6969

7070
void addTask(DefaultScheduledTask task) {
71+
tasksLock.writeLock().lock();
7172
try {
72-
tasksLock.writeLock().lock();
7373
if (tasks.isEmpty()) {
7474
startPipe();
7575
}
@@ -84,8 +84,8 @@ private void startPipe() {
8484
pipeFuture = schedulerService.scheduleAtFixedRate(new Runnable() {
8585

8686
public void run() {
87+
tasksLock.writeLock().lock();
8788
try {
88-
tasksLock.writeLock().lock();
8989
final long timeStamp = System.currentTimeMillis();
9090
for (Iterator<WeakReference<DefaultScheduledTask>> iter = tasks.iterator(); iter.hasNext();) {
9191
WeakReference<DefaultScheduledTask> ref = iter.next();
@@ -120,8 +120,8 @@ public void run() {
120120
}
121121

122122
void removeTask(DefaultScheduledTask task) {
123+
tasksLock.writeLock().lock();
123124
try {
124-
tasksLock.writeLock().lock();
125125
for(Iterator<WeakReference<DefaultScheduledTask>> iter = tasks.iterator();iter.hasNext();) {
126126
WeakReference<DefaultScheduledTask> ref = iter.next();
127127
DefaultScheduledTask t = ref.get();

visualvm/heapviewer/src/org/graalvm/visualvm/heapviewer/oql/OQLQueries.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.nio.file.Files;
3838
import java.util.ArrayList;
3939
import java.util.List;
40+
import java.util.Locale;
4041
import javax.swing.BorderFactory;
4142
import javax.swing.Icon;
4243
import javax.swing.JComponent;
@@ -308,7 +309,7 @@ private void loadFromFile(final Handler handler) {
308309
chooser.setFileFilter(new FileFilter() {
309310
public boolean accept(File f) {
310311
if (f.isDirectory()) return true;
311-
String fname = f.getName().toLowerCase();
312+
String fname = f.getName().toLowerCase(Locale.ENGLISH);
312313
if (fname.endsWith(".oql") || fname.endsWith(".txt")) return true; // NOI18N
313314
return false;
314315
}
@@ -383,7 +384,7 @@ private void saveToFile(OQLSupport.Query query, String queryText, Handler handle
383384
chooser.setFileFilter(new FileFilter() {
384385
public boolean accept(File f) {
385386
if (f.isDirectory()) return true;
386-
String fname = f.getName().toLowerCase();
387+
String fname = f.getName().toLowerCase(Locale.ENGLISH);
387388
if (fname.endsWith(".oql") || fname.endsWith(".txt")) return true; // NOI18N
388389
return false;
389390
}
@@ -396,7 +397,7 @@ public String getDescription() {
396397
File file = chooser.getSelectedFile();
397398
lastDirectory = file.getParentFile();
398399

399-
String fname = file.getName().toLowerCase();
400+
String fname = file.getName().toLowerCase(Locale.ENGLISH);
400401
if (!fname.endsWith(".oql") && !fname.endsWith(".txt")) // NOI18N
401402
file = new File(file.getParentFile(), file.getName() + ".oql"); // NOI18N
402403

visualvm/jmx/nbproject/project.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<compile-dependency/>
2222
<run-dependency>
2323
<release-version>0</release-version>
24-
<specification-version>1.6</specification-version>
24+
<specification-version>1.7</specification-version>
2525
</run-dependency>
2626
</dependency>
2727
<dependency>

visualvm/jmx/src/org/graalvm/visualvm/jmx/CredentialsProvider.java

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
*/
5252
public abstract class CredentialsProvider extends EnvironmentProvider {
5353

54-
private static final String PROPERTY_USERNAME = "prop_credentials_username"; // NOI18N
55-
private static final String PROPERTY_PASSWORD = "prop_credentials_password"; // NOI18N
54+
private static final String PROPERTY_USER = "prop_credentials_user"; // NOI18N
55+
private static final String PROPERTY_PWORD = "prop_credentials_pword"; // NOI18N
5656

5757
private static Persistent PERSISTENT_PROVIDER;
5858

@@ -90,8 +90,8 @@ public String getId() {
9090
*/
9191
public static class Custom extends CredentialsProvider {
9292

93-
private final String username;
94-
private final char[] password;
93+
private final String user;
94+
private final char[] pword;
9595
private final boolean persistent;
9696

9797

@@ -103,32 +103,32 @@ public static class Custom extends CredentialsProvider {
103103
* @param persistent true if the credentials should be persisted for another VisualVM sessions, false otherwise
104104
*/
105105
public Custom(String username, char[] password, boolean persistent) {
106-
this.username = username;
107-
this.password = encodePassword(password);
106+
this.user = username;
107+
this.pword = encodePassword(password);
108108
this.persistent = persistent;
109109
}
110110

111111

112112
public Map<String, ?> getEnvironment(Application application, Storage storage) {
113-
return createMap(username, password != null ? new String(password) : null);
113+
return createMap(user, pword);
114114
}
115115

116116
public String getEnvironmentId(Storage storage) {
117-
if (username != null) return username;
117+
if (user != null) return user;
118118
return super.getEnvironmentId(storage);
119119
}
120120

121121
public void saveEnvironment(Storage storage) {
122122
if (!persistent) return;
123-
storage.setCustomProperty(PROPERTY_USERNAME, username);
124-
storage.setCustomProperty(PROPERTY_PASSWORD, new String(password));
123+
storage.setCustomProperty(PROPERTY_USER, user);
124+
storage.setCustomProperty(PROPERTY_PWORD, new String(pword));
125125
}
126126

127127

128-
String getUsername(Storage storage) { return username; }
128+
String getUsername(Storage storage) { return user; }
129129

130-
boolean hasPassword(Storage storage) { return password != null &&
131-
password.length > 0; }
130+
boolean hasPassword(Storage storage) { return pword != null &&
131+
pword.length > 0; }
132132

133133
boolean isPersistent(Storage storage) { return persistent; }
134134

@@ -144,26 +144,26 @@ boolean hasPassword(Storage storage) { return password != null &&
144144
public static class Persistent extends CredentialsProvider {
145145

146146
public Map<String, ?> getEnvironment(Application application, Storage storage) {
147-
String username = storage.getCustomProperty(PROPERTY_USERNAME);
148-
String password = storage.getCustomProperty(PROPERTY_PASSWORD);
149-
return createMap(username, password);
147+
String user = storage.getCustomProperty(PROPERTY_USER);
148+
char[] pword = storage.getCustomProperty(PROPERTY_PWORD).toCharArray();
149+
return createMap(user, pword);
150150
}
151151

152152
public String getEnvironmentId(Storage storage) {
153153
if (storage != null) {
154-
String username = storage.getCustomProperty(PROPERTY_USERNAME);
155-
if (username != null) return username;
154+
String user = storage.getCustomProperty(PROPERTY_USER);
155+
if (user != null) return user;
156156
}
157157
return super.getEnvironmentId(storage);
158158
}
159159

160160

161161
String getUsername(Storage storage) { return storage.getCustomProperty(
162-
PROPERTY_USERNAME); }
162+
PROPERTY_USER); }
163163

164164
boolean hasPassword(Storage storage) {
165-
String password = storage.getCustomProperty(PROPERTY_PASSWORD);
166-
return password != null && password.length() > 0;
165+
String pword = storage.getCustomProperty(PROPERTY_PWORD);
166+
return pword != null && pword.length() > 0;
167167
}
168168

169169
boolean isPersistent(Storage storage) {
@@ -175,24 +175,21 @@ boolean isPersistent(Storage storage) {
175175

176176
// --- Private implementation ----------------------------------------------
177177

178-
private static Map<String, ?> createMap(String username, String password) {
178+
private static Map<String, ?> createMap(String username, char[] pword) {
179179
Map map = new HashMap();
180180

181181
if (username != null && !username.isEmpty())
182-
map.put(JMXConnector.CREDENTIALS,
183-
new String[] { username, decodePassword(password) });
182+
map.put(JMXConnector.CREDENTIALS, new String[] { username, new String(decodePassword(pword)) });
184183

185184
return map;
186185
}
187186

188-
private static char[] encodePassword(char[] password) {
189-
if (password == null) return null;
190-
return Utils.encodePassword(new String(password)).toCharArray();
187+
private static char[] encodePassword(char[] pword) {
188+
return pword == null ? null : Utils.encodePassword(pword);
191189
}
192190

193-
private static String decodePassword(String password) {
194-
if (password == null) return null;
195-
return Utils.decodePassword(password);
191+
private static char[] decodePassword(char[] pword) {
192+
return pword == null ? null : Utils.decodePassword(pword);
196193
}
197194

198195
}

visualvm/jmx/src/org/graalvm/visualvm/jmx/impl/CredentialsConfigurator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ public String getUsername() {
7474
return usernameField.getText().trim();
7575
}
7676

77-
public String getPassword() {
78-
return new String(passwordField.getPassword());
77+
public char[] getPassword() {
78+
return passwordField.getPassword();
7979
}
8080

8181
private CredentialsConfigurator() {
@@ -94,8 +94,8 @@ private void update() {
9494
SwingUtilities.invokeLater(new Runnable() {
9595
public void run() {
9696
String username = getUsername();
97-
String password = getPassword();
98-
okButton.setEnabled(username.length() > 0 && password.length() > 0);
97+
char[] password = getPassword();
98+
okButton.setEnabled(username.length() > 0 && password.length > 0);
9999
}
100100
});
101101
}

0 commit comments

Comments
 (0)