Recaf icon indicating copy to clipboard operation
Recaf copied to clipboard

Unable to edit package-info files

Open royteeuwen opened this issue 5 years ago • 11 comments

Describe the bug

I have an OSGi Bundle (a jar with some extra metadata added) that normally has package-info files at package level to state which version the package is

Example:

// Decompiled with: CFR 0.150
import org.osgi.annotation.versioning.Version;

@Version(value="1.0.0")
package my.package.name;

It states that it has a parse error. Found "package", expected one of ";" "@" "class" "enum "interface" "module" "open"

To Reproduce

Open a jar (for example the following one: https://repo1.maven.org/maven2/org/apache/sling/org.apache.sling.api/2.23.0/org.apache.sling.api-2.23.0.jar) and go to org.apache.sling.api.package-info and see the error

I would have expected to still be able to edit the file in assembler mode, but I don't get any action anywhere to go to assembler mode?

royteeuwen avatar Dec 28 '20 08:12 royteeuwen

package-info classes are an odd edge case that I've not properly handled yet.

The error you are seeing is because the content analyzer JavaParser fails to recognize the syntax of the class since its not a standard class visually.

You probably meant table mode instead of assembler mode. The assembler is a separate window for editing. You can switch on a per-tab basis between display modes and decompilers by right clicking the tab of the class/file and selecting what you want from the menu.

Col-E avatar Dec 28 '20 08:12 Col-E

Hey @Col-E, thanks for the prompt reply!

Well, If I go to Table mode, I also can't edit the @Version annotation. I can see it in HEX mode, but I can't adjust anything there. Any workaround I could do at this moment to do the edit anyway? I want to make the @Version go from 1.0.0 to 1.0.1

royteeuwen avatar Dec 28 '20 09:12 royteeuwen

So this is really odd... but say you have the following code:

import org.osgi.annotation.versioning.Version;

@Version(value="2.3.4")
package org.apache.sling.api;

Compiling this will fail. Move the import statement down below the package defintion.

@Version(value="2.3.4")
package org.apache.sling.api;

import org.osgi.annotation.versioning.Version;

Now it compiles 😕

I had assumed CFR put the package below on purpose and that was the correct way to do it and something was wrong on my end. Guess not.

Col-E avatar Dec 28 '20 10:12 Col-E

Opened an issue with CFR so hopefully they will be printed in the correct location by default some time in the near future 👍

Col-E avatar Dec 28 '20 10:12 Col-E

As for table mode not having annotation support, that's still a TODO #218

I didn't like how annotations were handled back then and don't have a good idea currently, but I may have to just deal with it and re-add that annotation handling back for the time being.

Col-E avatar Dec 28 '20 10:12 Col-E

It also looks like Phantom class generation for annotations in this case fails. So you'll want to add the jar from https://mvnrepository.com/artifact/org.osgi/org.osgi.annotation.versioning/1.1.1 as a library in your workspace.

Col-E avatar Dec 28 '20 10:12 Col-E

Can you explain the last comment? I have added the jar to the workspace as library now, but it still fails to do a decompilation for CFR / Fernflower / Pryccon ?

Is there a workaround in the meantime that I could do? Maybe delete the file and add a new one myself?

royteeuwen avatar Dec 28 '20 12:12 royteeuwen

Found "package", expected one of ";" "@" "class" "enum "interface" "module" "open" can be ignored since its a local syntax parser error and not strictly a compile error.

If you reorder the import and include the dependency that holds the @Version annotation, then it should work. I tested it with your file and it compiled for me.

Col-E avatar Dec 28 '20 13:12 Col-E

Upstream issue resolved, and the manual flip works for now until CFR releases a new artifact. I'll keep this open for now since its still only really editable in decompile mode and nothing else, which is not optimal.

Col-E avatar Jan 05 '21 08:01 Col-E

Super! In the meantime i got it to work the way you mentioned, thanks!

One remark as macbook user, it would be nice to use cmd +s to save, i tried a lot of times to get it to work to in the end figure out it had to be ctrl + s On 5 Jan 2021, 09:44 +0100, Matt [email protected], wrote:

Upstream issue resolved, and the manual flip works for now until CFR releases a new artifact. I'll keep this open for now since its still only really editable in decompile mode and nothing else, which is not optimal. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

royteeuwen avatar Jan 05 '21 10:01 royteeuwen

1.17.1 will fix phantom generation for the annotations, so you no longer need to add the jar defining those annotations :)

Col-E avatar Jan 11 '21 02:01 Col-E