Hi Nina,

You're exactly right on the error. Stephan mentioned this the other day but we 
thought it might just have been if you mix the byte codes (i.e. compile with 
JDK 6 and run with JDK 7). Luckily I found the error straight away.

A comparison violation is as follows if a < b and b < c then a must be less 
then c. If a is not less then c you haven't written the comparison method 
incorrectly. Having a quick look at the stack trace it's possible to find the 
bug in the canonical labeller.

Hint: what happens if the first values is negative… :)

1
2
3
4
5
6
7
8
9
10
11
12
  private void sortArrayList(ArrayList v) {
    Collections.sort(v, new Comparator() {
      public int compare(Object o1, Object o2) {
        return (int) (((InvPair) o1).getCurr() - ((InvPair) o2).getCurr());
      }
    });
    Collections.sort(v, new Comparator() {
      public int compare(Object o1, Object o2) {
        return (int) (((InvPair) o1).getLast() - ((InvPair) o2).getLast());
      }
    });
  }

https://gist.github.com/4139439
John May | Predoctoral Student – Chemoinformatics and Metabolism 
European Bioinformatics Institute, Wellcome Trust Genome Campus, Hinxton, 
Cambridge, CB10 1SD, UK 
[email protected] | +44–(0) 1223 49 2603

On 24 Nov 2012, at 08:41, Nina Jeliazkova <[email protected]> wrote:

> Dear Alberto, All
> 
> On 24 November 2012 10:06, Alberto Manganaro <[email protected]> 
> wrote:
> Dear all,
> 
> I encountered a strange Exception while using classes for generation of
> SMILES. For a couple of molecules, I get a "Comparison method violates
> its general contract!" message and I really can understand the meaning!
> 
> I'm actually working with CDK 1.4.9, following a slice of code where
> such Exception is raised:
> 
> String s_in =
> "CC(C)(C)C1=CC(=C(OP2OCC3(COP(OC4=CC=C(C=C4C(C)(C)C)C(C)(C)C)OC3)CO2)C=C1)C(C)(C)C";
> SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
> IMolecule m = sp.parseSmiles(s_in);
> SmilesGenerator sg = new SmilesGenerator();
> String s_out = sg.createSMILES(m);
> System.out.println(s_out);
> 
> The molecule itself is correctly parsed from the SMILES, and anyway it
> doesn't seem a "strange" or complex molecule... but then when I try to
> generate again the SMILES from the molecule, I get that Exception.
> 
> Does anyone know what's wrong? I make some mistakes or is it a weird
> behaviour of the SMILES generator? Thanks in advance for the help! Regards
> 
> I did a quick test with  
> https://github.com/ideaconsult/examples-cdk/tree/master/maven-single-module , 
> where CDK versions could be changed by maven profile. It works fine, no 
> exceptions (you could get the code and run it with , e.g.  mvn clean install 
> -P cdk-1.4.9  )
> 
> -------------------------------------------------------
>  T E S T S
> -------------------------------------------------------
> Running net.idea.examples.cdk.maven_single_module.SmilesTest
> O(C=1C=CC(=CC=1C(C)(C)C)C(C)(C)C)P2OCC4(CO2)(COP(OC3=CC=C(C=C3C(C)(C)C)C(C)(C)C)OC4)
> Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.706 sec
> 
> Otherwise, the error means a comparator is not transitive (Google search is 
> usually exceptionally precise when searching for error messages ;)   
> https://www.google.com/search?q=Comparison+method+violates+its+general+contract
>  
> 
> Which exactly comparator is hard to say without reproducing the error. 
> 
> But it is likely due to error in a specific JDK version - which one do you 
> use?  (I've tested with JDK 1.6_037)
> 
> http://www.oracle.com/technetwork/java/javase/compatibility-417013.html#source
>  
> Area: API: Utilities
> Synopsis: Updated sort behavior for Arrays and Collections may throw 
> anIllegalArgumentException
> Description: The sorting algorithm used by java.util.Arrays.sort and 
> (indirectly) byjava.util.Collections.sort has been replaced. The new sort 
> implementation may throw anIllegalArgumentException if it detects a 
> Comparable that violates the Comparable contract. The previous implementation 
> silently ignored such a situation.
> If the previous behavior is desired, you can use the new system 
> property,java.util.Arrays.useLegacyMergeSort, to restore previous mergesort 
> behavior.
> Nature of Incompatibility: behavioral
> RFE: 6804124
> 
> http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6804124
> 
> I am copying the cdk-devel list, as this seems to be change in the behaviour 
> in JDK 1.7 for a pretty core JDK functionality , and it could affect lot more 
> code than SMILES processing ...
> 
> Regards,
> Nina
> 
> 
> 
> Alberto
> 
> --
> Alberto Manganaro
> 
> Milano Chemometrics and QSAR Research Group
> Department of Environmental Sciences
> University of Milano-Bicocca P.zza della Scienza, 1
> 20126 Milano - Italy
> 
> http://michem.disat.unimib.it/chm/
> 
> ------------------------------------------------------------------------------
> Monitor your physical, virtual and cloud infrastructure from a single
> web console. Get in-depth insight into apps, servers, databases, vmware,
> SAP, cloud infrastructure, etc. Download 30-day Free Trial.
> Pricing starts from $795 for 25 servers or applications!
> http://p.sf.net/sfu/zoho_dev2dev_nov
> _______________________________________________
> Cdk-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/cdk-user
> 
> ------------------------------------------------------------------------------
> Monitor your physical, virtual and cloud infrastructure from a single
> web console. Get in-depth insight into apps, servers, databases, vmware,
> SAP, cloud infrastructure, etc. Download 30-day Free Trial.
> Pricing starts from $795 for 25 servers or applications!
> http://p.sf.net/sfu/zoho_dev2dev_nov_______________________________________________
> Cdk-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/cdk-user

------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Cdk-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cdk-user

Reply via email to