petermr / openVirus

aggregation of scholarly publications and extracted knowledge on viruses and epidemics.
The Unlicense
67 stars 17 forks source link

`ami3` `picocli` parsing error creates `ClassCastException` #61

Open petermr opened 4 years ago

petermr commented 4 years ago

In the test

    @Test
    public void testInclude() {
        String cmd = null;
        File cProjectDir = new File(SRC_TEST_AMI, "battery10");
        CProject project = new CProject(cProjectDir);

        cmd = "-p " + project
                + " -vv"
                + " --inputname raw"
                + " image"
                + " --include minp=500|maxpf=0.1"
                + "";

        AbstractAMITool imageTool = (AbstractAMITool) AMI.execute(AMIPixelTool.class, cmd);

    }

This correctly creates an error message

Invalid value for option '--include' (<ImageParameters=String>): expected one of [match, minheight, maxheight, minwidth, maxwidth, minpixf, maxpixf, minpix, maxpix, strings] (case-sensitive) but was 'minp'
Usage: ami image [OPTIONS]
Try 'ami image --help' for more information.

but also throws an Exception (when run in Eclipse)

java.lang.ClassCastException: org.contentmine.ami.tools.AMI cannot be cast to org.contentmine.ami.tools.AbstractAMITool
    at org.contentmine.ami.tools.AMIImageTest.testInclude(AMIImageTest.java:762)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
    at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)

When the command completes OK we (presumably) get the correct class returned.

remkop commented 4 years ago

Hard to Reproduce

I cannot reproduce this, perhaps because the test data is not committed? When I run the test I see this:

not found: cProject must be existing directory or have directory parent: 
\Users\pm286\workspace\cmdev\ami3\src\test\resources\org\contentmine\ami\battery10 (C:\Users\pm286\workspace\cmdev\ami3\src\test\resources\org\contentmine\ami\battery10

My suspicions

The test essentially executes this command:

ami [options] image --include minpix=500|maxpixf=0.1|graytol=20

... but then receives the initialized command object like this:

AMI.execute(AMIPixelTool.class, cmd);

Looking at the image command, this is defined by the AMIImageTool, not by the AMIPixelTool, which defines command pixel.

So, either the command should be ami [options] pixel ..., or the command object should be AMIImageTool:

// no need to cast: AMIImageTool extends AbstractAMITool
AMIImageTool imageTool =  AMI.execute(AMIImageTool.class, cmd);
petermr commented 4 years ago

Thanks. I thought I had committed the data. Will check. Not till tomorrow...

remkop commented 4 years ago

Was this resolved and can this ticket be closed?

petermr commented 4 years ago

Not sure it's been resolved... It tended to happen on parse errors. I'll try to repeat the problem. If I can't we'll close it.

On Tue, Jul 7, 2020 at 6:25 AM Remko Popma notifications@github.com wrote:

Was this resolved and can this ticket be closed?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/petermr/openVirus/issues/61#issuecomment-654609539, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFTCS7UEMEGPSX45FPGBL3R2KWTPANCNFSM4NYJDKMQ .

-- Peter Murray-Rust Founder ContentMine.org and Reader Emeritus in Molecular Informatics Dept. Of Chemistry, University of Cambridge, CB2 1EW, UK