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

val - Inferred Type is Object #260

Closed
andricDu opened this issue Jul 19, 2016 · 16 comments
Closed

val - Inferred Type is Object #260

andricDu opened this issue Jul 19, 2016 · 16 comments
Assignees
Labels
Milestone

Comments

@andricDu
Copy link

andricDu commented Jul 19, 2016

Here is a code snippet:

  private static String[] toStringArray(Collection<String> source) {
    return source.stream().toArray(String[]::new);
  }

  private static String[] getSearchTypes(String type) {
    val result = TYPE_ID_MAPPINGS.containsKey(type) ? newHashSet(TYPE_ID_MAPPINGS.get(type)) : MULTIPLE_SEARCH_TYPES;

    return toStringArray(result);
  }

TYPE_ID_MAPPINGS is a Map<String, String> explicitly defined as such.
MULTIPLE_SEARCH_TYPES is a Set<String> also explicitly defined.

Compiles fine but IntelliJ is complaining that result is a java.lang.object and cannot be passed to toStringArray as it expects a java.util.Collection<java.lang.String>.

This is with IntelliJ 2016.2 and latest plugin version.

@alexejk
Copy link
Collaborator

alexejk commented Jul 25, 2016

Can you please test it with Lombok Plugin 0.12 ?
Thee have been quite a few changes lately in both IDEA and the plugin

@andricDu
Copy link
Author

Updated

I've updated to the latest Lombok version (0.12) and tried IntelliJ IDEA 2016.2.1 EAP Build #IU-162.1447.7, built on July 20, 2016 and the issue persists.

Another Example

Here is another example where it complains I'm returning List<Object> rather than List<String>:

    val aggsTransform = transform(aggs.getBuckets(), bucket -> bucket.getKeyAsText().toString());

    return aggsTransform;

You can see the editor appears to be in a disagreement with itself:

An interesting thing is if I cast it like so, it fixes the isssue with a redundant cast warning:

val aggsTransform = (List<String>) transform(...);

However if I cast it at the return, it seems to be complain about Inconvertible Types most of the time. At times if I'm playing around with the method body and than throw the cast on at the return statement, it no longer complains and just mentions the redundant cast. Is it possible there is a race condition in the plugin causing the issue?

Extra Remarks

I've tried with javac as well as the Eclipse compiler + annotation processing options and issues seem to be the same.

Our code base makes heavy use of streams, lambdas, and method references which seems to correlate with where our val issues show up.

Also this project is open source as well in case you were curious at pulling it down and debugging the plugin.

I hope that helps.

Thank you for your response!

@alexejk
Copy link
Collaborator

alexejk commented Jul 25, 2016

If this issue is the same with Lombok and Eclipse (outside of IntelliJ that is) - this is a problem with Lombok itself. This project is only to provide IntelliJ support for Lombok - not to implement new features in core dependency.

There is a well-known issue with val and Streams/Lambdas in Lombok, for example: projectlombok/lombok#911

@alexejk
Copy link
Collaborator

alexejk commented Jul 25, 2016

As for your sample:

 static Map<String, String> TYPE_ID_MAPPINGS = new HashMap<>();
    static Set<String> MULTIPLE_SEARCH_TYPES = new HashSet<>();


    private static String[] toStringArray(Collection<String> source) {
        return source.stream().toArray(String[]::new);
    }

    private static String[] getSearchTypes(String type) {
        val result = TYPE_ID_MAPPINGS.containsKey(type) ? newHashSet(TYPE_ID_MAPPINGS.get(type)) : MULTIPLE_SEARCH_TYPES;

        return toStringArray(result);
    }

    static  Set<String> newHashSet(String foo) {
        return new HashSet<>();
    }

Seems to not throw an error with 2016.2 , lombok plugin 0.12 and lombok dependency 1.16.10.
Can you isolate this into a separate, self-contained project with e.g Gradle or Maven where we can reproduce the issue? Please also include the project configuration (*.iml) files so we can inspect any possible misconfigurations.

@andricDu
Copy link
Author

Eclipse does not have this issue. This is IntelliJ + lombok-intellij-plugin issue only.

I only mentioned that it occurs in IntelliJ regardless of which compiler you are using.

That particular issue you mentioned with lombok occurs only inside of lambda bodies and causes an actual compile error. All of our stuff builds fine with javac.

You can find our source code here, and it is a maven project: https://github.com/icgc-dcc/dcc-portal

@alexejk
Copy link
Collaborator

alexejk commented Jul 26, 2016

