Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ami3 picocli parsing error creates ClassCastException #61

Open
petermr opened this issue Jun 8, 2020 · 5 comments
Open

ami3 picocli parsing error creates ClassCastException #61

petermr opened this issue Jun 8, 2020 · 5 comments

Comments

@petermr
Copy link
Owner

petermr commented Jun 8, 2020

No description provided.

@petermr
Copy link
Owner Author

petermr commented Jun 8, 2020

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
Copy link

remkop commented Jun 10, 2020

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
Copy link
Owner Author

petermr commented Jun 10, 2020

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

remkop added a commit to petermr/ami3 that referenced this issue Jun 10, 2020
@remkop
Copy link

remkop commented Jul 7, 2020

Was this resolved and can this ticket be closed?

@petermr
Copy link
Owner Author

petermr commented Jul 7, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants