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

switch with nested choice type with metadata does not parse/validate #878

Open
hugohills-regnosys opened this issue Nov 28, 2024 · 4 comments
Labels
bug Something isn't working subject: model validation This issue is about validation of Rosetta models, such as the type system

Comments

@hugohills-regnosys
Copy link
Contributor

hugohills-regnosys commented Nov 28, 2024

switch with nested choice type with metadata does not parse/validate

  observable switch
      Asset   then Commodity exists,
      Basket  then basketConstituent extract [ Asset -> Commodity exists ] all = True,
      Index   then item ->> assetClass = Commodity, // this line causes issues
      default False 

where:

choice Observable: 
    Asset 
    Basket 
    Index 

choice Index: 
    CreditIndex 
    EquityIndex 
    FloatingRateIndex 
        [metadata location]
    ForeignExchangeRateIndex 
    OtherIndex

Note that if the problematic expression is replaced with item ->> assetClass exists then it works ok.

@hugohills-regnosys hugohills-regnosys added bug Something isn't working subject: model validation This issue is about validation of Rosetta models, such as the type system labels Nov 28, 2024
@hugohills-regnosys
Copy link
Contributor Author

See CDM PR were it was introduced (and then reverted with workaround)
finos/common-domain-model@eb64a52

@SimonCockx
Copy link
Contributor

Problem is not directly with the switch, but an error during indexing in the DerivedStateComputer.

@SimonCockx
Copy link
Contributor

Partially addressed by #896. However, the underlying issue of resolving references during derived state computing remains.

See stack trace here during Maven build:

