NegativeArraySizeException on static method with too many parameters #333

Closed
Lewox opened this Issue Sep 7, 2016 · 0 comments

Projects

None yet

2 participants

@Lewox
Lewox commented Sep 7, 2016

JMockit 1.27, TestNG 6.9.10, Java 8

The following exception is received on methods that have more than 100 parameters.

I understand that this is not a good programming practice, yet I'm dealing with legacy code that won't be refactored anytime soon.

java.lang.NegativeArraySizeException
    at TestDAO.method1(TestDAO.java)
    at TestDAO.method2(TestDAO.java:20)
    at MainTest.test(MainTest.java:40)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:498)

Class to mock:

/**
 * @author Lewox
 */
public class TestDAO {
   public static void method1(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10,
         int arg11, int arg12, int arg13, int arg14, int arg15, int arg16, int arg17, int arg18, int arg19, int arg20, int arg21, int arg22,
         int arg23, int arg24, int arg25, int arg26, int arg27, int arg28, int arg29, int arg30, int arg31, int arg32, int arg33, int arg34,
         int arg35, int arg36, int arg37, int arg38, int arg39, int arg40, int arg41, int arg42, int arg43, int arg44, int arg45, int arg46,
         int arg47, int arg48, int arg49, int arg50, int arg51, int arg52, int arg53, int arg54, int arg55, int arg56, int arg57, int arg58,
         int arg59, int arg60, int arg61, int arg62, int arg63, int arg64, int arg65, int arg66, int arg67, int arg68, int arg69, int arg70,
         int arg71, int arg72, int arg73, int arg74, int arg75, int arg76, int arg77, int arg78, int arg79, int arg80, int arg81, int arg82,
         int arg83, int arg84, int arg85, int arg86, int arg87, int arg88, int arg89, int arg90, int arg91, int arg92, int arg93, int arg94,
         int arg95, int arg96, int arg97, int arg98, int arg99, int arg100, int arg101, int arg102, int arg103, int arg104, int arg105, int arg106,
         int arg107, int arg108, int arg109, int arg110, int arg111, int arg112, int arg113, int arg114, int arg115, int arg116, int arg117,
         int arg118, int arg119, int arg120, int arg121, int arg122, int arg123, int arg124, int arg125, int arg126, int arg127, int arg128,
         int arg129, int arg130, int arg131, int arg132, int arg133, int arg134, int arg135, int arg136, int arg137, int arg138, int arg139,
         int arg140, int arg141, int arg142, int arg143, int arg144, int arg145, int arg146, int arg147, int arg148, int arg149) {
      System.out.println("Mock me...");
   }

   public static void method2() {
      method1(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
   }
}

Test class:

import org.testng.annotations.Test;

import mockit.Mock;
import mockit.MockUp;

/**
 * @author Lewox
 */
public class MainTest {
   @Test
   public void test() {
      new MockUp<TestDAO>() {
         @Mock
         public void method1(int arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10, int arg11,
               int arg12, int arg13, int arg14, int arg15, int arg16, int arg17, int arg18, int arg19, int arg20, int arg21, int arg22, int arg23,
               int arg24, int arg25, int arg26, int arg27, int arg28, int arg29, int arg30, int arg31, int arg32, int arg33, int arg34, int arg35,
               int arg36, int arg37, int arg38, int arg39, int arg40, int arg41, int arg42, int arg43, int arg44, int arg45, int arg46, int arg47,
               int arg48, int arg49, int arg50, int arg51, int arg52, int arg53, int arg54, int arg55, int arg56, int arg57, int arg58, int arg59,
               int arg60, int arg61, int arg62, int arg63, int arg64, int arg65, int arg66, int arg67, int arg68, int arg69, int arg70, int arg71,
               int arg72, int arg73, int arg74, int arg75, int arg76, int arg77, int arg78, int arg79, int arg80, int arg81, int arg82, int arg83,
               int arg84, int arg85, int arg86, int arg87, int arg88, int arg89, int arg90, int arg91, int arg92, int arg93, int arg94, int arg95,
               int arg96, int arg97, int arg98, int arg99, int arg100, int arg101, int arg102, int arg103, int arg104, int arg105, int arg106,
               int arg107, int arg108, int arg109, int arg110, int arg111, int arg112, int arg113, int arg114, int arg115, int arg116, int arg117,
               int arg118, int arg119, int arg120, int arg121, int arg122, int arg123, int arg124, int arg125, int arg126, int arg127, int arg128,
               int arg129, int arg130, int arg131, int arg132, int arg133, int arg134, int arg135, int arg136, int arg137, int arg138, int arg139,
               int arg140, int arg141, int arg142, int arg143, int arg144, int arg145, int arg146, int arg147, int arg148, int arg149) {
            System.out.println("Mocked!");
         }
      };

      TestDAO.method2();
   }
}
@rliesenfeld rliesenfeld self-assigned this Sep 7, 2016
@rliesenfeld rliesenfeld added the bug label Sep 7, 2016
@rliesenfeld rliesenfeld added a commit that closed this issue Sep 7, 2016
@rliesenfeld rliesenfeld Fixed bug where methods with many parameters could cause a NegativeAr…
…raySizeException, due to byte overflow (the BIPUSH op); closes #333.
7d4e545
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment