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

fix: Dummy filenames may not contain a file extension, remove it only if it exists (DEV-4227) #3442

Merged
merged 3 commits into from
Dec 12, 2024

Conversation

seakayone
Copy link
Contributor

@seakayone seakayone commented Dec 11, 2024

Pull Request Checklist

Task Description/Number

Fixes an occurence of a StringIndexOutOfBoundsException:

{"name":"org.knora.webapi.http.handler.KnoraExceptionHandler$","timestamp":"2024-12-10T16:05:57.392932872Z  ","level":"ERROR","thread":"zio-fiber-1856268975","message":"Unable to run route /v2/resources","cause":"Exception in thread \"zio-fiber-\" java.lang.StringIndexOutOfBoundsException: Range [0, -1) out of bounds for length 0
\tat java.base/jdk.internal.util.Preconditions$1.apply(Unknown Source)
\tat java.base/jdk.internal.util.Preconditions$1.apply(Unknown Source)
\tat java.base/jdk.internal.util.Preconditions$4.apply(Unknown Source)
\tat java.base/jdk.internal.util.Preconditions$4.apply(Unknown Source)
\tat java.base/jdk.internal.util.Preconditions.outOfBounds(Unknown Source)
\tat java.base/jdk.internal.util.Preconditions.outOfBoundsCheckFromToIndex(Unknown Source)
\tat java.base/jdk.internal.util.Preconditions.checkFromToIndex(Unknown Source)
\tat java.base/java.lang.String.checkBoundsBeginEnd(Unknown Source)
\tat java.base/java.lang.String.substring(Unknown Source)
\tat org.knora.webapi.messages.v2.responder.valuemessages.ValueContentV2$.fileInfoFromExternal$$anonfun$1$$anonfun$1$$anonfun$1(ValueMessagesV2.scala:717)
\tat zio.ZIO$.fromEither$$anonfun$1(ZIO.scala:3680)","logger_name":"org.knora.webapi.http.handler.KnoraExceptionHandler$","org.knora.webapi.http.handler.KnoraExceptionHandler$":"1ms"}

Issue Number: DEV-

PR Type

  • build/chore: maintenance tasks (no production code change)
  • docs: documentation changes (no production code change)
  • feat: represents new features
  • fix: represents bug fixes
  • perf: performance improvements
  • refactor: represents production code refactoring
  • test: adding or refactoring tests (no production code change)
  • deprecated: Deprecation warning (ideally referencing a migration guide)

Basic requirements for bug fixes and features

  • Tests for the changes have been added
  • Docs have been added / updated

Does this PR introduce a breaking change?

  • Yes

@seakayone seakayone changed the title fix: Dummy filenames may not contain a file extension, remove it only if it exists fix: Dummy filenames may not contain a file extension, remove it only if it exists (DEV-4227) Dec 11, 2024

def fromFilename(filename: String): Either[String, AssetId] = {
val withoutFileExtension =
if filename.contains(".") then filename.substring(0, filename.indexOf('.')) else filename
Copy link
Contributor

Choose a reason for hiding this comment

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

by the way, this looks like a filename.split('.').lift(0).getOrElse(filename)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that could work as well. Thanks for the hint.

@seakayone seakayone merged commit a6c8f2b into main Dec 12, 2024
9 checks passed
@seakayone seakayone deleted the fix/string-index-out-of-bounds-exception branch December 12, 2024 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants