squizlabs / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
10.66k stars 1.48k forks source link

v3.7.1 throws warning on accessing a cache in utils #3683

Closed simPod closed 1 year ago

simPod commented 1 year ago

Describe the bug

v3.7.1 throws warning on accessing a cache in utils

PHP Warning: Trying to access array offset on value of type null

Code sample

I don't know under what condition this happens

$ vendor/bin/phpcs
PHP Warning:  Trying to access array offset on value of type null in /path/vendor/squizlabs/php_codesniffer/src/Util/Cache.php on line 269

Warning: Trying to access array offset on value of type null in /path/vendor/squizlabs/php_codesniffer/src/Util/Cache.php on line 269
................ 16 / 16 (100%)

Time: 1.59 secs; Memory: 44MB

Expected behavior A clear and concise description of what you expected to happen.

Versions (please complete the following information):

jrfnl commented 1 year ago

@simPod This sounds like a duplicate of issue #3173 and the same response applies: without a reproduction scenario, any fix would just be hiding the error instead of fixing it.

simPod commented 1 year ago

Well, obviously the line above can read whatever from the file. So the reproduction is kind of straightforward. File can e. g. contain valid json like null.

On Thu, Oct 6, 2022, 14:43 Juliette @.***> wrote:

@simPod https://github.com/simPod This sounds like a duplicate of issue

3173 https://github.com/squizlabs/PHP_CodeSniffer/issues/3173 and the

same response applies: without a reproduction scenario, any fix would just be hiding the error instead of fixing it.

— Reply to this email directly, view it on GitHub https://github.com/squizlabs/PHP_CodeSniffer/issues/3683#issuecomment-1269975017, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACQAJJDKLBDDWFRLZSIQNDWB3CQXANCNFSM6AAAAAAQ6QRWWY . You are receiving this because you were mentioned.Message ID: @.***>

jrfnl commented 1 year ago

@simPod Except that is not a reproduction scenario which would ever occur in a normal PHPCS usage situation. Please read the other thread to see what I mean.

simPod commented 1 year ago

I understand we don't know how does it happen that cache file is empty. And it would be great to know it so we can solve the root issue.

But accessing an array offset on a mixed type is wrong whatever the root issue is. There should be a check and e.g. proper exception thrown on parse failure, or soft reset like #3684 introduces.

simPod commented 1 year ago

BTW I think my IDE is purging the phpcs cache file

It threw these exceptions and the cache file got empty. I opened issue with Jetbrains as well.

java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
    at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
    at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
    at com.intellij.util.io.BaseDataReader.waitFor(BaseDataReader.java:209)
    at com.intellij.execution.process.BaseOSProcessHandler$1.lambda$startNotified$0(BaseOSProcessHandler.java:93)
    at com.intellij.execution.process.ProcessWaitFor.lambda$new$0(ProcessWaitFor.java:45)
    at com.intellij.util.ConcurrencyUtil.runUnderThreadName(ConcurrencyUtil.java:212)
    at com.intellij.execution.process.ProcessWaitFor.lambda$new$1(ProcessWaitFor.java:23)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.OutOfMemoryError: Java heap space
Access is allowed from event dispatch thread only

