Skip to content

MDLV3000Reader throws NPE when query bond present #664

@marois

Description

@marois

In v2.3 when parsing an MDL V3000 string containing a query bond (order >= 4), the bond order is not set because query order types are not yet supported and a warning is logged (see lines MDLV3000Reader.java:419-420).

After all the lines are read, MDLV3000Reader.readConnectionTable attempts to assign the valence to each atom. In this loop, the code calls bond.getOrder().numeric(), which throws a Null Pointer Exception because bond.order == null for one of the bonds.

When a query bond is detected it might be better to set the bond order to Order.UNSET

Here's a simple test to reproduce the issue.

	@Test
	public void should_not_throw_NPE_when_reading_v3000_containing_query_bond() throws CDKException, IOException {
		final String molfile = "\n" +
				"  Mrv2011 08202018502D          \n" +
				"\n" +
				"  0  0  0     0  0            999 V3000\n" +
				"M  V30 BEGIN CTAB\n" +
				"M  V30 COUNTS 6 6 0 0 0\n" +
				"M  V30 BEGIN ATOM\n" +
				"M  V30 1 C -4.5418 1.0401 0 0\n" +
				"M  V30 2 C -5.8753 0.2701 0 0\n" +
				"M  V30 3 C -5.8753 -1.2701 0 0\n" +
				"M  V30 4 C -4.5418 -2.0401 0 0\n" +
				"M  V30 5 C -3.208 -1.2701 0 0\n" +
				"M  V30 6 C -3.208 0.2701 0 0\n" +
				"M  V30 END ATOM\n" +
				"M  V30 BEGIN BOND\n" +
				"M  V30 1 2 1 2\n" +
				"M  V30 2 1 2 3\n" +
				"M  V30 3 2 3 4\n" +
				"M  V30 4 1 4 5\n" +
				"M  V30 5 4 5 6\n" +
				"M  V30 6 1 6 1\n" +
				"M  V30 END BOND\n" +
				"M  V30 END CTAB\n" +
				"M  END\n";
		final StringReader stringReader = new StringReader(molfile);
		final ISimpleChemObjectReader reader = new ReaderFactory().createReader(stringReader);
		final IAtomContainer molecule = reader.read(SilentChemObjectBuilder.getInstance().newAtomContainer());
		assertNotNull(molecule);
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions