You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Sahoo (JIRA)" <ji...@apache.org> on 2013/10/02 17:00:47 UTC

[jira] [Created] (FELIX-4266) findbugs reported errors related to arrays being stored/returned directly

Sahoo created FELIX-4266:
----------------------------

             Summary: findbugs reported errors related to arrays being stored/returned directly 
                 Key: FELIX-4266
                 URL: https://issues.apache.org/jira/browse/FELIX-4266
             Project: Felix
          Issue Type: Bug
          Components: Framework
    Affects Versions: framework-4.2.1
            Reporter: Sahoo
            Assignee: Sahoo
            Priority: Minor
             Fix For: framework-4.4.0


FindBugs on Felix reported following two issues:

- Should change code to make a clone of the return value and return the copy, not the internal representation.
- Should change code to store a clone of the external mutable object.

Below are the fixes to these two issues:  

framework/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java  (revision 1528211)
+++ framework/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java  (working copy)
@@ -18,10 +18,11 @@
  */
 package org.apache.felix.framework.util.manifestparser;

+import org.osgi.framework.Constants;
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import org.osgi.framework.Constants;

 public class R4Library
 {
@@ -37,10 +38,10 @@
         String[] languages, String selectionFilter) throws Exception
     {
         m_libraryFile = libraryFile;
-        m_osnames = osnames;
-        m_processors = processors;
-        m_osversions = osversions;
-        m_languages = languages;
+        m_osnames = osnames == null ? osnames : osnames.clone();
+        m_processors = processors == null ? processors : processors.clone();
+        m_osversions = osversions == null ? osversions : osversions.clone();
+        m_languages = languages == null ? languages : languages.clone();
         m_selectionFilter = selectionFilter;
     }

@@ -51,22 +52,22 @@

     public String[] getOSNames()
     {
-        return m_osnames;
+        return m_osnames == null ? m_osnames : m_osnames.clone();
     }

     public String[] getProcessors()
     {
-        return m_processors;
+        return m_processors == null ? m_processors : m_processors.clone();
     }

     public String[] getOSVersions()
     {
-        return m_osversions;
+        return m_osversions == null ? m_osversions : m_osversions.clone();
     }

     public String[] getLanguages()
     {
-        return m_languages;
+        return m_languages == null ? m_languages : m_languages.clone();
     }

     public String getSelectionFilter()
@@ -184,4 +185,4 @@
         }
         return "*";
     }
-}
\ No newline at end of file
+} 



--
This message was sent by Atlassian JIRA
(v6.1#6144)