Why are these classes equal? Loaded from different classloaders.

I thought that classes loaded from different classloaders were seen as different in the JVM? But this code prints true to every check:
try
     Class c = new URLClassLoader( new URL[] { new URL( "jar:file://home/tests/test.jar!/" ) } ).loadClass( "Test" );
     Class c2 = new URLClassLoader( new URL[] { new URL( "jar:file://home/tests/test.jar!/" ) } ).loadClass( "Test" );
     System.out.println( ( c == c2 ) );
     System.out.println( ( c.equals( c2 ) ) );
     System.out.println( ( c.getName().equals( c2.getName() ) ) );
catch (Exception e)
     e.printStackTrace();
}

DrClap wrote:
The more unbelievable thing is that this:
System.out.println( ( c == c2 ) );prints "true". That shouldn't happen, and it's nothing to do with facts about classloaders. It shouldn't happen because "new" called twice should produce two different objects, no matter what kind of objects they are.
I didn't try your code because I would have had to spend a couple of minutes creating suitable jar files. But did you actually run that code? Or is it a reduction of some larger piece of code and you just assumed it would do what you said it does? Because I don't believe that.I actually ran the code and every line DID print out true. This is in Java 1.5.
I figured out why they're all true though - it's because the jar file was in the classpath, so the classes were loaded by a different classloader (the same one). When I put the jar out of the classpath, the statments printed out like this:
//false
System.out.println( ( c == c2 ) );
//false
System.out.println( ( c.equals( c2 ) ) );
//true
System.out.println( ( c.getName().equals( c2.getName() ) ) );I agree on the first one printing true but I seem to remember something about how they changed that rule in Java 1.5. I could be wrong but in c++, that would be a completely valid true statement (assuming your class implemented the "==" operator), so maybe they changed it to be in line with that?

