From 83cc04d7c79d37b8569e8158e5b26496787c15de Mon Sep 17 00:00:00 2001 From: Rafael da Fonseca Date: Sun, 14 Jun 2015 14:17:40 +0200 Subject: [PATCH] Fix 3 findbugs encoding warnings in VmwareStorageProcessor.java Ova templates and metadata should be written to file in UTF-8 Fix warning in UUID generation --- .../storage/resource/VmwareStorageProcessor.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java index ab1a01d66cf3..0bad8a63ccb9 100644 --- a/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java +++ b/plugins/hypervisors/vmware/src/com/cloud/storage/resource/VmwareStorageProcessor.java @@ -30,6 +30,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; +import java.io.UnsupportedEncodingException; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; @@ -680,7 +681,7 @@ private void postCreatePrivateTemplate(String installFullPath, long templateId, // TODO a bit ugly here BufferedWriter out = null; try { - out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(installFullPath + "/template.properties"))); + out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(installFullPath + "/template.properties"),"UTF-8")); out.write("filename=" + templateName + ".ova"); out.newLine(); out.write("description="); @@ -859,7 +860,7 @@ private void writeMetaOvaForTemplate(String installFullPath, String ovfFilename, // TODO a bit ugly here BufferedWriter out = null; try { - out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(installFullPath + "/" + templateName + ".ova.meta"))); + out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(installFullPath + "/" + templateName + ".ova.meta"),"UTF-8")); out.write("ova.filename=" + templateName + ".ova"); out.newLine(); out.write("version=1.0"); @@ -1388,7 +1389,13 @@ private Answer attachVolume(Command cmd, DiskTO disk, boolean isAttach, boolean } private static String getSecondaryDatastoreUUID(String storeUrl) { - return UUID.nameUUIDFromBytes(storeUrl.getBytes()).toString(); + String uuid = null; + try{ + uuid=UUID.nameUUIDFromBytes(storeUrl.getBytes("UTF-8")).toString(); + }catch(UnsupportedEncodingException e){ + s_logger.warn("Failed to create UUID from string " + storeUrl + ". Bad storeUrl or UTF-8 encoding error." ); + } + return uuid; } public synchronized ManagedObjectReference prepareSecondaryDatastoreOnHost(String storeUrl) throws Exception {