Skip to content

bridge: be tolerant to missing references #81

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

Merged
merged 2 commits into from
Jun 15, 2023
Merged

Conversation

carlosame
Copy link
Member

Instead of throwing an exception (and stop processing) on a missing reference, just report the error via the user agent and keep processing. This is what a conformant user agent is supposed to do.

There are other circumstances (like other I/O errors) where it would make sense to behave in the same way, but this may break POLA for legacy applications and is deferred to future updates. User feedback is encouraged.

The slideshow and extension modules are also affected by this PR.

Fixes #80.

@carlosame carlosame added the spec compliance Some behavior may not be spec-compliant label Jun 14, 2023
@carlosame carlosame added this to the 0.3.1 milestone Jun 14, 2023
@@ -164,7 +164,7 @@ protected void initializeAnimation() {
t = element.getParentNode();
} else {
t = ctx.getReferencedElement(element, uri);
if (t.getOwnerDocument() != element.getOwnerDocument()) {
if (t == null || t.getOwnerDocument() != element.getOwnerDocument()) {
Copy link

Choose a reason for hiding this comment

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

Won't this still throw an exception when the referenced element cannot be found?

Copy link
Member Author

Choose a reason for hiding this comment

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

Won't this still throw an exception when the referenced element cannot be found?

Yes, and it's the only thing that can be done with the current API, unless you want to silently ignore the problem.

I could change the API so the error can be processed, but that should be a different commit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in ba1fbcd

@@ -265,6 +266,15 @@ public static String getChainableAttributeNS(Element element, String namespaceUR
URIResolver resolver = ctx.createURIResolver(svgDoc, loader);
e = resolver.getElement(purl.toString(), e);
refs.add(purl);
} catch (FileNotFoundException ioEx) {
BridgeException ex = new BridgeException(ctx, e, ioEx, ERR_URI_IO,
Copy link

Choose a reason for hiding this comment

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

What do you think about isolating this duplicated code, possibly by delegating to the UserAgent using a static method?

catch(final FileNotFoundException fnfEx) {
  final BridgeExceptoin ex = new BridgeException(...);
  UserAgent.handle( ex, ctx );
  return "";
}

Doesn't have to go to the UserAgent, but it would be nice to see the duplication in one spot.

Copy link
Member Author

Choose a reason for hiding this comment

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

That could be a non-static method call to ctx but the code would be less readable (one has to look at what that method does) and more bytecode would be generated.

Instead of throwing an exception (and stop processing) on a missing reference, just
report the error via the user agent and keep processing. This is what a conformant
user agent is supposed to do.

There are other circumstances (like other I/O errors) where it would make sense to
behave in the same way, but this is deferred to future updates.

The `slideshow` and `extension` modules are also affected.
@carlosame carlosame force-pushed the fe-missing-references branch from 0020ede to ba1fbcd Compare June 15, 2023 12:13
@carlosame carlosame merged commit d455939 into master Jun 15, 2023
@carlosame carlosame deleted the fe-missing-references branch June 15, 2023 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec compliance Some behavior may not be spec-compliant
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BridgeException: Cannot find the referenced element
1 participant