[ERROR] Error scoping rosetta
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because the return value of "com.regnosys.rosetta.rosetta.simple.Annotation.getName()" is null
    at com.regnosys.rosetta.types.RosettaTypeProvider.lambda$getRMetaAttributes$0 (RosettaTypeProvider.java:224)
    at org.eclipse.xtext.xbase.lib.internal.BooleanFunctionDelegate.apply (BooleanFunctionDelegate.java:42)
    at com.google.common.collect.Iterators$5.computeNext (Iterators.java:637)
    at com.google.common.collect.AbstractIterator.tryToComputeNext (AbstractIterator.java:141)
    at com.google.common.collect.AbstractIterator.hasNext (AbstractIterator.java:136)
    at com.google.common.collect.TransformedIterator.hasNext (TransformedIterator.java:42)
    at com.google.common.collect.Iterators.addAll (Iterators.java:355)
    at com.google.common.collect.Lists.newArrayList (Lists.java:143)
    at com.google.common.collect.Lists.newArrayList (Lists.java:130)
    at org.eclipse.xtext.xbase.lib.IterableExtensions.toList (IterableExtensions.java:621)
    at com.regnosys.rosetta.types.RosettaTypeProvider.getRMetaAttributes (RosettaTypeProvider.java:232)
    at com.regnosys.rosetta.types.RosettaTypeProvider.getRMetaAttributesOfSymbol (RosettaTypeProvider.java:201)
    at com.regnosys.rosetta.types.RosettaTypeProvider.getRMetaAttributesOfFeature (RosettaTypeProvider.java:212)
    at com.regnosys.rosetta.types.RosettaTypeProvider.safeRType (RosettaTypeProvider.java:359)
    at com.regnosys.rosetta.types.RosettaTypeProvider.safeRType (RosettaTypeProvider.java:250)
    at com.regnosys.rosetta.types.RosettaTypeProvider.getRTypeOfSymbol (RosettaTypeProvider.java:151)
    at com.regnosys.rosetta.types.RosettaTypeProvider.getRTypeOfSymbol (RosettaTypeProvider.java:155)
    at com.regnosys.rosetta.types.RChoiceOption.getType (RChoiceOption.java:30)
    at com.regnosys.rosetta.types.RChoiceType.lambda$doGetAllOptions$1 (RChoiceType.java:78)
    at java.util.stream.ReferencePipeline$7$1FlatMap.accept (ReferencePipeline.java:289)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining (ArrayList.java:1709)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:570)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:560)
    at java.util.stream.StreamSpliterators$WrappingSpliterator.forEachRemaining (StreamSpliterators.java:315)
    at com.google.common.collect.CollectSpliterators$FlatMapSpliterator.lambda$forEachRemaining$1 (CollectSpliterators.java:361)
    at java.util.Spliterators$ArraySpliterator.forEachRemaining (Spliterators.java:1024)
    at com.google.common.collect.CollectSpliterators$FlatMapSpliterator.forEachRemaining (CollectSpliterators.java:357)
    at java.util.stream.ReferencePipeline$Head.forEach (ReferencePipeline.java:807)
    at java.util.stream.ReferencePipeline$7$1FlatMap.accept (ReferencePipeline.java:294)
    at java.util.ArrayList$ArrayListSpliterator.forEachRemaining (ArrayList.java:1709)
    at java.util.stream.AbstractPipeline.copyInto (AbstractPipeline.java:570)
    at java.util.stream.AbstractPipeline.wrapAndCopyInto (AbstractPipeline.java:560)
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential (ReduceOps.java:921)
    at java.util.stream.AbstractPipeline.evaluate (AbstractPipeline.java:265)
    at java.util.stream.ReferencePipeline.collect (ReferencePipeline.java:727)
    at com.regnosys.rosetta.types.RChoiceType.getAllOptions (RChoiceType.java:73)
    at com.regnosys.rosetta.scoping.RosettaScopeProvider.getScope (RosettaScopeProvider.java:353)
    at org.eclipse.xtext.linking.impl.DefaultLinkingService.getScope (DefaultLinkingService.java:59)
    at org.eclipse.xtext.linking.impl.DefaultLinkingService.getLinkedObjects (DefaultLinkingService.java:108)
    at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject (LazyLinkingResource.java:266)
    at org.eclipse.xtext.linking.lazy.LazyLinkingResource.getEObject (LazyLinkingResource.java:237)
    at org.eclipse.xtext.resource.persistence.StorageAwareResource.getEObject (StorageAwareResource.java:100)
    at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getEObject (ResourceSetImpl.java:223)
    at org.eclipse.emf.ecore.util.EcoreUtil.resolve (EcoreUtil.java:209)
    at org.eclipse.emf.ecore.util.EcoreUtil.resolve (EcoreUtil.java:269)
    at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eResolveProxy (BasicEObjectImpl.java:1477)
    at com.regnosys.rosetta.rosetta.expression.impl.SwitchCaseGuardImpl.getSymbolGuard (SwitchCaseGuardImpl.java:191)
    at com.regnosys.rosetta.rosetta.expression.impl.SwitchCaseGuardImpl.basicGetChoiceOptionGuard (SwitchCaseGuardImpl.java:263)
    at com.regnosys.rosetta.rosetta.expression.impl.SwitchCaseGuardImpl.getChoiceOptionGuard (SwitchCaseGuardImpl.java:253)
    at com.regnosys.rosetta.utils.ImplicitVariableUtil.findContainerDefiningImplicitVariable (ImplicitVariableUtil.java:64)
    at com.regnosys.rosetta.utils.ImplicitVariableUtil.implicitVariableExistsInContext (ImplicitVariableUtil.java:77)
    at com.regnosys.rosetta.derivedstate.RosettaDerivedStateComputer.setImplicitVariableInContextOfSymbolReference (RosettaDerivedStateComputer.java:144)
    at com.regnosys.rosetta.derivedstate.RosettaDerivedStateComputer.setDerivedState (RosettaDerivedStateComputer.java:64)
    at com.regnosys.rosetta.derivedstate.RosettaDerivedStateComputer.lambda$setAllDerivedState$0 (RosettaDerivedStateComputer.java:72)
    at java.util.Iterator.forEachRemaining (Iterator.java:133)
    at com.regnosys.rosetta.derivedstate.RosettaDerivedStateComputer.setAllDerivedState (RosettaDerivedStateComputer.java:71)
    at com.regnosys.rosetta.derivedstate.RosettaDerivedStateComputer.installDerivedState (RosettaDerivedStateComputer.java:50)
    at org.eclipse.xtext.resource.DerivedStateAwareResource.installDerivedState (DerivedStateAwareResource.java:244)
    at com.regnosys.rosetta.resource.RosettaResourceDescriptionManager.internalGetResourceDescription (RosettaResourceDescriptionManager.java:46)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager$1.get (DefaultResourceDescriptionManager.java:68)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager$1.get (DefaultResourceDescriptionManager.java:65)
    at org.eclipse.xtext.util.OnChangeEvictingCache.get (OnChangeEvictingCache.java:79)
    at org.eclipse.xtext.resource.impl.DefaultResourceDescriptionManager.getResourceDescription (DefaultResourceDescriptionManager.java:65)
    at org.eclipse.xtext.resource.persistence.StorageAwareResourceDescriptionManager.getResourceDescription (StorageAwareResourceDescriptionManager.java:29)
    at org.eclipse.xtext.builder.standalone.StandaloneBuilder.fillIndex (StandaloneBuilder.java:251)
    at org.eclipse.xtext.builder.standalone.StandaloneBuilder.launch (StandaloneBuilder.java:200)
    at com.regnosys.rosetta.maven.RosettaStandaloneBuilder.launch (RosettaStandaloneBuilder.java:81)
    at com.regnosys.rosetta.maven.AbstractRosettaGeneratorMojo.internalExecute (AbstractRosettaGeneratorMojo.java:100)
    at org.eclipse.xtext.maven.AbstractXtextGeneratorMojo.execute (AbstractXtextGeneratorMojo.java:144)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:126)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2 (MojoExecutor.java:328)
    at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:316)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:174)
    at org.apache.maven.lifecycle.internal.MojoExecutor.access$000 (MojoExecutor.java:75)
    at org.apache.maven.lifecycle.internal.MojoExecutor$1.run (MojoExecutor.java:162)
    at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute (DefaultMojosExecutionStrategy.java:39)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:159)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:105)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:73)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:53)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:118)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:261)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:173)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:101)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:906)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:283)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:206)
    at jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:103)
    at java.lang.reflect.Method.invoke (Method.java:580)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:255)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:201)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:361)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:314)
    at org.codehaus.classworlds.Launcher.main (Launcher.java:41)

@SimonCockx
Copy link
Contributor

SimonCockx commented Jan 8, 2025

More specifically, there might still be issues if the argument to the switch operation contains a reference to a symbol outside of the current resource. This however also depends on order of processing of the files, so sometimes it might work, sometimes it will not, so for some edge cases we might see strangeness in the future until the underlying issue is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working subject: model validation This issue is about validation of Rosetta models, such as the type system
Projects
None yet
Development

No branches or pull requests

2 participants