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

Qute - Ignore classes defined in the unnamed package in BeanArchives.index #26531

Merged

Conversation

michalvavrik
Copy link
Member

@michalvavrik michalvavrik commented Jul 3, 2022

fixes: #26524

When TypeInfos.create is looking for a parameter declaration type, it checks a couple of options and fallbacks to a prefix java.lang. The Qute reference guide contains an example of parameter declaration using only {@String foo} without java.lang, thus when user follows the example, he should not be warned. That is fixed by ignoring classes in the unnamed package.

@quarkus-bot quarkus-bot bot added area/arc Issue related to ARC (dependency injection) area/qute The template engine labels Jul 3, 2022
@quarkus-bot

This comment has been minimized.

@gsmet gsmet requested a review from mkouba July 4, 2022 07:29
Copy link
Contributor

@mkouba mkouba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a good solution. Note that the index wrapper can be used concurrently.

I wonder if we should get rid of the warning instead, and use e.g. the debug level...

@manovotn WDYT?

@manovotn
Copy link
Contributor

manovotn commented Jul 4, 2022

@mkouba hm, I think the warning in general has its value.
How about we don't attempt to index a class that has no package information? Classes with no packages have been bad practice for years.
Or, at least, we can detect this and first try to prepend java.lang.util and find such class and failing that fallback to attempted loading of such class?

@michalvavrik
Copy link
Member Author