com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments: EventQueue.isDispatchThread()=false
Current thread: Thread[DefaultDispatcher-worker-7,6,main] 1371265547
SystemEventQueueThread: Thread[AWT-EventQueue-0,6,main] 1661862958
    at com.intellij.openapi.application.impl.ApplicationImpl.throwThreadAccessException(ApplicationImpl.java:1042)
    at com.intellij.openapi.application.impl.ApplicationImpl.assertIsDispatchThread(ApplicationImpl.java:1025)
    at com.intellij.ide.projectView.impl.AbstractProjectViewPane.getSelectedUserObjects(AbstractProjectViewPane.java:344)
    at com.intellij.ide.projectView.impl.AbstractProjectViewPane.getData(AbstractProjectViewPane.java:394)
    at com.intellij.ide.projectView.impl.ProjectViewImpl$MyPanel.getData(ProjectViewImpl.java:1286)
    at com.intellij.ide.impl.DataManagerImpl.getDataFromProviderInner(DataManagerImpl.java:241)
    at com.intellij.ide.impl.DataManagerImpl.getDataFromProviderAndRulesInner(DataManagerImpl.java:81)
    at com.intellij.ide.impl.DataManagerImpl.getDataFromProviderAndRules(DataManagerImpl.java:60)
    at com.intellij.openapi.actionSystem.impl.EdtDataContext.calcData(EdtDataContext.java:151)
    at com.intellij.openapi.actionSystem.impl.EdtDataContext.getDataInner(EdtDataContext.java:136)
    at com.intellij.openapi.actionSystem.impl.EdtDataContext.getData(EdtDataContext.java:109)
    at com.intellij.openapi.actionSystem.DataKey.getData(DataKey.java:63)
    at com.intellij.ui.AutoScrollToSourceTaskManager$scheduleScrollToSource$1$navigatable$1$1.invoke(AutoScrollToSourceTaskManager.kt:62)
    at com.intellij.ui.AutoScrollToSourceTaskManager$scheduleScrollToSource$1$navigatable$1$1.invoke(AutoScrollToSourceTaskManager.kt:61)
    at com.intellij.openapi.application.rw.InternalReadAction.insideReadAction(InternalReadAction.kt:90)
    at com.intellij.openapi.application.rw.InternalReadAction.access$insideReadAction(InternalReadAction.kt:15)
    at com.intellij.openapi.application.rw.InternalReadAction$tryReadCancellable$1.invoke(InternalReadAction.kt:74)
    at com.intellij.openapi.application.rw.InternalReadAction$tryReadCancellable$1.invoke(InternalReadAction.kt:73)
    at com.intellij.openapi.progress.CancellationKt.withCurrentJob$lambda-0(cancellation.kt:17)
    at com.intellij.openapi.progress.Cancellation.withCurrentJob(Cancellation.java:60)
    at com.intellij.openapi.progress.CancellationKt.withCurrentJob(cancellation.kt:17)
    at com.intellij.openapi.progress.CancellationKt.executeWithJobAndCompleteIt(cancellation.kt:125)
    at com.intellij.openapi.application.rw.CancellableReadActionKt.cancellableReadActionInternal$lambda-1$lambda-0(cancellableReadAction.kt:49)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1086)
    at com.intellij.openapi.application.rw.CancellableReadActionKt.cancellableReadActionInternal$lambda-1(cancellableReadAction.kt:47)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtilService.runActionAndCancelBeforeWrite(ProgressIndicatorUtilService.java:63)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runActionAndCancelBeforeWrite(ProgressIndicatorUtils.java:130)
    at com.intellij.openapi.application.rw.CancellableReadActionKt.cancellableReadActionInternal(cancellableReadAction.kt:45)
    at com.intellij.openapi.application.rw.InternalReadAction.tryReadCancellable(InternalReadAction.kt:73)
    at com.intellij.openapi.application.rw.InternalReadAction.access$tryReadCancellable(InternalReadAction.kt:15)
    at com.intellij.openapi.application.rw.InternalReadAction$tryReadAction$2.invoke(InternalReadAction.kt:59)
    at com.intellij.openapi.application.rw.InternalReadAction$tryReadAction$2.invoke(InternalReadAction.kt:54)
    at com.intellij.openapi.progress.CancellationKt.withCurrentJob$lambda-0(cancellation.kt:17)
    at com.intellij.openapi.progress.Cancellation.withCurrentJob(Cancellation.java:60)
    at com.intellij.openapi.progress.CancellationKt.withCurrentJob(cancellation.kt:17)
    at com.intellij.openapi.progress.CoroutinesKt.blockingContext(coroutines.kt:142)
    at com.intellij.openapi.application.rw.InternalReadAction.tryReadAction(InternalReadAction.kt:54)
    at com.intellij.openapi.application.rw.InternalReadAction.readLoop(InternalReadAction.kt:46)
    at com.intellij.openapi.application.rw.InternalReadAction.access$readLoop(InternalReadAction.kt:15)
    at com.intellij.openapi.application.rw.InternalReadAction$runReadAction$2.invokeSuspend(InternalReadAction.kt:27)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(Unknown Source)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(Unknown Source)
    Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelled}@788ccc8a, EDT]
jrfnl commented 1 year ago

@simPod Any update on this ?

simPod commented 1 year ago

I don't see this anymore. Thanks.

jrfnl commented 1 year ago

@simPod Thanks for getting back to me!

jrfnl commented 1 year ago

@simPod Oh, I presume I can close out the associated PR #3684 now as well ?

simPod commented 1 year ago

I guess, at least for now

On Thu, Jul 13, 2023 at 8:14 PM Juliette @.***> wrote:

@simPod https://github.com/simPod Oh, I presume I can close out the associated PR #3684 https://github.com/squizlabs/PHP_CodeSniffer/pull/3684 now as well ?

— Reply to this email directly, view it on GitHub https://github.com/squizlabs/PHP_CodeSniffer/issues/3683#issuecomment-1634688902, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACQAJN5TXWMU2K7DFKGIJDXQA3JVANCNFSM6AAAAAAQ6QRWWY . You are receiving this because you were mentioned.Message ID: @.***>