Uncertainty principle in infinite potential well 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?
 A: The problem in the evaluation is that the function $x \psi_n$ lies outside the domain $D_{\theta}$ since it does not satisfy the boundary condition.
The operator $p{_\theta}$ is not self adjoint on this class of functions. Therefore, the step of its evaluation on the ket is not correct. 
The correct way to perform the computation is by integration by parts and in this case, the boundary term at $x = 1$ gives the correct answer. 
Please see the following article by: F. Gieres: "Mathematical surprises and Dirac's formalism in quantum mechanics", where examples of similar errors are given. Please see especially, example 5 in page 6 and its solution in page 39, which is very similar to the problem at hand.
A: The "uncertainty principle" is certainly a catching phrase (especially for the neophytes), the only real trouble is that people need to know a little bit (or maybe more) of functional analysis to find & understand its true meaning. 
As a general resource, one can take the book by Brian Hall "https://www.amazon.com/Quantum-Theory-Mathematicians-Graduate-Mathematics/dp/146147115X". It has chapter 12 for this particular topic. 
The trouble in the OP is that the domain of selfadjointness for $p_\theta$ does not include the range of $x$ under the particular boundary conditions required by the self-adjointness of $p_\theta$. The general theory claims that the maximal domain of the commutator of 2 unbounded operators has a certain restriction (3 conditions) 
$$D_{[A,B]} =: \{\psi\in D(A)\cap D(B)~|~ \text{Ran} (A) \subset D(B)~ \wedge~ \text{Ran} (B) \subset D(A) \}$$
These conditions (that D(A) and D(B) have a nonvoid intersection and moreover the ranges of the 2 operators are included in the other's domain) have to be checked for each physical system. Only then (if these 3 are met), is one allowed to make statements about "uncertainty principles" and possible failures thereof.
As a side note: In discussing matters of Hilbert space operator theory, one is strongly advised to NOT use the "bra-ket" formalism, simply because its mathematical foundation is really outside the scope of Hilbert space theory. The power of the bra-ket formalism is only at a formal calculus level, i.e. when one makes formal computations and doesn't worry if these expressions make sense from a mathematical standpoint
