Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6132077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:03:25+00:00 2026-05-23T17:03:25+00:00

I am trying to debug a Java application that is relying on Reflection. Right

  • 0

I am trying to debug a Java application that is relying on Reflection. Right now the error I get is the following:

java.lang.IllegalArgumentException: Can not set int field DataStructures.StackAr.topOfStack to java.lang.Integer
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:146)
    at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:150)
    at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:37)
    at sun.reflect.UnsafeIntegerFieldAccessorImpl.getInt(UnsafeIntegerFieldAccessorImpl.java:38)
    at sun.reflect.UnsafeIntegerFieldAccessorImpl.get(UnsafeIntegerFieldAccessorImpl.java:18)
    at java.lang.reflect.Field.get(Field.java:358)

THe last lines of the application running are:

Field f = classUnderTest.getDeclaredField(processFieldName(var));
f.setAccessible(true);
Long value = (Long) f.get(runtimeInstance);

The error message is a bit misleading and I am not sure why it is mentioning a set operation whereas I am trying to preform a get.

I am suspecting that the runtimeInstance is not an object of the expected class. But that error message is throwing me away.

Has anyone encountered this issue before? Any clues?

PS1: The exact line causing the exception is this one:

Long value = (Long) f.get(runtimeInstance);

PS2: processFieldName(var) processes the correct name of the field, i.e. it removes some artefacts from a string with the field name like this. and so on.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:03:25+00:00Added an answer on May 23, 2026 at 5:03 pm

    From the source of those accessors it seems that the class declaring the field is not assignable from the runtimeInstance‘s class:

    if (!(this.field.getDeclaringClass().isAssignableFrom(paramObject.getClass())))

      throwSetIllegalArgumentException(paramObject);

    field seems to be the field you want to get from the instance, paramObject is your runtimeInstance.

    Thus, if the declaring class of the field isn’t the class or a super class of the paramObject you’d get that message.

    Any chance your paramObject is an Integer here?

    Edit: here’s some source code from OpenJDK (should be similar to Oracle’s), to explain the message:

      protected String getSetMessage(String attemptedType, String attemptedValue) {
             String err = "Can not set";
             if (Modifier.isStatic(field.getModifiers()))
                 err += " static";
             if (isFinal)
                 err += " final";
             err += " " + field.getType().getName() + " field " + getQualifiedFieldName() + " to ";
             if (attemptedValue.length() > 0) {
                 err += "(" + attemptedType + ")" + attemptedValue;
             } else {
                 if (attemptedType.length() > 0)
                     err += attemptedType;
                 else
                     err += "null value";
             }
             return err;
         }
    

    Taking your message java.lang.IllegalArgumentException: Can not set int field DataStructures.StackAr.topOfStack to java.lang.Integer we find that:

    • the field is of type int
    • the field’s name is topOfStack in class DataStructures.StackAr
    • attemptedType is java.lang.Integer

    Since attemptedType is the type of your runtimeInstance I suspect classUnderTest is DataStructures.StackAr whereas runtimeInstance is of type java.lang.Integer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to debug an application (under PostgreSQL) and came across the following error:
I'm trying to debug the following code... @GET @Path(getGuestsXml) @Produces(application/xml) public Guest getGuestsXml() {
I have a thread in a Java web application that causes a java.lang.OutOfMemoryError: Java
I'm trying to debug a locally running java web start application. There is a
I have googled some time now trying to find a good sample application that
I'm trying to debug my Java application in Eclipse however when I hit a
I'm trying to secure a connection from a Java Client/Server application that communicates over
I'm trying to develop an application using Google's maps and I can't get this
I was getting the following error message while trying to debug my code: Not
I have an application called Update.jar that I'm trying to use with the java

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.