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

String templates + Spring + Annotations = possible error #102

Closed
marcobehler opened this issue Jul 8, 2019 · 3 comments

Comments

Projects
None yet
2 participants
@marcobehler
Copy link

commented Jul 8, 2019

Have a completely empty Spring project, with just one class like this:

@Configuration
@PropertySources({
        @PropertySource(value = "classpath:application.properties", ignoreResourceNotFound = true),
        @PropertySource(value = "classpath:application-${spring.profiles.active}.properties", ignoreResourceNotFound = true)
})
public class DefaultConfig {
}

When you now have string templating enabled with Manifold, compilation will fail with an "java: package spring does not exist" error. I understand why that error happens and that @DisableStringLiteralTemplates is probably a sane workaround.
Just wanted to trigger a discussion if string replacements in annotations is actually needed/feasible to change?

image

@rsmckinney

This comment has been minimized.

Copy link
Member

commented Jul 8, 2019

Hi @marcobehler. That's a great question. This has come up before with Spring and the answer is to disable string templates entirely or selectively with @DisableStringLiteralTemplates. However, more use-cases have surfaced where specific parts of code should be filtered from string template processing. To account for this I've added the capability for string templates to filter stuff, but it's internal. I think for now I'll hard code a filter for Spring annotations, but I'll probably expose an API to formalize it. I'll keep this issue open until it's all settled.

So for now you can either:

  1. remove the "strings" parameter from the -Xplugin:Manifold javac argument or
  2. use @DisableStringLiteralTemplates where needed
  3. escape the $ as \$ e.g.,"classpath:application-${spring.profiles.active}.properties"

But I'll likely have this fixed within 24 hours, I'll keep you posted.

@rsmckinney

This comment has been minimized.

Copy link
Member

commented Jul 8, 2019

Update. I added a 3rd option above (escape the $)

But I'm working out a solution to filter spring framework annotations from string templates. As easy as escaping the $ is, most folks will trip over the issue because it is not obvious.

@rsmckinney rsmckinney closed this in 20a2ced Jul 9, 2019

@rsmckinney

This comment has been minimized.

Copy link
Member

commented Jul 9, 2019

Disable string templates inside annotations. Justification:

  1. spring framework has its own $ processing that interferes
  2. more generally string templates are problematic with annotations in the context of annotation processors internal to IDEs like IntelliJ

There's not enough benefit to justify the cost of fixing the above two issues, so disabling string templates as annotation arguments.

Note this fix will be included in a new release due later this evening (PDT)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.