Bug 220 - java.lang.ClassCastException: at Pbomb.java:19 for any class that is not a Pbomb
Summary: java.lang.ClassCastException: at Pbomb.java:19 for any class that is not a Pbomb
Status: CONFIRMED
Alias: None
Product: Group 8
Classification: Unclassified
Component: Main (show other bugs)
Version: unspecified
Hardware: PC Windows
: High critical
Assignee: pchatterj2
URL:
Depends on:
Blocks:
 
Reported: 2017-11-26 17:07 HKT by pchatterj2
Modified: 2022-11-25 11:41 HKT (History)
2 users (show)

See Also:


Attachments
Test of the offending method with a test case (421 bytes, text/plain)
2017-11-26 17:10 HKT, pchatterj2
Details
bugfix : only does a class cast if the class is the same (290 bytes, patch)
2017-11-26 17:12 HKT, pchatterj2
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description pchatterj2 2017-11-26 17:07:17 HKT
How to reproduce : 
Call method isLarger on any instance of Class Patterns.Pbomb, pass an argument that is not an instance of class Pbomb.

Expected result :
Will return boolean true because a bomb is bigger than any other hand in dou dizhu

Actual : 
Throws java.lang.ClassCastException
Stack Trace :

java.lang.ClassCastException: pattern.tests.stubs.PdoubleStraightTestStubA cannot be cast to pattern.Pbomb
	at pattern.Pbomb.isLarger(Pbomb.java:19)
	at pattern.tests.unit.TestPBomb.isLarger1(TestPBomb.java:54)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	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.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
	at org.junit.vintage.engine.execution.RunnerExecutor.execute(RunnerExecutor.java:42)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(Unknown Source)
	at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
	at java.util.Iterator.forEachRemaining(Unknown Source)
	at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Unknown Source)
	at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
	at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(Unknown Source)
	at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(Unknown Source)
	at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
	at java.util.stream.ReferencePipeline.forEach(Unknown Source)
	at org.junit.vintage.engine.VintageTestEngine.executeAllChildren(VintageTestEngine.java:83)
	at org.junit.vintage.engine.VintageTestEngine.execute(VintageTestEngine.java:74)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
	at org.eclipse.jdt.internal.junit5.runner.JUnit5TestReference.run(JUnit5TestReference.java:82)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:539)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:761)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:461)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:207)
Comment 1 pchatterj2 2017-11-26 17:10:18 HKT
Created attachment 3 [details]
Test of the offending method with a test case

Bug confirmed with the above testcase
Comment 2 pchatterj2 2017-11-26 17:12:07 HKT
Created attachment 4 [details]
bugfix : only does a class cast if the class is the same

Resolved.
Comment 3 pchatterj2 2017-12-05 22:49:20 HKT
Note that the classcast exception must be checked for in other testcases as well, and is significant here because the test stub extends the actual PDoubleStraight class
Comment 4 pchatterj2 2017-12-05 22:50:45 HKT
Note that the classcast exception must be checked for in other testcases as well, and is significant here because the test stub extends the actual PDoubleStraight class
Comment 5 pchatterj2 2017-12-05 22:59:08 HKT
Confirmed with second testcase
class PbombTest {

Pbomb thisBomb = new Pbomb(3);
@Test	
public void isLarger1() {
		ArrayList<Integer> thisListOfValues = new ArrayList<>();
		for(int i = 0; i< 5; i++) {
			thisListOfValues.add(i + 1);
			thisListOfValues.add(i + 1);
		}
		PdoubleStraight another = new PdoubleStraight(thisListOfValues);
		boolean result = thisBomb.isLarger(another);
		assertEquals(true, result);
	}	
}