Consider infinite potential well i.e. Hilbert space $L^2 \bigl([0,1]\bigr)$. Next we consider subset $$D_\theta = \left\{ \psi \in L^2 \bigl([0,1]\bigr) | \; \psi \; \text{is absolutely continuos and } \psi (0) = e^{i \theta} \psi (1) \right\} $$ on which we define operator $p_\theta = i \frac{\partial}{\partial x}$. Denote by $\psi_{n, \theta} = e^{i (2\pi n - \theta) x}, \; n \in \mathbb{Z}$ eigenfunctions of $p_\theta$ to the eigenvalues $\lambda_{n, \theta} = 2\pi - \theta$. Now move on to commutator $[x,p_\theta]$. Typically it would be equal to $-i$, but one can write: $$\langle \psi_n | [x, p] \psi_n \rangle = \langle \psi_n | (xp - p x) \psi_n \rangle = \lambda_n \langle \psi_n | (x-x) \psi_n \rangle = 0 \neq -i \langle \psi_n | \psi_n \rangle = -i$$
My question is: how one should cope with uncertainty principle in infinite potential well?