Similar Messages

  • Where do Pipeline Component classes get loaded from?

    Can someone please point me to some documentation that describes where my Pipeline
    Component classes get loaded from?
    I have just wasted hours on this - to find that they are not loaded from WEB-INF/classes
    - but instead they must be available to the EJB classloader. The sampleportal
    is completely misleading in putting the classes in WEB-INF/classes - because they
    are in fact loaded from the sampleportal EJB jar!
    Did I miss something obvious?
    regards,
    Nick

    Nick
    Refer to this portal doc on dev2dev
    ftp://edownload:[email protected]/pub/downloads/webflow.doc
    -tulan
    "Nick Minutello" <[email protected]> wrote
    in message news:[email protected]..
    >
    >
    Can someone please point me to some documentation that describes where myPipeline
    Component classes get loaded from?
    I have just wasted hours on this - to find that they are not loaded fromWEB-INF/classes
    - but instead they must be available to the EJB classloader. Thesampleportal
    is completely misleading in putting the classes in WEB-INF/classes -because they
    are in fact loaded from the sampleportal EJB jar!
    Did I miss something obvious?
    regards,
    Nick

  • Why are these Webservices not supported in VC ?

    Hi all,
    I am using NW04s SP9, and I plan to make MDM-Application with VC.
    Therefore I introduced MDM-WebService into NW and defined it on VC.
    but "searchRecords" of "MDMSearchRecords" was displayed with "Not supported"
    in the right frame .
    Mmm...
    So I decided to think from a beginning.
    [http://www.27seconds.com/Holidays/US/USHolidayService.asmx?wsdl|http://www.27seconds.com/Holidays/US/USHolidayService.asmx?wsdl]
    I defined above it on VC and I used "Getholidaydate" .
    Good! .
    However,,, "Getholidaysforyear" was also "Not supported".
    Why are these methods "Not supported" ? .
    and how will come to be usable these methods in VC? .
    Thanx in advance.
    Regards,
    k.sugimoto.

    Hi
    Visual Composer supports Web services that are compliant with the Basic Profile 1 standard of the Web Services Interoperability (WS-I) Organization (http://help.sap.com/saphelp_nw70/helpdata/en/e0/92583ab4da4b9cb524f61ba4267d25/content.htm)
    Best regards
    Vincenzo

  • Find out where class was loaded from

    Is there a way to find out from what resource the java runtime loaded a class from? I know that -verbose:class argument will tell where classes were loaded from during runtime for only normal sun libs (core libraries from rt.jar), but it does not say where it is loading external stuff from. Can this be found out?
    For example, if a particular third party class is available several times (through accidental redundancy in classpaths)-- find out which resource it was taken from.
    I am sure you could get down into the weeds and look thorugh all the classpath entries for which ones contain which classes-- but there has got to be a better way.

    import java.io.File;
    import java.net.JarURLConnection;
    import java.net.URL;
    import java.net.URLDecoder;
    private File getPathToClass(Class c)
         try
              URL url = getClass().getResource(c.getName() + ".class");
              if( url.getProtocol().equals("jar") )
                   JarURLConnection jarCon = (JarURLConnection)url.openConnection();
                   url = jarCon.getJarFileURL();
              File file = new File(URLDecoder.decode(url.getPath(), "UTF-8"));
              return file;
         catch(Exception e)
              return null;
    }

  • Why are my emails not deleting from all devices when deleted from one?  I have iCloud set up and turned on. I have ipad2, iphone5 and a Mac. What am I doing wrong?  Thank you

    Why are my emails not deleting from all devices when deleted from one?  I have iCloud mail set up and turned on. I have ipad2, iPhone 5 and a Mac desktop. What am I doing wrong?  Thank you.

    It depends on the type of email account you are using, not on iCloud.  If you are using an IMAP or exchange account, when you delete from one device, it is deleted from all devices.  If you are using a POP (POP3) account, it won't.  (iCloud email, Gmail and Yahoo are all IMAP accounts.)

  • Why are certain albums like ones from Tool or Ozzy era black sabbath not available in the U.S. store

    why are certain albums like ones from Tool or Ozzy era black sabbath not available in the U.S. store

    Also, in some cases the artist will not allow download sales, or insists on a download store selling complete albums only rather than offering individual tracks, something Apple resists. In any case, it's not by Apple's choice; it's by decision of the content owners.

  • Does Apple charge a dollar to reset the apple id password? What are these $1.00 charges from itunes for? No purchases of movie books music etc. found on itunes.

    Does Apple charge a dollar to reset the apple id password? What are these $1.00 charges from itunes for? No purchases of movie books music etc. found on itunes.

    Found the answer.

  • Why are websites in firefox loading in an index mode after upgrading to mountain lion?

    why are websites in firefox loading in an index mode after upgrading to mountain lion?

    Hi Canes,
    Sorry - not sure what you mean?
    GB

  • F14, F15, F16 -- why are these keys on my Mac Keyboard ?

    *** !!
    Why are these keys added to my Macintosh Keyboard [circa September 2006] if the **** operating system won't allow us to use them ?
    What the **** Apple ??

    My 5+ year old keyboard has the F13 F14 F15 keys sitting all by their lonesome above the help, home, page up block of keys, and I set them to do the three Expose functions, so the system will use them (at least if you have the right hack). All the F keys used to be handier though, back in the OS 9 days, when I assigned them to do all sort of things.
    Francine
    Francine
    Schwieder

  • Why are all disks being ejected from my MacBook Pro?

    Why are all disks being ejected from my MacBook Pro?

    Likely that your optical drive is either failing or has a dirty laser lens and cannot read the disks.....

  • Find where Actionscript class is loaded from

    Hi folks,
              Is there anyway to tell where an actionscript class is loaded from (i.e. what swf file) at runtime? I've had a look at some of the reflection api's and some of the sample code but none seem to address this. I'm originally a Java developer and this is a fairly straightforward call. For any java developers who may be viewing this if I may I'll put in the java for which I'm looking for the equivalent actionscript if possible.
    Thread.currentThread().getContextClassLoader().getResource("java/lang/String.class").getPa th();
    This will give me the location jar/folder path from where the String class is loaded for the particular thread.
    Any help would be greatly appreciated,
    Mark.

    No official API, but there is a getSWFRoot on SystemManager that might help.

  • Why are my podcasts being deleted from my iPhone every time I sync them?

    why are my podcasts being deleted from my iPhone every time I sync them?

    I also have this problem though it only seems to affect my iPod Nano (6th gen).  It does not seem to affect my iPhone (though now as I type this, I better confirm that as I haven't manually managed podcasts on my iPhone since the last iTunes updates).  I have iTunes set to "manually manage music and videos" (just like OP, I'd rather manage music and videos myself rather than construct playlists and have iTunes sync them), and under the "Podcasts" tab on my nano, I do not have "Sync Podcasts" checked.
    Is this something that has occurred since the last iTunes update?

  • Why are colors faded when saving from Photoshop? And other weird things...

    I'm working on a file that's a CMYK default US Web Coated SWOP v2 file. I've tried saving to tiff and jpg from this file and both save faded versions. See below:
    Here's how it looks in PS:
    And as a jpg:
    And then another very bizarre thing... I saved it as a pdf to see how the colors would look and when viewing it in acrobat pro, I saw this:
    ....this is the same exact file as the other 2... Nothing was changed other than saving as pdf... Now I have 2 questions!
    Thanks for your help and expertise,
    Sarah

    If you're not having you images printed professionally in publications why are you editing in CMYK.  Displays and inkjet devices are RGB devices CMYK images need be converted when used on these devices. If in every step color management is used  and all devices calibrated well  colors should be quit consistent however color management is not always used and colors will be off  when color management is not done.  Photoshop is color managed is photoshop the only software you're using for your images. No Image viewers, no browsers, no document application etc.
    Also when I save the above image you state is a jpeg Its save as an png file with some Display color profile.  You need yo look into color management and what you useing as your color setting in Photoshop and hd.ow progile mismatches are handle.
    In fact all three image are png file Color mode is RGB 8bit  all have a display color profile all are different in sizes and at least one has different content. All are different yet you claim they are the same.

  • Why are these words not acceptable?

    Following up from another question regarding the frustrating password validation, you answered back that these following words were not acceptable in one's password:
    1234
    4321
    qwert
    test
    skype
    myspace
    password
    abc123
    123abc
    abcdef
    iloveyou
    letmein
    ebay
    paypal
    I understand that it'd be a problem if someone used one of those alone without any prefix or suffix with it, but WHY are you blocking it altogether? Why not allow it at least in middle of a cryptic word, like !@#$skype**&& , or ()()skype<><> ?
    It seems your password validation rules just check for an occurance of those words (some of which are questionable as to why it's blocked in the first place) anywhere in the string.
    Why are you making it hard for your users to come up with a password they can remember?Pretty much every other services (gmail, facebook, twitter, etc.) are equally as important and used (if not more important/used than Skype, on a daily basis) and don't enforce as much password rules and blocked words.
    It would be nice to see Skype go in the direction of 2-step verification like Gmail has.
    Use a simple password, bind a Cell-Phone number to it, get your temporary code via txt-message (if it's your first time on that computer / non-cached in browser), Simple!

    Hi
    Visual Composer supports Web services that are compliant with the Basic Profile 1 standard of the Web Services Interoperability (WS-I) Organization (http://help.sap.com/saphelp_nw70/helpdata/en/e0/92583ab4da4b9cb524f61ba4267d25/content.htm)
    Best regards
    Vincenzo

  • Unresolve classes - significance? Where are these classes?

    Hello,
    Does it mean I cant use any of these methods? as they are listed
    as the status when I loaded xmlparserv2.jar via loadjava. Where
    are these stored if not on xmlparserv2.jar? I am able to run
    xsutest.sql and it seems to execute okay. However, I still can
    not run the paginating samples, where one scroll or sample no 6
    the one that uses oracle.xml.sql.OracleXMLNoRowsException.
    ORA-29521: referenced name oracle/xml/sql/dml/OracleXMLSave could
    not be found
    ORA-29521: referenced name oracle/xml/sql/OracleXMLSQLException
    could not be found
    ORA-29521: referenced name oracle/xml/sql/query/OracleXMLQuery
    could not befound
    ORA-29521: referenced name
    oracle/xml/sql/OracleXMLSQLNoRowsException could not be found
    ORA-29521: referenced name oracle/xml/sql/query/OracleXMLQuery
    could not befound
    ORA-29521: referenced name oracle/xml/sql/dml/OracleXMLSave could
    not be found
    ORA-29521: referenced name oracle/xml/sql/OracleXMLSQLException
    could not be found
    errors : oracle/xml/xsql/actions/XSQLInsertRequestHandler
    errors : oracle/xml/xsql/actions/XSQLQueryHandler
    errors : oracle/xml/xsql/actions/XSQLRefCursorFunctionHandler
    errors : oracle/xml/xsql/actions/XSQLInsertParameterHandler
    loadjava: 7 errors

    I have the oracle 8.1.7 on SuSE Linux. Okay, I didnt recall
    which loadjava capture I have done those, but the point of my
    question is still, does it mean those methods that could not be
    found are not available for to call from java? Also, I noticed
    that a lot of the classes are already resolved, I assume it is
    loaded the first time I loadjava them in?
    Which version of database are you using? Also, please see my
    comments below.
    Hello,
    Does it mean I cant use any of these methods? as they are listed
    as the status when I loaded xmlparserv2.jar via loadjava. Where
    are these stored if not on xmlparserv2.jar? I am able to run
    xsutest.sql and it seems to execute okay. However, I still can
    not run the paginating samples, where one scroll or sample no 6
    the one that uses oracle.xml.sql.OracleXMLNoRowsException.
    ORA-29521: referenced name oracle/xml/sql/dml/OracleXMLSave could
    not be found
    ORA-29521: referenced name oracle/xml/sql/OracleXMLSQLException
    could not be found
    ORA-29521: referenced name oracle/xml/sql/query/OracleXMLQuery
    could not befound
    ORA-29521: referenced name
    oracle/xml/sql/OracleXMLSQLNoRowsException could not be found
    ORA-29521: referenced name oracle/xml/sql/query/OracleXMLQuery
    could not befound
    ORA-29521: referenced name oracle/xml/sql/dml/OracleXMLSave could
    not be found
    ORA-29521: referenced name oracle/xml/sql/OracleXMLSQLException
    could not be found These classed are in xsu12.jar(or xsu111.jar)
    errors : oracle/xml/xsql/actions/XSQLInsertRequestHandler
    errors : oracle/xml/xsql/actions/XSQLQueryHandler
    errors :
    oracle/xml/xsql/actions/XSQLRefCursorFunctionHandler
    errors : oracle/xml/xsql/actions/XSQLInsertParameterHandler
    loadjava: 7 errors These classes are in oraclexsql.jar.

Maybe you are looking for

  • LR4.1 Soft-proofing checkbox not visible in Windows 7 64-bit

    While I can use the "S" key to access softproofing, the checkbox doesn't show on the toolbar and the the option simply doesn't appear in the toolbar pop-up either! Any ideas except that this is a bug?

  • Connecting to SLM2048 switch through management console XSLT Processor problem

    When I try to connect to my SLM2048 I receive the following message: "your browser does not seem to support xsltprocessor" How can I resolve this ? I'm using IE 11 and Chrome 40.0.2214.93 m

  • Mac Pro international power cable

    Hello everyone, I am currently abroad, but would like to purchase the Mac Pro via the UK online store to be able to profit from student discount (I study in the UK). I realize that if I order the Mac Pro in the UK store, it will come with a UK power

  • Porting/converting an interactive DVD to Flash/SWF/FLV?

    Is it possible to make a complete mirror port or conversion of an existing interactive DVD to Flash (swf+flv) so that I can put it online and interact with it with my mouse through a flash enabled browser, just like were running on a DVD player, with

  • Parameter list problem

    Hi guys how are you i created a form that opens a number of reports and i send a different parameter list to each report but th thing is that the parameter list only affects one report is there any settings should be set to the report or is there pro