That's great idea, (though here it's just java.lang.), however there is no obligation to have a Java class in the package (I realize it won't ever happen in real use cases, maybe some tests), so it should be at least mentioned in the docs. I can do it if you want (if not, please ping me so I can close the PR)

@michalvavrik
Copy link
Member Author

What about introducing whitelist for selected classes in java.lang that are likely to be used this way (String, wrapper, ...)?

I know my original solution is clumsy, but it's pretty easy to work around concurrency as only non-immutable thing there is log level, so adding copy constructor (creating a new IndexWrapper instance) would fix that issue... or am I wrong?

@manovotn
Copy link
Contributor

manovotn commented Jul 4, 2022

I'll let @mkouba decide, I am just tossing ideas around :-)

@mkouba
Copy link
Contributor

mkouba commented Jul 7, 2022

Classes with no packages have been bad practice for years.

Bad practice and discouraged but still legal...

Or, at least, we can detect this and first try to prepend java.lang.util and find such class and failing that fallback to attempted loading of such class?

I don't think we can try the prefixed version first because it's legal e.g. to have a class String (with no package) and this class should take precedence.

I'd prefer to ignore the classes with the default package inside the BeanArchives.index(), i.e. something similar to what we do with primitive types and arrays. If you think about it then it can't be reliable anyway...

@manovotn
Copy link
Contributor

Or, at least, we can detect this and first try to prepend java.lang.util and find such class and failing that fallback to attempted loading of such class?

I don't think we can try the prefixed version first because it's legal e.g. to have a class String (with no package) and this class should take precedence.

I'd prefer to ignore the classes with the default package inside the BeanArchives.index(), i.e. something similar to what we do with primitive types and arrays. If you think about it then it can't be reliable anyway...

The two approaches seem similar in a way since you try to avoid indexing no-package classes.
Your suggestion sounds good, so +1

@michalvavrik michalvavrik force-pushed the feature/qute-decrease-logging-to-trace branch from f931228 to 053891c Compare July 12, 2022 19:30
@michalvavrik michalvavrik changed the title Qute - Decrease logging level when looking for param declaration type Qute - Ignore classes defined in the unnamed pckg in BeanArchives.index Jul 12, 2022
@michalvavrik michalvavrik changed the title Qute - Ignore classes defined in the unnamed pckg in BeanArchives.index Qute - Ignore classes defined in the unnamed package in BeanArchives.index Jul 12, 2022
@michalvavrik michalvavrik force-pushed the feature/qute-decrease-logging-to-trace branch 2 times, most recently from f152744 to 97571f9 Compare July 12, 2022 19:55
@michalvavrik michalvavrik requested a review from mkouba July 13, 2022 06:56
@manovotn manovotn self-requested a review July 13, 2022 07:21
@manovotn
Copy link
Contributor

Martin is currently out of the office, I'll review this today.

Copy link
Contributor

@manovotn manovotn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michalvavrik added two comments, if you don't have time, I can update the PR as well, just let me know.

@michalvavrik michalvavrik force-pushed the feature/qute-decrease-logging-to-trace branch from 97571f9 to d4af0f9 Compare July 13, 2022 09:22
@michalvavrik
Copy link
Member Author

Thank you for the review

Copy link
Contributor

@manovotn manovotn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Thanks for the PR @michalvavrik!

@manovotn manovotn added the triage/waiting-for-ci Ready to merge when CI successfully finishes label Jul 13, 2022
@manovotn manovotn merged commit 32ff92a into quarkusio:main Jul 14, 2022
@quarkus-bot quarkus-bot bot added this to the 2.12 - main milestone Jul 14, 2022
@quarkus-bot quarkus-bot bot removed the triage/waiting-for-ci Ready to merge when CI successfully finishes label Jul 14, 2022
@michalvavrik michalvavrik deleted the feature/qute-decrease-logging-to-trace branch July 14, 2022 07:14
@Ladicek
Copy link
Contributor

Ladicek commented Jul 14, 2022

I know the subject of this PR mentions Qute, but the change here basically means that classes in the unnamed package can't ever be beans, if I understand the code change correctly? I wonder how that works with JBang scripting, which by convention uses the unnamed package (judging from https://quarkus.io/guides/scripting).

@manovotn
Copy link
Contributor

Hmm, I have no idea nor did I know JBang uses unnamed package.
@maxandersen might know?

@maxandersen
Copy link
Member

maxandersen commented Jul 14, 2022

Yes, we don't require use of package before you actually need it.

Why is it we would not allow use of default packaged beans in Qute?
Sure - it might not be showing up in large enterprise apps, but why ban it when its perfectly valid java and for scripts/templating is just pure noise to type out?

@Ladicek
Copy link
Contributor

Ladicek commented Jul 14, 2022

I'd like to reiterate -- this PR, albeit mentioning Qute in the subject, actually changes a core piece of ArC. This has a potential to affect much more than just Qute, but I'll also confess right away that I didn't really investigate what the impact actually is.

EDIT: okay, just looking at the usages of the changed code and this seems pretty safe. Sorry for the false alarm! (Though I'm not exactly sure how the "additional classes" in ArC's IndexWrapper are supposed to be used and why would user classes actually end up there...)

@manovotn
Copy link
Contributor

"additional classes" in ArC's IndexWrapper are supposed to be used and why would user classes actually end up there...)

@Ladicek If memory serves, those were deps from 3rd party JARs that you didn't initially index or marked for indexation in any way.
During bean discovery, it can still happen that some bean has a type coming from such JAR in which case you need to additionally index that.

@mkouba
Copy link
Contributor

mkouba commented Jul 27, 2022

"additional classes" in ArC's IndexWrapper are supposed to be used and why would user classes actually end up there...)

@Ladicek If memory serves, those were deps from 3rd party JARs that you didn't initially index or marked for indexation in any way. During bean discovery, it can still happen that some bean has a type coming from such JAR in which case you need to additionally index that.

Originally the IndexWrapper was used to index JDK classes that are never part of the index and still can be used e.g. as a bean type. But then we realized that the same approach must be used e.g. if a bean type comes from an unindexed 3rd party library (as Matej mentioned).

@Ladicek
Copy link
Contributor

Ladicek commented Jul 27, 2022

OK, thanks! In that case, with this PR, bean types coming from unindexed 3rd party library can't be in the unnamed package, right? :-) Or something like that. Probably not a big deal, but it's a little strange.

@mkouba
Copy link
Contributor

mkouba commented Jul 27, 2022

OK, thanks! In that case, with this PR, bean types coming from unindexed 3rd party library can't be in the unnamed package, right? :-) Or something like that. Probably not a big deal, but it's a little strange.

I believe that it wouldn't work anyway... and a 3rd party library with classes in the unnamed package is IMO really bad idea.

@maxandersen
Copy link
Member

So default package is ok if it's in the jar the main class is in
Or how does it work ?

@mkouba
Copy link
Contributor

mkouba commented Jul 27, 2022

So default package is ok if it's in the jar the main class is in

Yes, it should be fine if it's in the application sources root, i.e. src/main/java in your project. Because the root is always indexed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/arc Issue related to ARC (dependency injection) area/qute The template engine kind/bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Qute - Failed to index String: Class does not exist in ClassLoader
5 participants