Skip to content

Conversation

@haniyakonain
Copy link
Contributor

@haniyakonain haniyakonain commented Oct 31, 2025

Overview

Fixes NullPointerException (NPE) errors when browsing mapping statistics and redirects endpoints by restoring proper extractor initialization. Adds automated testing to validate that statistics and redirects endpoints return HTTP 200 for all languages with mappings support.

Changes

Fixed NPE: Restored extractor.updateAll() call after instantiation to properly initialize extractors and statistics
Configured @mappings: Updated server.default.properties to use @mappings languages instead of hardcoded de,en
Added validation tests: Created stats-redirects-test.sh script that:
Automatically discovers all languages with @mappings support
Tests /statistics/{lang}/ endpoint for each language
Tests /mappings/{lang}/redirects/ endpoint for each language
Reports clear pass/fail results with detailed error messages
Integrated test into GitHub Actions workflow (server-web-api-test.yml)

Testing

To run manually:

cd scripts/src/main/bash
chmod +x stats-redirects-test.sh
./stats-redirects-test.sh

The script validates both endpoints for each language and exits with error code if any tests fail.

Summary by CodeRabbit

  • Tests

    • Added automated validation to verify stats and redirects endpoints return proper responses for all supported languages.
  • Chores

    • Updated server configuration to streamline language references.
    • Improved server startup initialization flow.

@coderabbitai
Copy link

coderabbitai bot commented Oct 31, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This PR introduces a new Bash test script for validating stats and redirects endpoints across all languages, integrates it into the CI/CD workflow, reconfigures the server to reference languages via a mappings alias instead of explicit codes, and consolidates the extractor initialization in the Server class.

Changes

Cohort / File(s) Summary
CI/CD Integration
\.github/workflows/server-web-api-test.yml
Added new GitHub Actions step "Run Stats and Redirects Tests" that executes the stats-redirects-test.sh script after existing coordinate tests.
Test Script Addition
scripts/src/main/bash/stats-redirects-test.sh
New Bash script that fetches language mappings, tests /statistics/{lang}/ and /mappings/{lang}/redirects/ endpoints for HTTP 200 responses, reports pass/fail counts, and exits with non-zero status on failures.
Configuration Changes
server/server.default.properties
Updated languages property from explicit codes de,en to dynamic reference @mappings.
Server Initialization
server/src/main/scala/org/dbpedia/extraction/server/Server.scala
Consolidated extractor field initialization and invocation of updateAll() at declaration time, removing separate initialization block.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Area of focus: The stats-redirects-test.sh script logic—verify correct parsing of language identifiers from mappings page, curl error handling, and test endpoint validation approach.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "fix: prevent NPE in stats and redirects endpoints by restoring extractor initialization" accurately captures the primary objective of the pull request, which is to fix NullPointerException errors in the stats and redirects endpoints by restoring the extractor.updateAll() call in Server.scala. The title is specific about both the problem (NPE in stats and redirects endpoints) and the solution (restoring extractor initialization), making it clear and informative for someone reviewing the project history. All changes in the PR—the configuration update to @mappings, the new test script, and the workflow integration—directly support this core fix. The title is concise, descriptive, and directly related to the main change without being misleading or overly vague.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
scripts/src/main/bash/stats-redirects-test.sh (2)

15-18: Address shellcheck warnings for safer array handling.

The script has two shellcheck warnings that should be addressed:

  1. Line 15 (SC2207): Using command substitution for array population is discouraged. While functional, consider using mapfile for safer handling.
  2. Line 18 (SC2145): Mixing string and array without proper expansion. Use "${LANGUAGES[*]}" instead of "${LANGUAGES[@]}" when displaying as a string.

Apply these improvements:

-LANGUAGES=($(echo "$MAPPINGS_PAGE" | grep -oP 'href="\K[^/"]+(?=/">)' | sort -u))
+mapfile -t LANGUAGES < <(echo "$MAPPINGS_PAGE" | grep -oP 'href="\K[^/"]+(?=/">)' | sort -u)
 [ ${#LANGUAGES[@]} -eq 0 ] && { echo "❌ ERROR: No languages found"; exit 1; }
 
-echo "Found ${#LANGUAGES[@]} languages: ${LANGUAGES[@]}"
+echo "Found ${#LANGUAGES[@]} languages: ${LANGUAGES[*]}"

22-36: Consider adding timeout to curl for robustness.

The test function correctly validates HTTP 200 responses and tracks failures. However, consider adding a timeout to prevent the test from hanging indefinitely if an endpoint becomes unresponsive.

-    http_code=$(curl -s -o /dev/null -w "%{http_code}" "$url")
+    http_code=$(curl -s --max-time 30 -o /dev/null -w "%{http_code}" "$url")
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14cca4b and 90f6828.

📒 Files selected for processing (4)
  • .github/workflows/server-web-api-test.yml (1 hunks)
  • scripts/src/main/bash/stats-redirects-test.sh (1 hunks)
  • server/server.default.properties (1 hunks)
  • server/src/main/scala/org/dbpedia/extraction/server/Server.scala (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
server/src/main/scala/org/dbpedia/extraction/server/Server.scala (1)
server/src/main/scala/org/dbpedia/extraction/server/ExtractionManager.scala (1)
  • updateAll (64-66)
🪛 Shellcheck (0.11.0)
scripts/src/main/bash/stats-redirects-test.sh

[warning] 15-15: Prefer mapfile or read -a to split command output (or quote to avoid splitting).

(SC2207)


[error] 18-18: Argument mixes string and array. Use * or separate argument.

(SC2145)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: deploy
🔇 Additional comments (5)
server/server.default.properties (1)

21-21: LGTM! Dynamic language configuration improves maintainability.

The change from hardcoded "de,en" to "@mappings" makes the configuration more dynamic and maintainable, automatically including all languages with mappings support without manual updates.

server/src/main/scala/org/dbpedia/extraction/server/Server.scala (1)

42-44: LGTM! Proper extractor initialization fixes the NPE.

The restoration of extractor.updateAll after instantiation correctly initializes the extractor's internal state, which is essential for the statistics and redirects endpoints to function without NullPointerException. This pattern is consistent with the single extractor cache initialization at lines 56-68.

Note: The extractor field is now public. Verify this is intentional for access from resources/endpoints.

.github/workflows/server-web-api-test.yml (1)

54-57: LGTM! Test step properly integrated into CI/CD workflow.

The new test step follows the established pattern and is correctly positioned after server startup and before shutdown. It will automatically validate stats and redirects endpoints for all mappings languages.

scripts/src/main/bash/stats-redirects-test.sh (2)

38-44: LGTM! Test loop comprehensively validates both endpoints.

The loop correctly tests both statistics and redirects endpoints for each discovered language, providing clear output for each test.


46-59: LGTM! Clear summary and proper exit code handling.

The summary provides comprehensive test results with clear pass/fail indicators and exits with appropriate status codes for CI/CD integration.

@haniyakonain haniyakonain marked this pull request as draft November 2, 2025 16:47
@haniyakonain haniyakonain force-pushed the add-stats-redirects-test branch 2 times, most recently from 5e4b2ae to 7731575 Compare November 11, 2025 07:24
haniyakonain added 2 commits November 11, 2025 13:12
…ages

- Create stats-redirects-test.sh to verify HTTP 200 responses
- Restore extractor initialization with updateAll() call
- Configure server to use @mappings languages
- Test validates stats and redirects endpoints for each language
- Reports clear pass/fail results with detailed error messages
The @mappings token may be causing server startup issues.
Using explicit language list (de,en) to fix CI/CD timeout.
@haniyakonain haniyakonain force-pushed the add-stats-redirects-test branch 2 times, most recently from c26c2ab to 6fb6409 Compare November 11, 2025 08:50
@sonarqubecloud
Copy link

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.

1 participant