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 8348781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:47:35+00:00 2026-06-09T07:47:35+00:00

I am using method static void setFinalStatic(Field field, Object newValue) throws Exception { field.setAccessible(true);

  • 0

I am using method

   static void setFinalStatic(Field field, Object newValue) throws Exception
   {
      field.setAccessible(true);

      final Field modifiersField = Field.class.getDeclaredField("modifiers");
      modifiersField.setAccessible(true);
      modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);

      field.set(null, newValue);
   }  

for changing private static final fields.
But if field has type Map i get exception

Exception in thread "main" java.lang.IllegalAccessException: Can not set static final java.util.Map field org.hibernate.type.TypeFactory.BASIC_TYPES to java.util.HashMap
    at sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:55)
    at sun.reflect.UnsafeFieldAccessorImpl.throwFinalFieldIllegalAccessException(UnsafeFieldAccessorImpl.java:59)
    at sun.reflect.UnsafeQualifiedStaticObjectFieldAccessorImpl.set(UnsafeQualifiedStaticObjectFieldAccessorImpl.java:59)
    at java.lang.reflect.Field.set(Field.java:657)
    at com.company.tester.Main.setFinalStatic(Main.java:64)  

any ideas?

more code

  Field types = TypeFactory.class.getDeclaredField("BASIC_TYPES");
  types.setAccessible(true);
  Map val = (Map) types.get(null);
  Map newMap = new HashMap(val);
  newMap.put(String.class.getName(), new MyType());
  setFinalStatic(TypeFactory.class.getDeclaredField("BASIC_TYPES"), new HashMap());
  • 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-06-09T07:47:37+00:00Added an answer on June 9, 2026 at 7:47 am

    field.setAccessible(true) turns of all security checks for that Field. Changing its apparent modifiers won’t help. There is something else preventing this from working.

    Instead of trying to replace the Map, I would try updating it.

    Field types = TypeFactory.class.getDeclaredField("BASIC_TYPES");
    types.setAccessible(true);
    Object bt = types.get(null);
    Field m = bt.getClass().getDeclaredField("m");
    m.setAccessible(true);
    Map val = (Map) m.get(bt);
    val.put(String.class.getName(), new MyType());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When loading the class, using method forName() , any static initializers in the class
I'm using a public static class and static method with its parameters: public static
using following method on Path button click: public static void pathButtonAction() { JFileChooser chooser
I have a method: public static void GetObjects() { using(MyContext context = new MyContext())
I came across this behavior today while using the Substring method: static void Main(string[]
namespace MyNamespace { static void foo1() { } } using namespace MyNamespace; class MyClass
I want to call a static method in my jsp file using scriptlet and
I am using Jon Skeet's ReadFully method implemented here: public static byte[] ReadFully(Stream stream)
Is using an instance of a class to access static methods considered bad practice?
import java.net.URL; import java.net.URLConnection; import java.sql.*; public class searchlink{ public static void main(String args[])

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.