0

This site suddenly is making an AnnotionException. Nothing was changed on the server nor de site itself, just maybe Apache / PHP updates. I tried using different PHP versions, 7.4 / 8.0 / 8.1 but all give the same error.

When I run the site locally on 8.0 or 8.1 there is no error. Can anyone point me in the right direction as to where I should start looking?

Drupal 9.4.0

Doctrine\Common\Annotations\AnnotationException: [Semantical Error] The class "Drupal\language\Annotation\LanguageNegotiation" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "Drupal\language\Annotation\LanguageNegotiation". If it is indeed no annotation, then you need to add @IgnoreAnnotation("LanguageNegotiation") to the _class_ doc comment of class Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationBrowser. in Doctrine\Common\Annotations\AnnotationException::semanticalError() (line 39 of /home/avascosolar/test/app/vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php).

Drupal\Component\Annotation\Doctrine\DocParser->Annotation() (Line: 640)
Drupal\Component\Annotation\Doctrine\DocParser->Annotations() (Line: 338)
Drupal\Component\Annotation\Doctrine\DocParser->parse('/**
 * Class for identifying language from the browser Accept-language HTTP header.
 *
 * @LanguageNegotiation(
 *   id = \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationBrowser::METHOD_ID,
 *   weight = -2,
 *   name = @Translation("Browser"),
 *   description = @Translation("Language from the browser's language settings."),
 *   config_route_name = "language.negotiation_browser"
 * )
 */', 'class Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationBrowser') (Line: 101)
Drupal\Component\Annotation\Doctrine\SimpleAnnotationReader->getClassAnnotations(Object) (Line: 125)
Drupal\Component\Annotation\Doctrine\SimpleAnnotationReader->getClassAnnotation(Object, 'Drupal\language\Annotation\LanguageNegotiation') (Line: 145)
Drupal\Component\Annotation\Plugin\Discovery\AnnotatedClassDiscovery->getDefinitions() (Line: 86)
Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator->getDefinitions() (Line: 285)
Drupal\Core\Plugin\DefaultPluginManager->findDefinitions() (Line: 175)
Drupal\Core\Plugin\DefaultPluginManager->getDefinitions() (Line: 22)
Drupal\Core\Plugin\DefaultPluginManager->getDefinition('language-url') (Line: 185)
Drupal\language\LanguageNegotiator->negotiateLanguage('language_interface', 'language-url') (Line: 133)
Drupal\language\LanguageNegotiator->initializeType('language_interface') (Line: 218)
Drupal\language\ConfigurableLanguageManager->getCurrentLanguage() (Line: 92)
Drupal\language\EventSubscriber\LanguageRequestSubscriber->setLanguageOverrides() (Line: 74)
Drupal\language\EventSubscriber\LanguageRequestSubscriber->onKernelRequestLanguage(Object, 'kernel.request', Object)
call_user_func(Array, Object, 'kernel.request', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.request') (Line: 134)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 191)
Drupal\page_cache\StackMiddleware\PageCache->fetch(Object, 1, 1) (Line: 128)
Drupal\page_cache\StackMiddleware\PageCache->lookup(Object, 1, 1) (Line: 82)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 709)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

2 Answers 2

1

If @Annotation is missing from the documentation comment for the Drupal\language\Annotation\LanguageNegotiation, in the file containing that class, then it's a problem of corrupted files that need to be replaced.

If the documentation comment for that class contains @Annotation, then it's a problem with the OPcache settings. If opcache.save_comments is disabled, then all documentation comments will be discarded from the opcode cache. As the documentation says, this breaks applications and frameworks that rely on comment parsing for annotations.
In this case, PHP should not even find the @LanguageNegotiation annotation.

1
  • You saved the day, thanks! I did not know frameworks could rely on comments.
    – WEHA
    Jun 25 at 6:52
1

When I look at my Drupal 9.4.0 code the class "Drupal\language\Annotation\LanguageNegotiation" is annotated with @Annotation:

web/core/modules/language/src/Annotation/LanguageNegotiation.php

<?php

namespace Drupal\language\Annotation;

use Drupal\Component\Annotation\Plugin;

/**
 * Defines a language negotiation annotation object.
 *
 * Plugin Namespace: Plugin\LanguageNegotiation
 *
 * For a working example, see
 * \Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationBrowser.
 *
 * @see \Drupal\language\LanguageNegotiator
 * @see \Drupal\language\LanguageNegotiationMethodManager
 * @see \Drupal\language\LanguageNegotiationMethodInterface
 * @see hook_language_negotiation_info_alter()
 * @see plugin_api
 *
 * @Annotation
 */
class LanguageNegotiation extends Plugin {

So somehow the Drupal code on the server is corrupted and you should download it again or sync it with the local copy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.