Thanks for clarification.
I can see if I get some time to check the project - I do wonder, however why the above-mentioned sample actually works fine in IDEa but you are getting warnings. Will keep you posted.

As long as the code compiles via command-line with mvn installin your case - this is correct its IntelliJ-related issue.

@alexejk alexejk added this to the 0.13 milestone Jul 26, 2016
@alexejk alexejk self-assigned this Jul 26, 2016
@alexejk
Copy link
Collaborator

alexejk commented Jul 26, 2016

I've just checked your project and it works as intended for me.
For example FileService contains quite a few transformations, vals and lambdas but all of them seem to not cause any errors.

Is there a specific file that is causing issues that I can check out?
Maybe you should re-import your project after deleting *.iml files? It does look like your project/IDE has some kind of misconfiguration.

@andricDu
Copy link
Author

Interesting! Thanks for giving it a go. FileService does provide a single lombok val inference error for me.

If the project looks misconfigured, it is because it was developed in Eclipse with Eclipse project files, and the project itself is a spring-boot project so for the @Autowired annotations to resolve the server module has to have the Spring facet enabled under File -> Project Structure in IntelliJ.

I am just now investigating using IntelliJ for development on this project as we feel the Lombok support is in a good place.

What I am going to do: As a sanity check, I am going to install IntelliJ, Lombok, ...etc.. on a virgin system and see what happens.

Another spot where I am receiving an error is here (subtype variable is resolving to Object): https://github.com/icgc-dcc/dcc-portal/blob/develop/dcc-portal-server/src/main/java/org/icgc/dcc/portal/server/service/EntitySetService.java#L287

Thanks a lot! I appreciate the help, and I'll let you know what I find on a fresh system.

@andricDu
Copy link
Author

One last note, the develop branch has a few spots where classes are using the experimental @UtilityClass Lombok annotation. I'm doing my testing on a branch where those have been stripped out as we made a decision to not use that annotation as it can cause issues.

@alexejk
Copy link
Collaborator

alexejk commented Jul 26, 2016

Latest lombok plugin supports @UtilityClass on 2016.2 version of IDEA.
If you are on older version (all the way down to 15.x) you can enable "IntelliJ runtime patching" in Lombok plugin configuration. This is however not needed for 2016.2 as it provides native APIs for modifier visibility augmentation.

Please double check if all parts of newly imported code have Annotation Processing enabled.

@andricDu
Copy link
Author

I've reproduced the issue, and in the same file you tried (FileService.java, line 292 in my case).

Fresh System

  • Windows 10
  • IntelliJ 2016.2
  • lombok-intellij-plugin v0.12
  • Tried runtime patching with restarts of IDE in between
  • JDK1.8.0_101

Original System

  • Mac OSX 10.11.5
  • IntelliJ 2016.2.1 EAP
  • lombok-intellij-plugin v0.12
  • both compilers tried
  • JDK1.8.0_92

Going to attempt a couple more sanity checks on my main dev machine (Mac).

@andricDu
Copy link
Author

Also this may sound silly but I'm observing some non determinism in the val errors showing up, both between the two machines, and against the machine itself between IDE opens.

@andricDu
Copy link
Author

andricDu commented Jul 27, 2016

So this is the weirdism I'm seeing (fresh system, latest everything):

Initially the IDE shows:

Then all I do is add a single white space before the return and hit save to trigger the inspection again:

Suddenly it works?

@mplushnikov mplushnikov modified the milestones: 0.14, 0.13 Jul 27, 2016
@slovit
Copy link

slovit commented Jul 28, 2016

Same issue for me. Just imported the project and did nothing more.
IDE: 2016.2 Ultimate
Lombok plugin: 0.13.16

screen shot 2016-07-28 at 9 51 56 am

@andricDu
Copy link
Author

Not sure if related to this, but I noticed that IntelliJ was reporting exceptions caused by lombok plugin:

Accessing 'java.class.fqn' during processing 'java.field.name'. Nested different indices processing may cause deadlock
java.lang.Throwable
    at com.intellij.openapi.diagnostic.Logger.error(Logger.java:127)
    at com.intellij.util.indexing.IndexAccessValidator.checkAccessingIndexDuringOtherIndexProcessing(IndexAccessValidator.java:37)
    at com.intellij.psi.stubs.StubIndexImpl.a(StubIndexImpl.java:340)
    at com.intellij.psi.stubs.StubIndexImpl.processElements(StubIndexImpl.java:316)
    at com.intellij.psi.stubs.StubIndex.getElements(StubIndex.java:146)
    at com.intellij.psi.stubs.StubIndex.getElements(StubIndex.java:135)
    at com.intellij.psi.impl.java.stubs.index.JavaFullClassNameIndex.get(JavaFullClassNameIndex.java:48)
    at com.intellij.psi.impl.file.impl.JavaFileManagerImpl.a(JavaFileManagerImpl.java:91)
    at com.intellij.psi.impl.file.impl.JavaFileManagerImpl.findClass(JavaFileManagerImpl.java:126)
    at com.intellij.psi.impl.PsiElementFinderImpl.findClass(PsiElementFinderImpl.java:54)
    at com.intellij.psi.impl.JavaPsiFacadeImpl.b(JavaPsiFacadeImpl.java:122)
    at com.intellij.psi.impl.JavaPsiFacadeImpl.findClass(JavaPsiFacadeImpl.java:99)
    at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.a(PsiJavaCodeReferenceElementImpl.java:395)
    at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.access$100(PsiJavaCodeReferenceElementImpl.java:55)
    at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl$OurGenericsResolver.resolve(PsiJavaCodeReferenceElementImpl.java:350)
    at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl$OurGenericsResolver.resolve(PsiJavaCodeReferenceElementImpl.java:342)
    at com.intellij.psi.impl.source.resolve.ResolveCache$4.compute(ResolveCache.java:191)
    at com.intellij.psi.impl.source.resolve.ResolveCache$4.compute(ResolveCache.java:188)
    at com.intellij.openapi.util.RecursionManager$2.doPreventingRecursion(RecursionManager.java:112)
    at com.intellij.psi.impl.source.resolve.ResolveCache.resolveWithCaching(ResolveCache.java:188)
    at com.intellij.psi.impl.PsiImplUtil.multiResolveImpl(PsiImplUtil.java:745)
    at com.intellij.psi.impl.PsiImplUtil.multiResolveImpl(PsiImplUtil.java:734)
    at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.multiResolve(PsiJavaCodeReferenceElementImpl.java:377)
    at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.advancedResolve(PsiJavaCodeReferenceElementImpl.java:370)
    at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.resolve(PsiJavaCodeReferenceElementImpl.java:339)
    at com.intellij.psi.impl.source.PsiImportStatementBaseImpl.resolve(PsiImportStatementBaseImpl.java:64)
    at com.intellij.psi.impl.source.PsiJavaFileBaseImpl.a(PsiJavaFileBaseImpl.java:329)
    at com.intellij.psi.impl.source.PsiJavaFileBaseImpl.processDeclarations(PsiJavaFileBaseImpl.java:303)
    at com.intellij.psi.scope.util.PsiScopesUtil.treeWalkUp(PsiScopesUtil.java:68)
    at com.intellij.psi.scope.util.PsiScopesUtil.treeWalkUp(PsiScopesUtil.java:50)
    at com.intellij.psi.scope.util.PsiScopesUtil.resolveAndWalk(PsiScopesUtil.java:226)
    at com.intellij.psi.scope.util.PsiScopesUtil.resolveAndWalk(PsiScopesUtil.java:157)
    at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.a(PsiJavaCodeReferenceElementImpl.java:448)
    at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.access$100(PsiJavaCodeReferenceElementImpl.java:55)
    at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl$OurGenericsResolver.resolve(PsiJavaCodeReferenceElementImpl.java:350)
    at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl$OurGenericsResolver.resolve(PsiJavaCodeReferenceElementImpl.java:342)
    at com.intellij.psi.impl.source.resolve.ResolveCache$4.compute(ResolveCache.java:191)
    at com.intellij.psi.impl.source.resolve.ResolveCache$4.compute(ResolveCache.java:188)
    at com.intellij.openapi.util.RecursionManager$2.doPreventingRecursion(RecursionManager.java:112)
    at com.intellij.psi.impl.source.resolve.ResolveCache.resolveWithCaching(ResolveCache.java:188)
    at com.intellij.psi.impl.PsiImplUtil.multiResolveImpl(PsiImplUtil.java:745)
    at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.a(PsiJavaCodeReferenceElementImpl.java:277)
    at com.intellij.psi.impl.source.PsiJavaCodeReferenceElementImpl.getCanonicalText(PsiJavaCodeReferenceElementImpl.java:262)
    at com.intellij.psi.impl.source.tree.java.PsiAnnotationImpl.getQualifiedName(PsiAnnotationImpl.java:96)
    at de.plushnikov.intellij.plugin.util.PsiAnnotationSearchUtil.findAnnotationQuick(PsiAnnotationSearchUtil.java:58)
    at de.plushnikov.intellij.plugin.util.PsiAnnotationSearchUtil.findAnnotation(PsiAnnotationSearchUtil.java:33)
    at de.plushnikov.intellij.plugin.util.PsiAnnotationSearchUtil.isAnnotatedWith(PsiAnnotationSearchUtil.java:82)
    at de.plushnikov.intellij.plugin.processor.modifier.ValueModifierProcessor.isSupported(ValueModifierProcessor.java:34)
    at de.plushnikov.intellij.plugin.provider.LombokAugmentProvider.transformModifiers(LombokAugmentProvider.java:81)
    at com.intellij.psi.augment.PsiAugmentProvider$3.process(PsiAugmentProvider.java:133)
    at com.intellij.psi.augment.PsiAugmentProvider$3.process(PsiAugmentProvider.java:130)
    at com.intellij.psi.augment.PsiAugmentProvider.forEach(PsiAugmentProvider.java:146)
    at com.intellij.psi.augment.PsiAugmentProvider.transformModifierProperties(PsiAugmentProvider.java:130)
    at com.intellij.psi.impl.source.PsiModifierListImpl.b(PsiModifierListImpl.java:96)
    at com.intellij.psi.impl.source.PsiModifierListImpl.hasModifierProperty(PsiModifierListImpl.java:84)
    at com.intellij.psi.impl.source.PsiFieldImpl.hasModifierProperty(PsiFieldImpl.java:182)
    at com.intellij.codeInsight.completion.JavaCompletionUtil.isInExcludedPackage(JavaCompletionUtil.java:136)
    at com.intellij.codeInsight.daemon.impl.quickfix.StaticMembersProcessor.process(StaticMembersProcessor.java:132)
    at com.intellij.codeInsight.daemon.impl.quickfix.StaticMembersProcessor.process(StaticMembersProcessor.java:32)
    at com.intellij.psi.stubs.StubProcessingHelperBase.processStubsInFile(StubProcessingHelperBase.java:169)
    at com.intellij.psi.stubs.StubProcessingHelperBase.processStubsInFile(StubProcessingHelperBase.java:52)
    at com.intellij.psi.stubs.StubIndexImpl$2.process(StubIndexImpl.java:324)
    at com.intellij.psi.stubs.StubIndexImpl$StubIdListContainerAction.perform(StubIndexImpl.java:675)
    at com.intellij.psi.stubs.StubIndexImpl$StubIdListContainerAction.perform(StubIndexImpl.java:663)
    at com.intellij.util.indexing.ValueContainer.forEach(ValueContainer.java:81)
    at com.intellij.psi.stubs.StubIndexImpl.a(StubIndexImpl.java:350)
    at com.intellij.psi.stubs.StubIndexImpl.processElements(StubIndexImpl.java:316)
    at com.intellij.psi.impl.PsiShortNamesCacheImpl.processFieldsWithName(PsiShortNamesCacheImpl.java:236)
    at com.intellij.psi.impl.CompositeShortNamesCache.processFieldsWithName(CompositeShortNamesCache.java:273)
    at com.intellij.codeInsight.daemon.impl.quickfix.StaticImportConstantFix.getMembersToImport(StaticImportConstantFix.java:73)
    at com.intellij.codeInsight.daemon.impl.quickfix.StaticImportMemberFix.isAvailable(StaticImportMemberFix.java:78)
    at com.intellij.codeInsight.daemon.impl.ShowAutoImportPass.a(ShowAutoImportPass.java:146)
    at com.intellij.codeInsight.daemon.impl.ShowAutoImportPass.addImports(ShowAutoImportPass.java:94)
    at com.intellij.codeInsight.daemon.impl.DefaultHighlightInfoProcessor.a(DefaultHighlightInfoProcessor.java:70)
    at com.intellij.openapi.application.TransactionGuardImpl.a(TransactionGuardImpl.java:88)
    at com.intellij.openapi.application.TransactionGuardImpl.access$300(TransactionGuardImpl.java:40)
    at com.intellij.openapi.application.TransactionGuardImpl$2.run(TransactionGuardImpl.java:113)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.a(LaterInvocator.java:326)
    at com.intellij.openapi.application.impl.LaterInvocator$FlushQueue.run(LaterInvocator.java:310)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
    at java.awt.EventQueue.access$500(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:709)
    at java.awt.EventQueue$3.run(EventQueue.java:703)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
    at com.intellij.ide.IdeEventQueue.i(IdeEventQueue.java:793)
    at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:629)
    at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:385)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

@mplushnikov
Copy link
Owner

Closed this issue as obsolete now after last changes in IntelliJ 2020.3.EAP Feel free to open new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants