Skip to content

Commit 74ea5e2

Browse files
Fix handling of null scope and try_construct (#196)
* Refs #23130. Fix handling of null scope. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #23130. Fix calculation of try construct. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> * Refs #25500. Apply review. Signed-off-by: Miguel Company <miguelcompany@eprosima.com> --------- Signed-off-by: Miguel Company <miguelcompany@eprosima.com>
1 parent 219815d commit 74ea5e2

6 files changed

Lines changed: 31 additions & 15 deletions

File tree

src/main/java/com/eprosima/idl/parser/tree/Annotation.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,16 @@ public String getValue() throws RuntimeGenerationException
231231
return ((AnnotationMember)m_members.values().toArray()[0]).getValue();
232232
}
233233

234+
public String getEnumStringValue() throws RuntimeGenerationException
235+
{
236+
if(m_members.size() != 1)
237+
{
238+
throw new RuntimeGenerationException("Error in annotation " + getName() +
239+
": accessing value of a multiple parameter exception");
240+
}
241+
return ((AnnotationMember)m_members.values().toArray()[0]).getEnumStringValue();
242+
}
243+
234244
public String getValueFromAny(TypeCode typecode) throws RuntimeGenerationException
235245
{
236246
if(m_members.size() != 1)

src/main/java/com/eprosima/idl/parser/typecode/AliasTypeCode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public String getScopedname()
170170
*/
171171
public String getFullScopedname()
172172
{
173-
if(m_scope.isEmpty())
173+
if((m_scope == null) || m_scope.isEmpty())
174174
{
175175
return m_name;
176176
}
@@ -180,7 +180,7 @@ public String getFullScopedname()
180180

181181
public String getROS2Scopedname()
182182
{
183-
if (m_scope.isEmpty())
183+
if ((m_scope == null) || m_scope.isEmpty())
184184
{
185185
return m_name;
186186
}
@@ -190,7 +190,7 @@ public String getROS2Scopedname()
190190

191191
public String getCScopedname()
192192
{
193-
if(m_scope.isEmpty())
193+
if((m_scope == null) || m_scope.isEmpty())
194194
{
195195
return m_name;
196196
}
@@ -205,7 +205,7 @@ public String getScope()
205205

206206
public boolean getHasScope()
207207
{
208-
return !m_scope.isEmpty();
208+
return (m_scope != null) && !m_scope.isEmpty();
209209
}
210210

211211
@Override

src/main/java/com/eprosima/idl/parser/typecode/BitfieldSpec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public String getScope()
6262

6363
public boolean getHasScope()
6464
{
65-
return !m_scope.isEmpty();
65+
return (m_scope != null) && !m_scope.isEmpty();
6666
}
6767

6868
public String getNamespace()

src/main/java/com/eprosima/idl/parser/typecode/MemberAppliedAnnotations.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,21 +232,22 @@ void calculate_try_construct() throws RuntimeGenerationException
232232
{
233233
if (isAnnotationTryConstruct())
234234
{
235-
if (m_annotations.get(Annotation.try_construct_str).getValue().equals(Annotation.try_construct_discard_str))
235+
String annotation_value = m_annotations.get(Annotation.try_construct_str).getEnumStringValue();
236+
if (annotation_value.equals(Annotation.try_construct_discard_str))
236237
{
237238
try_construct_ = TryConstructFailAction.DISCARD;
238239
}
239-
else if (m_annotations.get(Annotation.try_construct_str).getValue().equals(Annotation.try_construct_use_default_str))
240+
else if (annotation_value.equals(Annotation.try_construct_use_default_str))
240241
{
241242
try_construct_ = TryConstructFailAction.USE_DEFAULT;
242243
}
243-
else if (m_annotations.get(Annotation.try_construct_str).getValue().equals(Annotation.try_construct_trim_str))
244+
else if (annotation_value.equals(Annotation.try_construct_trim_str))
244245
{
245246
try_construct_ = TryConstructFailAction.TRIM;
246247
}
247248
else
248249
{
249-
throw new RuntimeGenerationException("try_construct annotation does not have a recognized value");
250+
throw new RuntimeGenerationException("try_construct annotation does not have a recognized value: '" + annotation_value + "'");
250251
}
251252
}
252253
else

src/main/java/com/eprosima/idl/parser/typecode/MemberedTypeCode.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public String getScopedname()
8181
*/
8282
public String getFullScopedname()
8383
{
84-
if(m_scope.isEmpty())
84+
if((m_scope == null) || m_scope.isEmpty())
8585
{
8686
return m_name;
8787
}
@@ -91,7 +91,7 @@ public String getFullScopedname()
9191

9292
public String getROS2Scopedname()
9393
{
94-
if(m_scope.isEmpty())
94+
if((m_scope == null) || m_scope.isEmpty())
9595
{
9696
return m_name;
9797
}
@@ -101,7 +101,7 @@ public String getROS2Scopedname()
101101

102102
public String getCScopedname()
103103
{
104-
if(m_scope.isEmpty())
104+
if((m_scope == null) || m_scope.isEmpty())
105105
{
106106
return m_name;
107107
}
@@ -111,7 +111,7 @@ public String getCScopedname()
111111

112112
public String getJavaScopedname()
113113
{
114-
if(m_scope.isEmpty())
114+
if((m_scope == null) || m_scope.isEmpty())
115115
{
116116
return m_name;
117117
}
@@ -121,7 +121,7 @@ public String getJavaScopedname()
121121

122122
public String getJniScopedname()
123123
{
124-
if(m_scope.isEmpty())
124+
if((m_scope == null) || m_scope.isEmpty())
125125
{
126126
return m_name;
127127
}
@@ -136,7 +136,7 @@ public String getScope()
136136

137137
public boolean getHasScope()
138138
{
139-
return !m_scope.isEmpty();
139+
return (m_scope != null) && !m_scope.isEmpty();
140140
}
141141

142142
@Override

src/main/java/com/eprosima/idl/parser/typecode/TypeCode.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public boolean isIsAnyTypeCode()
8686

8787
protected String generate_namespace(String scope)
8888
{
89+
if (scope == null || scope.isEmpty())
90+
{
91+
return "";
92+
}
93+
8994
String namespace = scope;
9095
// Remove last scope when declared inside an Interface
9196
if (isDeclaredInsideInterface())

0 commit comments

Comments
 (0)