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

Changing static final field results in "Caused by: java.lang.IllegalAccessError: Update to static final field" #621

Open
dmigowski opened this issue Jan 7, 2025 · 3 comments

Comments

@dmigowski
Copy link

Hello,

I am using hotswap agent with great success but when I change a static final field in a class I get this exception:

java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.hotswap.agent.plugin.jvm.ClassInitPlugin$2.executeCommand(ClassInitPlugin.java:130)
	at org.hotswap.agent.command.impl.CommandExecutor.run(CommandExecutor.java:43)
Caused by: java.lang.IllegalAccessError: Update to static final field de.ikoffice.app.primaform.control.PrimaformOvertimeManager.overtimeAbsence3 attempted from a different method ($$ha$clinit) than the initializer method <clinit> 
	at de.ikoffice.app.primaform.control.PrimaformOvertimeManager.$$ha$clinit(Unknown Source)
	... 6 more

This wasn't an issue with JRebel, but the reason for this is probably that they unfinal all the fields automatically. Is there anything I can do except for removing the final modifier during development? Thanks in advance.

It seems like removing the final modifiers for a class during reload is a possible solution.

@skybber
Copy link
Contributor

skybber commented Jan 7, 2025

Hi,

thanks for report. May be we can fix ClassInitPlugin and clear FINAL modifier using the following approach:

            haClinit.instrument(
                new ExprEditor() {
                    public void edit(FieldAccess f) throws CannotCompileException {
                        try {
                            if (f.isStatic() && f.isWriter()) {
// clear FINAL code:
                                f.getField().setModifiers(f.getField().getModifiers() & ~Modifier.FINAL);

Could you please check if this resolves the issue in your case? Let me know how it works or if further adjustments are needed.

@dmigowski
Copy link
Author

Okey, just let me check if I get this thing to compile on my machine, I am just a simple user :).

@skybber
Copy link
Contributor

skybber commented Jan 9, 2025

Hi, I tried to reproduce this issue with the latest version of HA, but I don't see this problem. What JVM are you using please?

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