Unchecked conversion Warnings!!

1. how do i get rid of these unchecked conversion warning for
List<Element> children = new ArrayList<Element>(element.getChildren( "result" ));
where element.getChildren( "result" ) returns a list of Elements.
warning is :
warning: [unchecked] unchecked conversion
found : java.util.List
required: java.util.Collection<? extends org.jdom.Element>
List<Element> children = new ArrayList<Element>(element.getChildren( "result"
2. warning: [deprecation] setIndent(java.lang.String) in org.jdom.output.XMLOutputter has been deprecated
output.setIndent(" ");

1. The message is correct, your code is not safe
The problem is that getChildren returns List not List<Element>. Do you understand the diference? how can a List of an especified type (Element) be created on a List that accepts everything?
This will solve your problem:
//most obvious way to do it
List<Element> children = new ArrayList<Element>();
for (Iterator i = element.getChildren( "result" ).iterator(); i.hasNext();){
    children.add((Element) i.next()); //may throw class cast exception
}Do you get the comment about class cast exception? I sugest reading the Generics Tutorial that comes with the jdk documentation.
2 The method is deprecated, this means it is there but not supported (This is the java way : -) Go to the API for the reason...
I did that for you and the method does not even exist anymore, try updating to version 1.0 .

Similar Messages

  • Unchecked conversion

    Hi all,
    I have a Swing application that uses few generic classes. Currently I'm trying to remove all warnings in my code (adding serialVersionUID is very annoying by the way). I want to express one of my problem with a basic sample.
    Consider that I define a generic class A:
    public class A<T> {
         public List<String> getList() {
              return new ArrayList<String>();
    }And another class B that uses A:
    public class B {
         public void doSomethingUnsecure(A a) {
              List<String> list = a.getList();
              for(String item : list) {
                   System.out.println(item);
         public void doSomethingSecure(A a) {          
              for(Object o : a.getList()) {
                   String item = (String)o;               
                   System.out.println(item);
    }I have a few question regarding this piece of code:
    1) Why 'List<String> list = a.getList();' in 'doSomethingUnsecure' gives a warning ? It's not the case if A is not generic.
    The warning is "Type safety: The expression of type List needs unchecked conversion to conform to List<String>"
    2) Why I get no warning at all for 'doSomethingSecure' ?
    3) Is there a better way to go around this problem than casting each element in the list (like in doSomethingSecure) ?

    >
    public class A<T> {
         public List<String> getList() {
              return new ArrayList<String>();
    public class B {
         public void doSomethingUnsecure(A a) {
              List<String> list = a.getList();
              for(String item : list) {
                   System.out.println(item);
         public void doSomethingSecure(A a) {          
              for(Object o : a.getList()) {
                   String item = (String)o;               
                   System.out.println(item);
    }1) Why 'List<String> list = a.getList();' in 'doSomethingUnsecure' gives a warning ? It's not the case if A is not generic.Because once you declare A<T>, java is going to generate a warning every time you use A without some kind of <> after it.
    A generic type is forever generic. Using the "raw" type is permissible, and sometimes even necessary, but it always gets a warning.
    You want to tell it A<SomeClass>, and you want to try and make sure that your <SomeClass> is correct. If you can't, then you might be able to get away with using A<?>, as suggested, if you are treating the A<> item as read-only.
    2) Why I get no warning at all for 'doSomethingSecure' ?Because anything can fit into a variable of type Object, so iterating with "Object o" is okay. No cast is needed in this case.
    3) Is there a better way to go around this problem than casting each element in the list (like in doSomethingSecure) ?Get the type parameters right, as mentioned above.
    =Austin

  • Warning: [unchecked] unchecked conversion.. how to avoid this warning?

    Hi all,
    When i compile my java file, i get this warning.
    Z:\webapps\I2SG_P2\WEB-INF\classes\com\i2sg>javac testwincDB.java
    Note: testwincDB.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    Z:\webapps\I2SG_P2\WEB-INF\classes\com\i2sg>javac -Xlint testwincDB.java
    testwincDB.java:15: warning: [unchecked] unchecked conversion
    found   : java.util.ArrayList
    required: java.util.ArrayList<java.lang.String[]>
        ArrayList <String[] > recRep2 = dbh.getReconReport2(projID);My functions are:
    public ArrayList getReconReport2(int projID)
            ArrayList <String[] > recRep2 = new ArrayList <String[] > ();
            String getReconReportQuery2 = "select recon_count FROM i2sg_recon1 WHERE PROJECT_ID = " + projID;
            int i=0;
            try {
            resultSet = statement.executeQuery(getReconReportQuery2);
                  while (resultSet.next())
                         recRep2.add(new String[1]); // 0:RECON_COUNT
                ((String []) recRep2.get(i))[0] = resultSet.getString("RECON_COUNT");
                         i++;
                  resultSet.close();
                  } catch (Exception ex)
                ex.printStackTrace(System.out);
            return recRep2;
        }and
    import java.sql.*;
    import java.util.ArrayList;
    import java.util.*;
    public class testwincDB
        public static void main(String args[])
        int projID=8;
        wincDB dbh = new wincDB();
        ArrayList <String[] > recRep2 = dbh.getReconReport2(projID);
        int totalRec = recRep2.size();
         for(int i=0;i<totalRec;i++)
        System.out.println(((String []) recRep2.get(i))[0]);
    }Thanks in advance,
    Lakshma

    found : java.util.ArrayList
    required: java.util.ArrayList<java.lang.String[]>
    ArrayList <String[] > recRep2 = dbh.getReconReport2(projID);This tells all about the warning.....
    public ArrayList getReconReport2(int projID)change it to:
    public ArrayList<String[]> getReconReport2(int projID)Thanks!
    Edit: Very late.... :-)
    Edited by: T.B.M on Jan 15, 2009 7:20 PM

  • Conversion Warnings in Acrobat 7.0 Pro

    I am having problems with my pdf's of our newspaper pages that we send to our online subscribers.  I create a reduced size paper so that it's not so massive that they won't be able to download it.  I have been having complaints that pages are missing sections.  We have checked it on several different computers by downloading as our subscribers would, and we have had no problem.  However, several of our subscribers say it is still happening to their copies.  Today when I was preparing the pages for tomorrow's edition, I watched how I am getting a warning that says "Conversion Warnings - The PDF contained image masks that were not downsampled".  I had this happen on 5 pages that I was working on.
    What am I doing wrong?  I am thinking that these pages may cause problems tomorrow for some of our subscribers. Incidentally, these suscribers  just informed me that this has been happening for quite some time.  I have to admit that I was getting that conversion warning message, but had never heard any complaints, so I assumed it was not causing problems!
    Can somebody help me out here?

    Hi Michael, Thank you so much for the reply. You would think Adobe Support could have told me that so I really appreciate it. Do you know what I need to do to upgrade it ? Can I find an upgrade on E-Bay or do I need to go to COMP USA or some other place to buy the upgrade? Last, what exactly am I looking for to upgrade it to the newest version. (Name of product). I will also remove the other program so it won't have any other issues once I get the upgrade. Thanks again and God Bless, Tony

  • How to avoid "unchecked cast" warnings

    Hi all,
    here is my code:
    private Vector<String> vector1;
    private Vector<String> vector2=new Vector<String>();
    vector1=(Vector<String>)vector2.clone();
    ...How can i avoid "unchecked cast" warnings, while compiling with "-Xlint:unchecked" option.

    I'd also add that you should think about the following idioms:
    1. Ask yourself do I really need a synchronized structure? The answer might be that unsynchronized structure like ArrayList might be more appropriate. If you DO need a concurrent structure then you may find high-performance one in java.util.concurrent package.
    2. Using interfaces will be more appropriate in the long run:
    List<String> l = new ArrayList<String>(); because you can replace the implementation of the specific interface with more appropriate structure just on one place.
    Best regards,
    Andrej

  • Removing unchecked call warnings

    I have moved from 1.4.2 to 1.5.0 today, and now I'm trying to solve all the unchecked call warnings that I had in the code, but I have one that I don't know how to avoid it.
    I need a matrix of nxn dimensions where every element is an Integer. I was creating this matrix in a recursive way, with a recursion deep of n. For example, if n=3, I had finally a Vector<Vector<Vector<Vector<Integer> > > >. As n is configurable by the user, I can't determine the data types that i must declare in the recursive calls that I use to manage the matrix.
    There is a class to implement my "matrix" in a simplest way?
    If not, there is a way to remove the warnings in the recursive calls?
    If not, I suppose that I must keep the warnings...
    Jorge

    Well, my use of the matrix is not mathematical but to represent the "real world".
    I'm working in the project previous to the University graduation, and I'm implementing a communication protocol among different computers.
    Those computers are linked in n dimensions (I have let configurable the dimensions because I think that flexibility is important for things like this).
    If n=1, the computers are linked like this:
    A - B - C -D - E -F - G - H - J
    If I have n = 2 the computers are linked like this:
    A - B - C
    | \ | / |
    D - E - F
    | / | \ |
    G - H - J
    (Well, in the post preview this last configuration looks very bad because some spaces are trim: The "E" computer is linked to all the rest of computers)
    If I have n = 3 the computers are linked in a cube shape, if I have n = 4 in an hipercube, and so on.
    That's why I need a multidimensional matrix to represent my network.
    I have a class that encapsulates the access to all the linked neighbours of a computer, and internally it stores these neighbours as a Vector of Vector's. of Vector's...(n times)
    For example, to create all the neighbour objects, I must write code like this:
    private Vector neighbours; // I don't know what I must write inside <> next to Vector declaration
    neighbours = new Vector(LINKS_IN_DIMENSION); // Again, the warning complains the lack of <>, but I don't know what goes inside
    initializeDimensionVector(1, neighbours);
    // In the method declaration, I need again the <> specification but is not possible
    private void initializeDimensionVector(int dimension, Vector vecDimension)
         vecDimension.setSize(LINKS_IN_DIMENSION);
         if ( NET_DIMENSIONS == dimension )
              for ( int i = 0; i < LINKS_IN_DIMENSION; ++i )
              vecDimension.setElementAt(new NeighbourDirectlyConnected(), i);
              return;
         for ( int i = 0; i < LINKS_IN_DIMENSION; ++i )
              // And finally here, for the new recursive call, the unspecified Vector declaration appears again
              vecDimension.setElementAt(new Vector(LINKS_IN_DIMENSION), i);
              initializeDimensionVector(dimension + 1, (Vector)vecDimension.elementAt(i));
    }The number of dimensions n is represented by NET_DIMENSIONS.
    The other constant (LINKS_IN_DIMENSION) tells how many different indexes we have per dimension.
    Hope this sample code explains a little bit what I'm trying to do.
    I can close my eyes and forget the warnings, but I come from the C++ world and experience tells that warnings musn't be ignored.
    Regards and thanks for your help.
    Jorge.

  • Help with "unchecked conversion" warning

    Hello,
    following line
    Vector devices = SomeDeviceManager.getDeviceList();
    gives a warning (when compiled in java 1.5 with -Xlint):
    found raw type: java.util.Vector
    missing type parameters for generic class java.util.Vector<E>
    When I change code to
    Vector<DeviceInfo> devices = SomeDeviceManager.getDeviceList();
    warning turns into "unchecked conversion" warning. SomeDeviceManager is from some old .jar library, so it's not possible to change getDeviceList signature.
    How can I eliminate this warning?
    Thanks.

    @SuppressWarnings("unchecked")
    - Saish

  • Unchecked conversion warning - What is the proper way to fix this?

    I've been trying to figure this out for awhile now, and I have not seen an example that will set me on the right track. Given the following code:
            public TreeSet<String> sort = new TreeSet<String>(CI_NE_Comparator);
            public static Comparator CI_NE_Comparator = new CaseInsensitiveNeverEqualsComparator();
            public static class CaseInsensitiveNeverEqualsComparator implements Comparator
              public int compare(Object o1, Object o2)
                   String s1 = (String) o1;
                   String s2 = (String) o2;
                   int compare = s1.trim().toLowerCase().compareTo(s2.trim().toLowerCase());
                   if (compare == 0)
                        return 1; // ensure like values are never deemed equal
                   return compare;
         }I'm getting a warning declaring the class variable sort:
    Type safety: The expression of type Comparator needs unchecked conversion to conform to Comparator <? super String>
    So just what is the proper method to make the Comparator conform to generics?
    ** Btw - if anyone knows of a better way to do that comparator, I'm all ears!

    Why don't you want like values to be deemed equal?
    What would be wrong with using
    String.CASE_INSENSITIVE_ORDER?The code you see above is a stripped down example. We have the need to present data records in alphabetical order to a user, and sometimes these records have the same dscr, but that doesn't necessarily mean it's a unique record. Because of the backing query, I can't rely on the order in which the records were received.
    I can't modify the queries. Also, I can't modify the 30 or so different types of data records, all having the common field dscr, so that I can write a better implementation. But, I can write a better comparator.
    This is all legacy code that I've been working with, so I have to make sure things work as they did before.

  • Generics with JAXB and Unchecked Conversions

    If there is a more appropriate forum for JAXB related posts, my apologies, I browsed the list and didn't see one.
    Here's my schema:
         </complexType>
         <element name="songList"
              type="com:songListType"/>
         <complexType name="songListType">
              <sequence>
                   <element name="songList"
                        type="string" minOccurs="0" maxOccurs="unbounded"/>
              </sequence>
         </complexType>And my question os
    Is there a way to get JAXB to generate a class that has a method lie
    List<String> getSongList();Instead of
    List getSongList();I'd like to eliminate the unchecked conversions. If anyone has any suggestions or can reference a tutorial, I'd greatly appreciate some tips.
    Thanks

    Wow, sorry for all the typos btw

  • Working around unchecked conversions when using reflection

    I think I've convinced myself that there's no way around this issue when using reflection and Generics, but here's the issue:
    Suppose I've got a method that uses reflection to compare an arbitrary property in
    an arbitrary pair of beans (of the same class).
    public static <T> int compare(T bean0, T bean1, String prop) throws Exception {
         Method m = bean0.getClass().getMethod(
                   "get" + prop.substring(0,1).toUpperCase() +
                   prop.substring(1));
         Object o0 = m.invoke(bean0);
         Object o1 = m.invoke(bean1);
         if (o0 instanceof Comparable &&
             o1 instanceof Comparable &&
             (o1.getClass().isAssignableFrom(o0.getClass()) ||
              o0.getClass().isAssignableFrom(o1.getClass()))) {
              return ((Comparable)o0).compareTo(o1); // compiler warning
         } else {
              return o0.toString().compareTo(o1.toString());
    }There's no way that, in general, when using reflection to invoke methods, that you can coerce the types to avoid compile-time type safety warnings. I think the above code is guarranteed not to throw a runtime ClassCastException, but there's no way to write the code so that the compiler can guarrantee it. At least that's what I think. Am I wrong?

    Ok it looks like you're dealing with a classloader issue. when you call that method, it is the equivelant of calling
    Class.forName("Box", true, this.getClass().getClassLoader())The exception is thrown when your class's classloader cannot find the class box. try putting 'null' there
    Class.forName("Box", true, null)and it will request the bootstrap classloader to load the class. just make sure you have permission :
    If the loader is null, and a security manager is present, and the caller's class loader is not null, then this method calls the security manager's checkPermission method with a RuntimePermission("getClassLoader") permission to ensure it's ok to access the bootstrap class loader. (copied from the API)

  • Character set conversion warnings in Gtk apps

    Recently I noticed that various Gtk applications throw this warning (actually, many times, pretty much every time something in the window needs updating) when running them:
    (gimp:5803): Gdk-WARNING **: Error converting from UTF-8 to STRING: Conversion from character set 'UTF-8' to 'ISO-8859-1' is not supported
    (gvim:5697): Gdk-WARNING **: Error converting from UTF-8 to STRING: Could not open converter from 'UTF-8' to 'ISO-8859-1'
    These are examples with gimp and gvim, but the same goes for alunn, rox, firefox, gtk-chtheme, ...
    I tried to search various forums and google, but nobody seems to address this issue, and if, then it's along the lines "recompile everything and start with gtk2". That's not satisfactory for me. Especially, since some apps (like gimp) sometimes crash with this error.
    Some info: I run with LC_ALL=en_US.UTF-8 and LANG=en_US.UTF-8, and locales defined in locale.gen include en_US.UTF-8 and en_US ISO-8859-1, and I did generate the locales (locale-gen).
    Any help/ideas about what to do with this are appreciated.
    EDIT: couldn't it be a problem with the recent update of glibc (on 02/15)?
    Last edited by bender02 (2007-02-23 05:49:44)

    Well, talking to myself here - I just wanted to say that recent upgrade to glibc-2.5-5 seems to have solved the issue.

  • Installing old VIs in newer LabVIEW folder: how to avoid conversion warnings?

    We are offering a set of VIs to our users. We build our own installer which installs them into the LabVIEW program folder under vi.lib. A menu file is installed in the menus tor which collects the VIs in a palette.
    For providing compatibility with LV 8.2 and up the VIs are in v8.2 format. When they are installed in a higher LV version and a LV program that contains some of the VIs is closed, LV issues the warning that the VIs have been recompiled and converted from an older format. How can we install the VIs so that LV ignores the format version?

    smercurio_fc wrote:
    I did not mean to imply that setting the read-only flag would fix your problem. Only that it would prevent the file from being saved, if that's what you were intending to be done. You cannot change the behavior, as it is by design. You can deal with it by compiling the VIs when you install the software, as has been mentioned. Or, you can distribute pre-compiled versions in the LabVIEW versions of your choice.
    You mean it is definitely not possible to have VIs in one, relatively old LabVIEW format and install them for newer LabVIEW versions without getting this (completely useless) warning? This is hard to believe. How do other companies distribute their LabVIEW programming interfaces? Do they really maintain a VI versions for every LV version (and possible sub-version) just to guarantee a good user experience?
    Since the recompiled changes are dumped anyway, I would expect a VI or library flag I could set or a special way of installing the VIs that tells LabVIEW: ignore the changes when the VI is closed.
    Recompiling everything during installation is not what we want since it would make the installation process too complicated, in which our LabVIEW API is just a small part. If nothing else works I would rather install the VIs writable so the user could just hit "save all" when he closes his program and get rid of the warnings, but this is not optimal.
    Olf

  • Unchecked conversion found

    Hi this issue involves two classes.
    in my first class I declare sonarData by doing the following:
    private ArrayList<SonarData> sonarDataArray = new ArrayList<SonarData>();
    further down in my code I call on a method from another class:
    sonarDataArray = fp.parseFiles();
    fp.parseFiles() returns an array list which i declared the same way as the first one:
    private ArrayList<SonarData> sonarDataArray = new ArrayList<SonarData>();
    The issue happens with fp.parseFiles(). It recognizes this as just an ArrayList not an ArrayList<SonarData>
    Hope this makes sense, thanks for any help

    It ArrayList is declared as:
    private ArrayList<SonarData> sonarDataArray = new ArrayList<SonarData>();
    And the method returns sonarDataArray so it should be ArrayList<SonarData> however when I compile it says found ArrayList looking for ArrayList<SonarData>

  • Unchecked problem while compiling

    When compiling, I get a non-fatal warning, 'unchecked', what ever that means. It is the command flag Xlint-unchecked or something.
    The code is a static hashtable which I am statically putting elements into:
    public static Hashtable variables = new Hashtable();
    static{
      variables.put("###",...);
      //another 30 lines or so of the same...
    }1. What does unchecked mean?
    2. Why does the Hashtable give me this warning?
    3. How can it be fixed?
    Thanks

    This all has to do with the addition of generics to Java 5. Generics allow the specification of data types in the code so that errors (for instance, placing a String value in a hashtable intended to hold Integers) can be detected at compile time rather than run time.
    You are compiling some code that doesn't specify the data type.
    Add the following to the javac option to see the details of the warning. (See the javac documentation.)
    -Xlint:unchecked
    Give more detail for unchecked conversion warnings that are mandated by the Java Language Specification.
    Refer to this for what to do to fix it:
    http://java.sun.com/j2se/1.5.0/docs/guide/language/generics.html

  • How to use a ".generate" file in JDeveloper 11g ?

    hi
    Using JDeveloper 11g (11.1.1.0.1) I created a Database Diagram and dropped both SCOTT.EMP and SCOTT.DEPT tables on it, creating Offline Database Objects.
    After that I used the "Generate..." option from the right-click menu on the SCOTT Offline Database Source in JDeveloper, to generate a SQL script.
    Step 6 of 6 allowed me to "Save settings for reuse", resulting in a ".generate" file (see GenerateSQLFromDatabaseObjectsStep6Of6.png).
    question
    How should I be able to reuse such a ".generate" file, the right-click menu does not have a "Generate" option (like JDeveloper 10g has) or something similar, see GenerateSQLRightClickMenuForGenerateFile.png.
    many thanks
    Jan Vervecken

    Thanks for your reply Susan.
    You were not able to access it via metalink as it was categorized as an internal bug rather than a production version bug. Since it has now been fixed it is unlikely that I can get it changed to allow it to be seen via metalink.about "unlikely", see also ...
    ... Steve Muench : "Re: Request for "WHERE  -   IN" Combination with Bind Variables."
    ... Keimpe Bronkhorst : "Re: Generics : compiler option : unchecked conversion warnings"
    ... Brian Duff : "Re: Surround With Try/Catch : comments issue"
    ... Frank Nimphius : "Re: Jdev 11g: Warnings in structure window for jspx (makeCurrent)"
    But there is probably an explanation.
    regards
    Jan

Maybe you are looking for