Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 304029 - Method getUpper() of MultiplicityElements always returns 1
Summary: Method getUpper() of MultiplicityElements always returns 1
Status: RESOLVED WONTFIX
Alias: None
Product: MDT.UML2
Classification: Modeling
Component: Core (show other bugs)
Version: 3.0.0   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: UML2 Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-26 09:07 EST by Philipp Reinkemeier CLA
Modified: 2012-06-18 12:16 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philipp Reinkemeier CLA 2010-02-26 09:07:29 EST
Build Identifier: 20090920-1017

In a recent project i discovered, that calling the method "getUpper()" on a Property-object, always returns 1.

Reproducible: Always

Steps to Reproduce:
1. Create a Property instance, for which property.upperValue.value = 10 (only an example here, it does also not work with other values)
2. call getUpper()
3. look at the value you got returned: It will be 1
Comment 1 Philipp Reinkemeier CLA 2010-02-26 09:27:49 EST
I have tracked down the issue via debugging the calls:

MultiplicityElementImpl.getUpper() -> MultiplicityElementOperations.getUpper(this) -> 
MultiplicityElementImpl.upperBound() -> MultiplicityElementOperations.upperBound() -> ValueSpecificationImpl.unlimitedValue() -> ValueSpecificationOperations.unlimitedValue(this)

The problem is an unconditionally thrown "UnsupportedOperationException" by ValueSpecificationOperations.unlimitedValue(). This exception gets catched by MultiplicityElementOperations.upperBound(). But instead of doing any exception handling here, the body of the catch statement is:
"catch (UnsupportedOperationException uoe) { // do nothing }"
This results in the method "MultiplicityElementOperations.upperBound()" returning 1, as this seems to be the default case, when no multiplicity has been specified.

A possible workaround for those, who need the functionality of querying the upper multiplicity of a MultiplicityElement, would be to use the method "getUpperValue()" instead and call "interValue()" on this ValueSpecification.
Comment 2 Philipp Reinkemeier CLA 2010-02-26 09:29:54 EST
(In reply to comment #1)
> A possible workaround for those, who need the functionality of querying the
> upper multiplicity of a MultiplicityElement, would be to use the method
> "getUpperValue()" instead and call "interValue()" on this ValueSpecification.

I meant "getUpperValue().integerValue()"
Comment 3 Kenn Hussey CLA 2012-06-18 12:16:53 EDT
Since primitive types in Java must have a value, it's not possible for lower and upper (as opposed to lowerValue and upperValue) to not have a value. Currently, the default multiplicity is returned in cases where these should have been "undefined"; in hindsight, a better approach may have been to define a constant (e.g., -2) to indicated "undefined", but changing this at this point could have undesirable compatibility effects for clients.

Given that the workaround of inspecting the upperValue (or lowerValue) exists, I'm marking this issue as "won't fix".